Set up saving dictionary changes correctly
This commit is contained in:
parent
0ff0afcd52
commit
97677244f5
|
@ -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() {
|
||||
|
|
|
@ -89,7 +89,11 @@ export function renderPartsOfSpeechSelect() {
|
|||
partOfSpeech = removeTags(partOfSpeech);
|
||||
optionsHTML += `<option value="${partOfSpeech}">${partOfSpeech}</option>`;
|
||||
});
|
||||
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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue