diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-01-15 11:37:05 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-01-15 11:37:05 -0800 |
commit | a5aff370e4b514218b4984de270ee8e082a5c333 (patch) | |
tree | 0e358e7b79ff90a8924942e072291aa07b5fc361 /ext/bg/js/options-form.js | |
parent | b5e1a9e26089fec647d20275e8a4cbd453679a6a (diff) |
don't wipe options when disabling anki support (fixes #27)
Diffstat (limited to 'ext/bg/js/options-form.js')
-rw-r--r-- | ext/bg/js/options-form.js | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 2a49a148..af918aa6 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -24,7 +24,7 @@ function yomichan() { return chrome.extension.getBackgroundPage().yomichan; } -function getFormValues() { +function getFormData() { return optionsLoad().then(optionsOld => { const optionsNew = $.extend(true, {}, optionsOld); @@ -42,12 +42,14 @@ function getFormValues() { optionsNew.anki.enable = $('#anki-enable').prop('checked'); optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/); optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10); - optionsNew.anki.terms.deck = $('#anki-terms-deck').val(); - optionsNew.anki.terms.model = $('#anki-terms-model').val(); - optionsNew.anki.terms.fields = fieldsToDict($('#terms .anki-field-value')); - optionsNew.anki.kanji.deck = $('#anki-kanji-deck').val(); - optionsNew.anki.kanji.model = $('#anki-kanji-model').val(); - optionsNew.anki.kanji.fields = fieldsToDict($('#kanji .anki-field-value')); + if (optionsOld.anki.enable) { + optionsNew.anki.terms.deck = $('#anki-terms-deck').val(); + optionsNew.anki.terms.model = $('#anki-terms-model').val(); + optionsNew.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value')); + optionsNew.anki.kanji.deck = $('#anki-kanji-deck').val(); + optionsNew.anki.kanji.model = $('#anki-kanji-model').val(); + optionsNew.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value')); + } $('.dict-group').each((index, element) => { const dictionary = $(element); @@ -290,7 +292,7 @@ function showAnkiError(error) { } } -function fieldsToDict(selection) { +function ankiFieldsToDict(selection) { const result = {}; selection.each((index, element) => { result[$(element).data('field')] = $(element).val(); @@ -369,7 +371,7 @@ function onAnkiModelChanged(e) { showAnkiSpinner(true); const element = $(this); - getFormValues().then(({optionsNew, optionsOld}) => { + getFormData().then(({optionsNew, optionsOld}) => { const tab = element.closest('.tab-pane'); const tabId = tab.attr('id'); @@ -389,7 +391,7 @@ function onOptionsChanged(e) { return; } - getFormValues().then(({optionsNew, optionsOld}) => { + getFormData().then(({optionsNew, optionsOld}) => { return optionsSave(optionsNew).then(() => { yomichan().setOptions(optionsNew); updateVisibility(optionsNew); |