From d03abfa566279b08f85156bdd1c28c17a025459d Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Tue, 1 Oct 2019 14:41:09 -0600 Subject: [PATCH] Add etymology field to advanced word form area --- src/js/render/words.js | 6 ++++++ src/js/setupListeners/words.js | 11 +++++++++-- src/js/wordManagement.js | 27 +++++++++++++++++++++++++-- template-index.html | 6 ++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/js/render/words.js b/src/js/render/words.js index b611d3a..a6bd45c 100644 --- a/src/js/render/words.js +++ b/src/js/render/words.js @@ -160,6 +160,12 @@ export function renderEditForm(wordId = false) { + Show Advanced +
Save Changes Cancel Edit diff --git a/src/js/setupListeners/words.js b/src/js/setupListeners/words.js index 3ddee00..bd2d06e 100644 --- a/src/js/setupListeners/words.js +++ b/src/js/setupListeners/words.js @@ -1,17 +1,19 @@ import { renderEditForm } from '../render/words'; -import { confirmEditWord, cancelEditWord, confirmDeleteWord, submitWordForm } from '../wordManagement'; +import { confirmEditWord, cancelEditWord, confirmDeleteWord, expandAdvancedForm, submitWordForm } from '../wordManagement'; import { goToNextPage, goToPreviousPage, goToPage } from '../pagination'; import { setupMaximizeButtons } from './buttons'; import { setupIPAFields } from '.'; export function setupWordForm() { const wordForm = document.getElementById('wordForm'), + expandAdvancedFormButton = document.getElementById('expandAdvancedForm'), addWordButton = document.getElementById('addWordButton'); wordForm.addEventListener('submit', event => { // Allow semantic form and prevent it from getting submitted event.preventDefault(); return false; }); + expandAdvancedFormButton.addEventListener('click', expandAdvancedForm); addWordButton.addEventListener('click', submitWordForm); setupIPAFields(); @@ -61,8 +63,13 @@ export function setupWordOptionSelections() { } export function setupWordEditFormButtons() { - const saveChangesButtons = document.getElementsByClassName('edit-save-changes'), + const expandAdvancedFormButtons = document.getElementsByClassName('expand-advanced-form'), + saveChangesButtons = document.getElementsByClassName('edit-save-changes'), cancelChangesButtons = document.getElementsByClassName('edit-cancel'); + Array.from(expandAdvancedFormButtons).forEach(button => { + button.removeEventListener('click', expandAdvancedForm); + button.addEventListener('click', expandAdvancedForm); + }); Array.from(saveChangesButtons).forEach(button => { button.removeEventListener('click', confirmEditWord); button.addEventListener('click', confirmEditWord); diff --git a/src/js/wordManagement.js b/src/js/wordManagement.js index 54c716a..9573642 100644 --- a/src/js/wordManagement.js +++ b/src/js/wordManagement.js @@ -155,12 +155,26 @@ export function parseReferences(detailsMarkdown) { return detailsMarkdown; } +export function expandAdvancedForm(id = false) { + const wordId = typeof id.target !== 'undefined' ? this.id.replace('expandAdvancedForm', '') : id; + const button = typeof id.target !== 'undefined' ? this : document.getElementById('expandAdvancedForm' + (!wordId ? '' : wordId)), + form = document.getElementById('advancedForm' + (!wordId ? '' : wordId)); + if (form.style.display !== 'block') { + button.innerText = 'Hide Advanced'; + form.style.display = 'block'; + } else { + button.innerText = 'Show Advanced'; + form.style.display = 'none'; + } +} + export function submitWordForm() { const name = document.getElementById('wordName').value, pronunciation = document.getElementById('wordPronunciation').value, partOfSpeech = document.getElementById('wordPartOfSpeech').value, definition = document.getElementById('wordDefinition').value, - details = document.getElementById('wordDetails').value; + details = document.getElementById('wordDetails').value, + etymology = document.getElementById('wordEtymology').value; const word = { name: removeTags(name).trim(), @@ -171,6 +185,10 @@ export function submitWordForm() { wordId: getNextId(), }; + if (removeTags(etymology).trim() !== '') { + word.etymology = removeTags(etymology).trim(); + } + if (validateWord(word)) { addWord(word); sortWords(true); @@ -252,7 +270,8 @@ export function confirmEditWord(id) { pronunciation = document.getElementById('wordPronunciation_' + wordId).value, partOfSpeech = document.getElementById('wordPartOfSpeech_' + wordId).value, definition = document.getElementById('wordDefinition_' + wordId).value, - details = document.getElementById('wordDetails_' + wordId).value; + details = document.getElementById('wordDetails_' + wordId).value, + etymology = document.getElementById('wordEtymology_' + wordId).value; const word = { name: removeTags(name).trim(), @@ -263,6 +282,10 @@ export function confirmEditWord(id) { wordId, }; + if (removeTags(etymology).trim() !== '') { + word.etymology = removeTags(etymology).trim(); + } + if (validateWord(word, wordId)) { if (confirm(`Are you sure you want to save changes to "${word.name}"?`)) { document.getElementById('editForm_' + wordId).classList.add('done'); diff --git a/template-index.html b/template-index.html index 0cce357..4d0021c 100644 --- a/template-index.html +++ b/template-index.html @@ -139,6 +139,12 @@ + + Advanced +
Add Word