diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-05-28 14:18:43 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-05-28 14:18:43 -0700 |
commit | 5f8cd0653389ddda06055d51c92129f2225a7cdc (patch) | |
tree | 8f26db305932e8d9b685d3520a16ac035e53eec8 /ext/bg/js/options-form.js | |
parent | 281b8018a67c34cc5518904b6c78f1ee0c497f77 (diff) |
Show proper options
Diffstat (limited to 'ext/bg/js/options-form.js')
-rw-r--r-- | ext/bg/js/options-form.js | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 6001d145..2a8a086b 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -21,21 +21,6 @@ function yomichan() { return chrome.extension.getBackgroundPage().yomichan; } -function optionsToForm(opts) { - $('#scan-length').val(opts.scanLength); - $('#activate-on-startup').prop('checked', opts.activateOnStartup); - $('#load-enamdict').prop('checked', opts.loadEnamDict); - $('#select-matched-text').prop('checked', opts.selectMatchedText); - $('#enable-anki-connect').prop('checked', opts.enableAnkiConnect); - - if (opts.enableAnkiConnect) { - $('#anki-vocab-deck').val(opts.ankiVocabDeck); - $('#anki-vocab-model').val(opts.ankiVocabModel); - $('#anki-kanji-deck').val(opts.ankiKanjiDeck); - $('#anki-kanji-model').val(opts.ankiKanjiModel); - } -} - function formToOptions(section, callback) { loadOptions((optsOld) => { const optsNew = $.extend({}, optsOld); @@ -60,7 +45,7 @@ function formToOptions(section, callback) { }); } -function populateAnkiDeckAndModel() { +function populateAnkiDeckAndModel(opts) { const yomi = yomichan(); const ankiDeck = $('.anki-deck'); @@ -69,15 +54,20 @@ function populateAnkiDeckAndModel() { if (names !== null) { names.forEach((name) => ankiDeck.append($('<option/>', {value: name, text: name}))); } - }}); - const ankiModel = $('.anki-model'); - ankiModel.find('option').remove(); - yomi.api_getModelNames({callback: (names) => { - if (names !== null) { - names.forEach((name) => ankiModel.append($('<option/>', {value: name, text: name}))); - ankiModel.trigger('change'); - } + const ankiModel = $('.anki-model'); + ankiModel.find('option').remove(); + yomi.api_getModelNames({callback: (names) => { + if (names !== null) { + names.forEach((name) => ankiModel.append($('<option/>', {value: name, text: name}))); + + $('#anki-vocab-deck').val(opts.ankiVocabDeck); + $('#anki-vocab-model').val(opts.ankiVocabModel); + $('#anki-kanji-deck').val(opts.ankiKanjiDeck); + $('#anki-kanji-model').val(opts.ankiKanjiModel); + ankiModel.trigger('change'); + } + }}); }}); } @@ -112,7 +102,7 @@ function onOptionsGeneralChanged(e) { saveOptions(optsNew, () => { yomichan().setOptions(optsNew); if (!optsOld.enableAnkiConnect && optsNew.enableAnkiConnect) { - populateAnkiDeckAndModel(); + populateAnkiDeckAndModel(optsNew); } }); }); @@ -128,7 +118,11 @@ function onOptionsAnkiChanged(e) { $(document).ready(() => { loadOptions((opts) => { - optionsToForm(opts); + $('#scan-length').val(opts.scanLength); + $('#activate-on-startup').prop('checked', opts.activateOnStartup); + $('#load-enamdict').prop('checked', opts.loadEnamDict); + $('#select-matched-text').prop('checked', opts.selectMatchedText); + $('#enable-anki-connect').prop('checked', opts.enableAnkiConnect); $('.options-general input').change(onOptionsGeneralChanged); $('.options-anki input, .options-anki select').change(onOptionsAnkiChanged); @@ -142,7 +136,7 @@ $(document).ready(() => { }); if (opts.enableAnkiConnect) { - populateAnkiDeckAndModel(); + populateAnkiDeckAndModel(opts); $('.options-anki').show(); } }); |