diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-09-13 13:38:37 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-09-13 13:38:37 -0700 |
commit | cd4f16c096746d13502dc7b258dfe16c97344ba1 (patch) | |
tree | 0f601e128da4632440b9e2a568f9b1acbc759b0a /ext/bg/js/options-form.js | |
parent | 540d0e239c9b7dc5bee8a3e53bcf6ec0767ee80b (diff) |
Options cleanup
Diffstat (limited to 'ext/bg/js/options-form.js')
-rw-r--r-- | ext/bg/js/options-form.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 3dab0a87..a1ecccda 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -60,8 +60,8 @@ function modelIdToMarkers(id) { }[id]; } -function formToOptions(section, callback) { - loadOptions((optsOld) => { +function formToOptions(section) { + return loadOptions().then(optsOld => { const optsNew = $.extend({}, optsOld); switch (section) { @@ -86,7 +86,10 @@ function formToOptions(section, callback) { break; } - callback(sanitizeOptions(optsNew), sanitizeOptions(optsOld)); + return { + optsNew: sanitizeOptions(optsNew), + optsOld: sanitizeOptions(optsOld) + }; }); } @@ -185,8 +188,8 @@ function onOptionsGeneralChanged(e) { return; } - formToOptions('general', (optsNew, optsOld) => { - saveOptions(optsNew, () => { + formToOptions('general').then(({optsNew, optsOld}) => { + saveOptions(optsNew).then(() => { yomichan().setOptions(optsNew); if (!optsOld.enableAnkiConnect && optsNew.enableAnkiConnect) { updateAnkiStatus(); @@ -210,23 +213,23 @@ function onOptionsAnkiChanged(e) { return; } - formToOptions('anki', (opts) => { - saveOptions(opts, () => yomichan().setOptions(opts)); + formToOptions('anki').then(({optsNew, optsOld}) => { + saveOptions(optsNew).then(() => yomichan().setOptions(optsNew)); }); } function onAnkiModelChanged(e) { if (e.originalEvent) { - formToOptions('anki', (opts) => { - opts[modelIdToFieldOptKey($(this).id)] = {}; - populateAnkiFields($(this), opts); - saveOptions(opts, () => yomichan().setOptions(opts)); + formToOptions('anki').then(({optsNew, optsOld}) => { + optsNew[modelIdToFieldOptKey($(this).id)] = {}; + populateAnkiFields($(this), optsNew); + saveOptions(optsNew).then(() => yomichan().setOptions(optsNew)); }); } } $(document).ready(() => { - loadOptions((opts) => { + loadOptions().then(opts => { $('#scan-length').val(opts.scanLength); $('#activate-on-startup').prop('checked', opts.activateOnStartup); $('#load-enamdict').prop('checked', opts.loadEnamDict); |