From 7d29e5b533a4607d1580cb6982de3870605805af Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 29 Oct 2017 10:18:15 -0700 Subject: cleanup of settings page --- ext/bg/js/settings.js | 56 +++++++++++++++++++++------------------------------ ext/bg/settings.html | 17 +++++++++------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 7a9ba4f9..d608a81b 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -25,7 +25,6 @@ async function formRead() { optionsNew.general.compactTags = $('#compact-tags').prop('checked'); optionsNew.general.compactGlossaries = $('#compact-glossaries').prop('checked'); optionsNew.general.resultOutputMode = $('#result-output-mode').val(); - optionsNew.general.mainDictionary = $('#main-dictionary').val(); optionsNew.general.audioSource = $('#audio-playback-source').val(); optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val()); optionsNew.general.debugInfo = $('#show-debug-info').prop('checked'); @@ -58,6 +57,7 @@ async function formRead() { optionsNew.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value')); } + optionsNew.general.mainDictionary = $('#dict-main').val(); $('.dict-group').each((index, element) => { const dictionary = $(element); const title = dictionary.data('title'); @@ -85,11 +85,11 @@ function formUpdateVisibility(options) { advanced.hide(); } - const merge = $('.options-merge'); + const mainGroup = $('#dict-main-group'); if (options.general.resultOutputMode === 'merge') { - merge.show(); + mainGroup.show(); } else { - merge.hide(); + mainGroup.hide(); } const debug = $('#debug'); @@ -105,40 +105,32 @@ function formUpdateVisibility(options) { } async function formMainDictionaryOptionsPopulate(options) { - const select = $('#main-dictionary').empty(); + const select = $('#dict-main').empty(); + select.append($('')); - let titles = await utilDatabaseGetTitlesWithSequences(); - titles = titles.filter(title => options.dictionaries[title].enabled); - const formOptionsHtml = []; - let mainDictionarySelected = false; + let mainDictionary = ''; + const formOptions = [$]; + const titles = await utilDatabaseGetTitlesWithSequences(); for (const title of titles) { - if (options.general.mainDictionary === title) { - mainDictionarySelected = true; + select.append($(``)); + if (title === options.general.mainDictionary) { + mainDictionary = title; } - formOptionsHtml.push(``); } - if (!mainDictionarySelected) { - options.general.mainDictionary = ''; - } - - const notSelectedOptionHtml = ``; - - select.append($([notSelectedOptionHtml].concat(formOptionsHtml).join(''))); + select.val(mainDictionary); } async function onFormOptionsChanged(e) { - try { - if (!e.originalEvent && !e.isTrigger) { - return; - } - - const {optionsNew, optionsOld} = await formRead(); - await formMainDictionaryOptionsPopulate(optionsNew); - await optionsSave(optionsNew); + if (!e.originalEvent && !e.isTrigger) { + return; + } - formUpdateVisibility(optionsNew); + const {optionsNew, optionsOld} = await formRead(); + await optionsSave(optionsNew); + formUpdateVisibility(optionsNew); + try { const ankiUpdated = optionsNew.anki.enable !== optionsOld.anki.enable || optionsNew.anki.server !== optionsOld.anki.server; @@ -162,7 +154,6 @@ async function onReady() { $('#compact-tags').prop('checked', options.general.compactTags); $('#compact-glossaries').prop('checked', options.general.compactGlossaries); $('#result-output-mode').val(options.general.resultOutputMode); - $('#main-dictionary').val(options.general.mainDictionary); $('#audio-playback-source').val(options.general.audioSource); $('#audio-playback-volume').val(options.general.audioVolume); $('#show-debug-info').prop('checked', options.general.debugInfo); @@ -194,6 +185,7 @@ async function onReady() { try { await dictionaryGroupsPopulate(options); + await formMainDictionaryOptionsPopulate(options); } catch (e) { dictionaryErrorShow(e); } @@ -204,8 +196,6 @@ async function onReady() { ankiErrorShow(e); } - await formMainDictionaryOptionsPopulate(options); - formUpdateVisibility(options); } @@ -311,7 +301,7 @@ async function dictionaryGroupsPopulate(options) { async function onDictionaryPurge(e) { e.preventDefault(); - const dictControls = $('#dict-importer, #dict-groups').hide(); + const dictControls = $('#dict-importer, #dict-groups, #dict-main-group').hide(); const dictProgress = $('#dict-purge').show(); try { @@ -352,7 +342,7 @@ async function onDictionaryImport(e) { const options = await optionsLoad(); const summary = await utilDatabaseImport(e.target.files[0], updateProgress); options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false}; - if (summary.hasSequences && !options.general.mainDictionary) { + if (summary.hasSequences && options.general.mainDictionary === '') { options.general.mainDictionary = summary.title; } await optionsSave(options); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 12556065..1565ed52 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -145,21 +145,20 @@ or you can simply purge the database to delete everything.

- Please visit the Yomichan homepage to download free - dictionaries that you can use with this extension. + Deleting individual dictionaries is not currently feasible due to limitations of browser database technology.

+
+ + +
+
Dictionary data is being purged, please be patient...
No dictionaries have been installed
-
- - -
-
Dictionary data is being imported, please be patient...
@@ -168,6 +167,10 @@
+

+ Select a dictionary to import for use below. Please visit the Yomichan + homepage to download free dictionaries to use with this extension and to learn about importing proprietary EPWING dictionaries. +

-- cgit v1.2.3