diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index c6cbad3..7f19dde 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -34,7 +34,7 @@ function AddWord() { var partOfSpeech = htmlEntities(document.getElementById("partOfSpeech").value).trim(); var simpleDefinition = htmlEntities(document.getElementById("simpleDefinition").value).trim(); var longDefinition = htmlEntities(document.getElementById("longDefinition").value); - var editIndex = htmlEntities(document.getElementById("editIndex").value); + // var editIndex = htmlEntities(document.getElementById("editIndex").value); var errorMessageArea = document.getElementById("errorMessage"); var errorMessage = ""; var updateConflictArea = document.getElementById("updateConflict"); @@ -42,23 +42,7 @@ function AddWord() { if (word != "" && (simpleDefinition != "" || longDefinition != "")) { var wordIndex = (!currentDictionary.settings.allowDuplicates) ? WordIndex(word) : -1; - if (editIndex != "") { - if (WordAtIndexWasChanged(editIndex, word, pronunciation, partOfSpeech, simpleDefinition, longDefinition)) { - document.getElementById("editWordButtonArea").style.display = "none"; - DisableForm(); - updateConflictArea.style.display = "block"; - updateConflictArea.innerHTML = "Do you really want to change the word \"" + currentDictionary.words[parseInt(editIndex)].name + "\" to what you have set above?"; - updateConflictArea.innerHTML += ''; - updateConflictArea.innerHTML += ''; - } else { - errorMessage = "No change has been made to \"" + word + "\""; - if (currentDictionary.words[parseInt(editIndex)].name != word) { - errorMessage += ". (Your dictionary is currently set to ignore case.)" - } - } - } else if (wordIndex >= 0) { + if (wordIndex >= 0) { if (WordAtIndexWasChanged(wordIndex, word, pronunciation, partOfSpeech, simpleDefinition, longDefinition)) { document.getElementById("newWordButtonArea").style.display = "none"; DisableForm(); @@ -74,7 +58,7 @@ function AddWord() { updateConflictText += ''; - updateConflictText += ' '; + updateConflictText += ' '; updateConflictArea.innerHTML = updateConflictText; } else { @@ -107,23 +91,70 @@ function AddWord() { errorMessageArea.innerHTML = errorMessage; } -function EditWord(index) { - SaveScroll(); - if (wordFormIsLocked()) { - window.scroll(0, 0); +function ShowWordEditForm(index) { + var indexString = index.toString(); // Variable for reduced processing + var word = currentDictionary.words[index]; // Reference for easier reading + var editForm = '
\ +

Editing ' + htmlEntitiesParse(word.name) + '

\ + \ + \ + \ + \ + \ + \ +
\ + \ +
\ + \ +
'; + + document.getElementById("entry" + indexString).innerHTML = editForm; + + SetPartsOfSpeech("partOfSpeech" + indexString); +} + +function CancelEditForm(index) { + document.getElementById("entry" + index.toString()).innerHTML = DictionaryEntry(index).replace("", "").replace("", ""); +} + +function EditWord(indexString) { + var word = htmlEntities(document.getElementById("word" + indexString).value).trim(); + var pronunciation = htmlEntities(document.getElementById("pronunciation" + indexString).value).trim(); + var partOfSpeech = htmlEntities(document.getElementById("partOfSpeech" + indexString).value).trim(); + var simpleDefinition = htmlEntities(document.getElementById("simpleDefinition" + indexString).value).trim(); + var longDefinition = htmlEntities(document.getElementById("longDefinition" + indexString).value); + // var editIndex = htmlEntities(document.getElementById("editIndex").value); + var errorMessageArea = document.getElementById("errorMessage" + indexString); + var errorMessage = ""; + var updateConflictArea = document.getElementById("updateConflict" + indexString); + + if (WordAtIndexWasChanged(indexString, word, pronunciation, partOfSpeech, simpleDefinition, longDefinition)) { + document.getElementById("editWordButtonArea" + indexString).style.display = "none"; + DisableForm(); + updateConflictArea.style.display = "block"; + updateConflictArea.innerHTML = "Do you really want to change the word \"" + currentDictionary.words[parseInt(indexString)].name + "\" to what you have set above?"; + updateConflictArea.innerHTML += ''; + updateConflictArea.innerHTML += ''; + } else { + errorMessage = "No change has been made to \"" + word + "\""; + if (currentDictionary.words[parseInt(indexString)].name != word) { + errorMessage += ". (Your dictionary is currently set to ignore case.)"; + } } - ClearForm(); - - document.getElementById("editIndex").value = index.toString(); - document.getElementById("word").value = htmlEntitiesParse(currentDictionary.words[index].name); - document.getElementById("pronunciation").value = htmlEntitiesParse(currentDictionary.words[index].pronunciation); - document.getElementById("partOfSpeech").value = htmlEntitiesParse(currentDictionary.words[index].partOfSpeech); - document.getElementById("simpleDefinition").value = htmlEntitiesParse(currentDictionary.words[index].simpleDefinition); - document.getElementById("longDefinition").value = htmlEntitiesParse(currentDictionary.words[index].longDefinition); - - document.getElementById("newWordButtonArea").style.display = "none"; - document.getElementById("editWordButtonArea").style.display = "block"; + errorMessageArea.innerHTML = errorMessage; } function UpdateWord(wordIndex, word, pronunciation, partOfSpeech, simpleDefinition, longDefinition) { @@ -219,7 +250,7 @@ function ShowDictionary() { function DictionaryEntry(itemIndex) { displayPublic = (typeof displayPublic !== 'undefined' && displayPublic != null) ? displayPublic : false; - var entryText = "🔗"; + var entryText = "🔗"; var searchTerm = regexParseForSearch(document.getElementById("searchBox").value); var searchByWord = document.getElementById("searchOptionWord").checked; @@ -290,7 +321,7 @@ function DictionaryEntry(itemIndex) { function ManagementArea(itemIndex) { var managementHTML = "
"; - managementHTML += "Edit"; + managementHTML += "Edit"; managementHTML += "Delete"; managementHTML += "