diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-05-21 17:44:02 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-05-21 17:44:02 -0700 |
commit | 5f97e8d16a18873f2a4f3cac47d295280764a142 (patch) | |
tree | 5f64b4e0d96655936dd2a6e9efd84430e5e73611 /ext/bg/js/options-form.js | |
parent | ad54735a80ede1980eca4ab51273256c5fd8d3bd (diff) |
WIP
Diffstat (limited to 'ext/bg/js/options-form.js')
-rw-r--r-- | ext/bg/js/options-form.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index a77419ff..93755745 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -35,46 +35,47 @@ function formToOptions() { }); } -function updateVisibility() { - if ($('#enableAnkiConnect').prop('checked')) { +function updateAnkiFormDataVis(opts) { + if (opts.enableAnkiConnect) { + updateAnkiFormData(); $('.options-anki').show(); } else { $('.options-anki').hide(); } } -function updateAnkiPage() { +function updateAnkiFormData() { const yomichan = chrome.extension.getBackgroundPage().yomichan; - $('#ankiDeck').find('option').remove(); - $('#ankiModel').find('option').remove(); - - yomichan.getDeckNames((names) => { - names.forEach((name) => { - $('#ankiDeck').append($('<option/>', {value: name, text: name})); - }); + const ankiDeck = $('#ankiDeck'); + ankiDeck.find('option').remove(); + yomichan.api_getDeckNames((names) => { + if (names !== null) { + names.forEach((name) => ankiDeck.append($('<option/>', {value: name, text: name}))); + } }); - yomichan.getModelNames((names) => { - names.forEach((name) => { - $('#ankiModel').append($('<option/>', {value: name, text: name})); - }); + const ankiModel = $('#ankiModel'); + ankiModel.find('option').remove(); + yomichan.api_getModelNames((names) => { + if (names !== null) { + names.forEach((name) => ankiModel.append($('<option/>', {value: name, text: name}))); + } }); } function onOptionsChanged() { - updateVisibility(); const opts = formToOptions(); saveOptions(opts, () => { chrome.extension.getBackgroundPage().yomichan.setOptions(opts); + updateAnkiFormDataVis(opts); }); } $(document).ready(() => { loadOptions((opts) => { optionsToForm(opts); - updateVisibility(); - updateAnkiPage(); + updateAnkiFormDataVis(opts); $('input').on('input paste change', onOptionsChanged); }); }); |