From 97677244f5e0a99e40290cba3eba6037c51775a8 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sat, 4 May 2019 00:21:55 -0600 Subject: [PATCH] Set up saving dictionary changes correctly --- src/js/dictionaryManagement.js | 44 ++++++++++++++++++++++++++++++++-- src/js/render.js | 6 ++++- src/js/setupListeners.js | 5 ++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index 8db971a..f390237 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -1,4 +1,5 @@ -import { renderDictionaryDetails } from "./render"; +import { renderDictionaryDetails, renderPartsOfSpeechSelect } from "./render"; +import { removeTags } from "../helpers"; export function updateDictionary () { @@ -9,6 +10,7 @@ export function openEditModal() { const { name, specification, description, partsOfSpeech } = window.currentDictionary; const { consonants, vowels, blends, phonotactics } = window.currentDictionary.details.phonology; const { orthography, grammar } = window.currentDictionary.details; + const { allowDuplicates, caseSensitive, sortByDefinition, isComplete, isPublic } = window.currentDictionary.settings; document.getElementById('editName').value = name; document.getElementById('editSpecification').value = specification; @@ -26,7 +28,45 @@ export function openEditModal() { document.getElementById('editOrthography').value = orthography.notes; document.getElementById('editGrammar').value = grammar.notes; - document.getElementById('editModal').style.display = 'block'; + document.getElementById('editAllowDuplicates').checked = allowDuplicates; + document.getElementById('editCaseSensitive').checked = caseSensitive; + document.getElementById('editSortByDefinition').checked = sortByDefinition; + document.getElementById('editIsComplete').checked = isComplete; + document.getElementById('editIsPublic').checked = isPublic; + + document.getElementById('editModal').style.display = ''; +} + +export function save() { + window.currentDictionary.name = removeTags(document.getElementById('editName').value.trim()); + window.currentDictionary.specification = removeTags(document.getElementById('editSpecification').value.trim()); + window.currentDictionary.description = removeTags(document.getElementById('editDescription').value.trim()); + window.currentDictionary.partsOfSpeech = document.getElementById('editPartsOfSpeech').value.split(',').map(val => val.trim()); + + window.currentDictionary.details.phonology.consonants = document.getElementById('editConsonants').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.vowels = document.getElementById('editVowels').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.blends = document.getElementById('editBlends').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.phonotactics.onset = document.getElementById('editOnset').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.phonotactics.nucleus = document.getElementById('editNucleus').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.phonotactics.coda = document.getElementById('editCoda').value.split(',').map(val => val.trim()); + window.currentDictionary.details.phonology.phonotactics.exceptions = removeTags(document.getElementById('editExceptions').value.trim()); + + window.currentDictionary.details.orthography.notes = removeTags(document.getElementById('editOrthography').value.trim()); + window.currentDictionary.details.grammar.notes = removeTags(document.getElementById('editGrammar').value.trim()); + + window.currentDictionary.settings.allowDuplicates = document.getElementById('editAllowDuplicates').checked; + window.currentDictionary.settings.caseSensitive = document.getElementById('editCaseSensitive').checked; + window.currentDictionary.settings.sortByDefinition = document.getElementById('editSortByDefinition').checked; + window.currentDictionary.settings.isComplete = document.getElementById('editIsComplete').checked; + window.currentDictionary.settings.isPublic = document.getElementById('editIsPublic').checked; + + renderDictionaryDetails(); + renderPartsOfSpeechSelect(); +} + +export function saveAndClose() { + save(); + document.getElementById('editModal').style.display = 'none'; } export function updateGeneralDetails() { diff --git a/src/js/render.js b/src/js/render.js index c1aa019..d472f3f 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -89,7 +89,11 @@ export function renderPartsOfSpeechSelect() { partOfSpeech = removeTags(partOfSpeech); optionsHTML += ``; }); - Array.from(document.getElementsByClassName('part-of-speech-select')).forEach(select => select.innerHTML = optionsHTML); + Array.from(document.getElementsByClassName('part-of-speech-select')).forEach(select => { + const selectedValue = select.value; + select.innerHTML = optionsHTML; + select.value = selectedValue; + }); } export function renderWords() { diff --git a/src/js/setupListeners.js b/src/js/setupListeners.js index 60f34d4..887ea14 100644 --- a/src/js/setupListeners.js +++ b/src/js/setupListeners.js @@ -3,7 +3,7 @@ import { renderWords } from './render'; import { validateWord, addWord } from './wordManagement'; import { removeTags } from '../helpers'; import { getNextId } from './utilities'; -import { openEditModal } from './dictionaryManagement'; +import { openEditModal, save, saveAndClose } from './dictionaryManagement'; export default function setupListeners() { setupDetailsTabs(); @@ -49,7 +49,8 @@ function setupEditFormTabs() { } function setupEditFormButtons() { - + document.getElementById('editSave').addEventListener('click', () => save()); + document.getElementById('editSaveAndClose').addEventListener('click', () => saveAndClose()); } function setupSearchBar() {