diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-01-14 20:38:11 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-01-14 20:38:11 -0800 |
commit | 6ad860bd728d8cca8f30ef83c34bdba8801f0238 (patch) | |
tree | 9c3d70fdc12face72b68a217fe5d22378b31963f /ext/bg/js/options-form.js | |
parent | 8fe82573cc456fe1256989e0c3e524590a1a0acf (diff) |
WIP
Diffstat (limited to 'ext/bg/js/options-form.js')
-rw-r--r-- | ext/bg/js/options-form.js | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index fcb3d50f..c0a9b22f 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -57,24 +57,23 @@ function getFormValues() { optsNew.dictionaries[title] = {enableTerms, enableKanji}; }); - return { - optsNew: sanitizeOptions(optsNew), - optsOld: sanitizeOptions(optsOld) - }; + return {optsNew, optsOld}; }); } function updateVisibility(opts) { + const general = $('#anki-general'); if (opts.anki.enable) { - $('#anki-general').show(); + general.show(); } else { - $('#anki-general').hide(); + general.hide(); } + const advanced = $('.options-advanced'); if (opts.general.showAdvanced) { - $('.options-advanced').show(); + advanced.show(); } else { - $('.options-advanced').hide(); + advanced.hide(); } } @@ -93,18 +92,17 @@ $(document).ready(() => { $('#scan-delay').val(opts.scanning.delay); $('#scan-length').val(opts.scanning.length); + $('#dict-purge').click(onDictionaryPurge); + $('#dict-importer a').click(onDictionarySetUrl); + $('#dict-import').click(onDictionaryImport); + $('#dict-url').on('input', onDictionaryUpdateUrl); + $('#anki-enable').prop('checked', opts.anki.enable); $('#anki-card-tags').val(opts.anki.tags.join(' ')); $('#sentence-extent').val(opts.anki.sentenceExt); - $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); - $('#dict-purge').click(onDictionaryPurge); - $('#dict-importer a').click(onDictionarySetUrl); - $('#dict-import').click(onDictionaryImport); - $('#dict-url').on('input', onDictionaryUpdateUrl); - populateDictionaries(opts); populateAnkiDeckAndModel(opts); updateVisibility(opts); @@ -301,10 +299,10 @@ function fieldsToDict(selection) { return result; } -function modelIdToFieldOptKey(id) { +function modelIdToCard(id) { return { - 'anki-term-model': 'anki.terms.fields', - 'anki-kanji-model': 'anki.kanji.fields' + 'anki-term-model': 'terms', + 'anki-kanji-model': 'kanji' }[id]; } @@ -374,12 +372,12 @@ function populateAnkiFields(element, opts) { } const modelId = element.attr('id'); - const optKey = modelIdToFieldOptKey(modelId); + const card = modelIdToCard(modelId); const markers = modelIdToMarkers(modelId); return anki().getModelFieldNames(modelName).then(names => { names.forEach(name => { - const html = Handlebars.templates['model.html']({name, markers, value: opts[optKey][name] || ''}); + const html = Handlebars.templates['model.html']({name, markers, value: opts.anki[card].fields[name] || ''}); container.append($(html)); }); @@ -401,7 +399,8 @@ function onAnkiModelChanged(e) { showAnkiSpinner(true); getFormValues().then(({optsNew, optsOld}) => { - optsNew[modelIdToFieldOptKey($(this).id)] = {}; + const card = modelIdToCard($(this).id); + optsNew.anki[card].fields = {}; populateAnkiFields($(this), optsNew).then(() => { optionsSave(optsNew).then(() => yomichan().setOptions(optsNew)); }).catch(error => { |