Added export words, cleaned up looks a bit

This commit is contained in:
Robbie Antenesse 2016-06-21 12:30:00 -06:00
parent 3902ba96ba
commit 6341948f45
6 changed files with 83 additions and 16 deletions

18
EXPORT.form Normal file
View File

@ -0,0 +1,18 @@
<h2>Export</h2>
<div id="exportOptions">
<div class="settingsCol">
<label>
<span>Word List</span>
</label>
<p style="font-size:12px;">This process exports all of the words in the dictionary as a CSV format file.</p>
<p style="font-size:12px;">You can either use the exported file to re-import them into a different dictionary in Lexiconga, or taken and used somewhere else you might need them!</p>
<button type="button" onclick="ExportWords(); return false;">Export Words</button>
</div>
<div class="settingsCol">
<label>
<span>Full Dictionary</span>
<p style="font-size:12px;">This process exports the full dictionary, words and all information, in a ".dict" format to be re-imported back into Lexiconga as a new dictionary.</p>
<button type="button" onclick="ExportDictionary(); return false;">Export Dictionary</button>
</label>
</div>
</div>

View File

@ -15,6 +15,7 @@
<label>
<span>Full Dictionary</span>
<p style="font-size:12px;">This process imports a full dictionary previously exported from Lexiconga in a .dict format.</p>
<p style="font-size:12px;">All imported dictionaries are set to not be public by default, even if the source dictionary was public. Be sure to check the settings after importing to make sure everything is how you want it after importing.</p>
<input type="file" id="importFile" />
<button type="button" onclick="ImportDictionary(); return false;">Import Dictionary</button>
</label>

View File

@ -1 +1 @@
The Filter system has been updated—you can now filter on as many parts of speech as you want!
<i><small>June 21, 2016</small></i> So much has been updated! Check the <a href="http://test.lexicon.ga/updates" target="_blank">Updates page</a> to see all the changes!

View File

@ -303,16 +303,17 @@ if ($display_mode != "build") {
<label>
<b>Total Entries:</b> <i id="numberOfWordsInDictionary"></i>
</label>
<label><button type="button" onclick="ExportDictionary()" style="cursor:pointer;">Export Current Dictionary</button></label>
<br>
<?php if ($current_user > 0) { //If logged in, show the special options. ?>
<label><span>Change Dictionaries</span>
<select id="userDictionaries" onchange="ChangeDictionary();"></select>
</label>
<br>
<label><button type="button" onclick="CreateNewDictionary()" style="cursor:pointer;">Create a New Dictionary</button></label>
<?php } ?>
<label>
<button type="button" onclick="ShowInfo('importForm')">Import...</button>
</label>
<label style="display:inline-block;margin-right:8px;"><button type="button" onclick="ShowInfo('exportForm')">Export...</button></label>
<label style="display:inline-block;"><button type="button" onclick="ShowInfo('importForm')">Import...</button></label>
<br><br>
<?php if ($current_user > 0) { //If logged in, show the log out button. ?>
<label><button type="button" onclick="DeleteCurrentDictionary()" style="cursor:pointer;">Delete Current Dictionary</button></label>
<?php } else { //If logged in, show the log out button. ?>
@ -422,7 +423,7 @@ if ($display_mode != "build") {
<?php } ?>
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
<script>
var aboutText = termsText = privacyText = loginForm = forgotForm = importForm = "Loading...";
var aboutText = termsText = privacyText = loginForm = forgotForm = exportForm = importForm = "Loading...";
<?php if ($display_mode != "build") { ?>
window.onload = function () {
ShowPublicDictionary(<?php if ($display_mode == "word") echo "true"; ?>);
@ -436,6 +437,7 @@ if ($display_mode != "build") {
GetTextFile("/PRIVACY.md", "privacyText", true);
GetTextFile("/LOGIN.form", "loginForm", false);
GetTextFile("/FORGOT.form", "forgotForm", false);
GetTextFile("/EXPORT.form", "exportForm", false);
GetTextFile("/IMPORT.form", "importForm", false);
}
<?php } else { ?>

View File

@ -342,7 +342,7 @@ function DictionaryEntryTemplate(wordObject, managementIndex) {
entryText += "'><a name='" + wordObject.wordId + "'></a>";
if (currentDictionary.settings.isPublic) {
entryText += "<a href='/" + currentDictionary.externalID + "/" + wordObject.wordId + "' class='wordLink clickable' title='Share Word' style='margin-left:5px;'>&#10150;</a>";
entryText += "<a href='/" + currentDictionary.externalID + "/" + wordObject.wordId + "' target='_blank' class='wordLink clickable' title='Share Word' style='margin-left:5px;'>&#10150;</a>";
}
entryText += "<a href='#" + wordObject.wordId + "' class='wordLink clickable' title='Link Within Page'>&#x1f517;</a>";
@ -619,6 +619,10 @@ function LoadDictionary() {
function ChangeDictionary(userDictionariesSelect) {
userDictionariesSelect = (typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null) ? userDictionariesSelect : document.getElementById("userDictionaries");
if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 0) {
// Show the info page with loading screen and hide settings and stuff.
ShowInfoWithText("<h1>Loading " + userDictionariesSelect.options[userDictionariesSelect.selectedIndex].text + "...</h1>");
HideSettings();
ChangeDictionaryToId(userDictionariesSelect.value, function(response) {
if (response == "no dictionaries") {
console.log(response);
@ -630,7 +634,7 @@ function ChangeDictionary(userDictionariesSelect) {
SaveDictionary(false);
ProcessLoad();
LoadUserDictionaries();
HideSettings();
HideInfo(); // Hide the loading screen.
}
});
}
@ -694,12 +698,32 @@ function SavePreviousDictionary () {
}
function ExportDictionary() {
var downloadName = removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g, '');
if (downloadName == "") {
downloadName = "export";
}
download(downloadName + ".dict", localStorage.getItem('dictionary'));
}
function ExportWords() {
if (currentDictionary.words.length > 0) {
var downloadName = removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g, '');
if (downloadName == "") {
downloadName = "export";
}
download(downloadName + ".dict", localStorage.getItem('dictionary'));
downloadName += "_words";
var wordsCSV = "word,pronunciation,part of speech,equivalent,explanation\n";
for (var i = 0; i < currentDictionary.words.length; i++) {
var word = htmlEntities(currentDictionary.words[i].name).trim();
var pronunciation = htmlEntities(currentDictionary.words[i].pronunciation).trim();
var partOfSpeech = htmlEntities(currentDictionary.words[i].partOfSpeech).trim();
var simpleDefinition = htmlEntities(currentDictionary.words[i].simpleDefinition).trim();
var longDefinition = htmlEntities(currentDictionary.words[i].longDefinition);
wordsCSV += word + "," + pronunciation + "," + partOfSpeech + "," + simpleDefinition + "," + longDefinition + "\n";
}
download(downloadName + ".csv", wordsCSV);
} else {
alert("Dictionary must have at least 1 word to export.")
}
@ -730,8 +754,10 @@ function ImportDictionary() {
currentDictionary.settings.isPublic = false; // Reset public setting for imported dictionary.
SaveDictionary(true);
ProcessLoad();
HideInfo();
HideSettings();
document.getElementById("importFile").value = "";
NewNotification("Successfully Imported the \"" + currentDictionary.name + "\" Dictionary.");
} else {
var errorString = "File is missing:";
if (!tmpDicitonary.hasOwnProperty("name"))
@ -779,8 +805,18 @@ function ImportWords() {
currentRow++;
// If there are no errors OR the word and either equivalent or explanation contain data, then import it.
if ((row.data[0].word.trim().length > 0 && (row.data[0].equivalent.trim().length > 0 || row.data[0].explanation.trim().length > 0)) || row.errors.length == 0) {
currentDictionary.words.push({name: htmlEntities(row.data[0]["word"]).trim(), pronunciation: htmlEntities(row.data[0]["pronunciation"]).trim(), partOfSpeech: ((htmlEntities(row.data[0]["part of speech"]).trim().length > 0) ? htmlEntities(row.data[0]["part of speech"]).trim() : " "), simpleDefinition: htmlEntities(row.data[0]["equivalent"]).trim(), longDefinition: htmlEntities(row.data[0]["explanation"]).trim(), wordId: currentDictionary.nextWordId++});
resultsArea.innerHTML += "<p>Imported \"" + htmlEntitiesParse(htmlEntities(row.data[0]["word"])).trim() + "\" successfully</p>";
var wordName = htmlEntities(row.data[0]["word"]).trim(),
wordPronunciation = htmlEntities(row.data[0]["pronunciation"]).trim(),
wordPartOfSpeech = ((htmlEntities(row.data[0]["part of speech"]).trim().length > 0) ? htmlEntities(row.data[0]["part of speech"]).trim() : " "),
wordSimpleDefinition = htmlEntities(row.data[0]["equivalent"]).trim(),
wordLongDefinition = htmlEntities(row.data[0]["explanation"]).trim(),
wordId = currentDictionary.nextWordId++;
currentDictionary.words.push({name: wordName, pronunciation: wordPronunciation, partOfSpeech: wordPartOfSpeech, simpleDefinition: wordSimpleDefinition, longDefinition: wordLongDefinition, wordId: wordId});
var wordEntry = DictionaryEntryTemplate(currentDictionary.words[currentDictionary.words.length - 1]);
resultsArea.innerHTML += wordEntry;
rowsImported++;
} else {
// If it's not just an empty line, give an error.
@ -796,6 +832,7 @@ function ImportWords() {
complete: function(results) {
SaveAndUpdateWords("all");
resultsArea.innerHTML += "<p>The file has finished importing " + rowsImported.toString() + " words.</p>";
NewNotification("Imported " + rowsImported.toString() + " words.");
// Scroll to the bottom.
document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight;
document.getElementById("numberOfWordsInDictionary").innerHTML = currentDictionary.words.length.toString();

View File

@ -8,6 +8,7 @@ function Initialize() {
GetTextFile("/PRIVACY.md", "privacyText", true);
GetTextFile("/LOGIN.form", "loginForm", false);
GetTextFile("/FORGOT.form", "forgotForm", false);
GetTextFile("/EXPORT.form", "exportForm", false);
GetTextFile("/IMPORT.form", "importForm", false);
SetKeyboardShortcuts();
@ -444,16 +445,20 @@ function ToggleSearchFilter() {
}
function ShowInfo(variableName) {
document.getElementById("infoText").innerHTML = window[variableName];
ShowInfoWithText(window[variableName]);
if (variableName == "loginForm") {
// document.getElementById("infoText").innerHTML = loginForm;
if (currentDictionary.words.length > 0 || currentDictionary.name != "New" || currentDictionary.description != "A new dictionary.") {
document.getElementById("dictionaryWarn").innerHTML = "If your current dictionary is not already saved to your account, be sure to <span class='exportWarnText' onclick='ExportDictionary()'>export it before logging in</span> so you don't lose anything!";
}
}
HideAccountSettings();
document.getElementById("infoPage").scrollTop = 0;
}
function ShowInfoWithText(text) {
document.getElementById("infoText").innerHTML = text;
document.getElementById("infoScreen").style.display = "block";
document.getElementById("infoPage").scrollTop = 0;
HideAccountSettings();
}
function HideInfo() {
@ -670,11 +675,15 @@ function ShowFilterWordCount(numberOfWords) {
}
function NewWordNotification(word) {
var wordId = currentDictionary.nextWordId - 1;
NewNotification("New Word Added: <a href='#" + wordId.toString() + "'>" + word + "</a>");
}
function NewNotification(message) {
var notificationArea = document.getElementById("notificationArea");
var notificationMessage = document.getElementById("notificationMessage");
var wordId = currentDictionary.nextWordId - 1;
notificationArea.style.display = "block";
notificationMessage.innerHTML = "New Word Added: <a href='#" + wordId.toString() + "'>" + word + "</a>";
notificationMessage.innerHTML = message;
}
function FocusAfterAddingNewWord() {