From 4103b09893ed27a951a5521fd469fa58f4661df6 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 28 May 2016 13:35:46 -0700 Subject: Improvements to options page --- ext/bg/js/options-form.js | 84 +++++++++++++++++++++++++++++++---------------- ext/bg/options.html | 4 +-- 2 files changed, 57 insertions(+), 31 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index d5d2eaee..0a39d3ea 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -33,27 +33,28 @@ function optionsToForm(opts) { $('#anki-kanji-model').val(opts.ankiKanjiModel); } -function formToOptions() { - return sanitizeOptions({ - scanLength: $('#scan-length').val(), - activateOnStartup: $('#activate-on-startup').prop('checked'), - loadEnamDict: $('#load-enamdict').prop('checked'), - selectMatchedText: $('#select-matched-text').prop('checked'), - enableAnkiConnect: $('#enable-anki-connect').prop('checked'), - ankiVocabDeck: $('#anki-vocab-deck').val(), - ankiVocabModel: $('#anki-vocab-model').val(), - ankiKanjiDeck: $('#anki-kanji-deck').val(), - ankiKanjiModel: $('#anki-kanji-model').val() - }); -} +function formToOptions(section, callback) { + loadOptions((optsOld) => { + const optsNew = $.extend({}, optsOld); + + switch (section) { + case 'general': + optsNew.scanLength = $('#scan-length').val(); + optsNew.activateOnStartup = $('#activate-on-startup').prop('checked'); + optsNew.loadEnamDict = $('#load-enamdict').prop('checked'); + optsNew.selectMatchedText = $('#select-matched-text').prop('checked'); + optsNew.enableAnkiConnect = $('#enable-anki-connect').prop('checked'); + break; + case 'anki': + optsNew.ankiVocabDeck = $('#anki-vocab-deck').val(); + optsNew.ankiVocabModel = $('#anki-vocab-model').val(); + optsNew.ankiKanjiDeck = $('#anki-kanji-deck').val(); + optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); + break; + } -function updateAnkiFormVis(opts) { - if (opts.enableAnkiConnect) { - populateAnkiDeckAndModel(); - $('.options-anki').fadeIn(); - } else { - $('.options-anki').fadeOut(); - } + callback(sanitizeOptions(optsNew), sanitizeOptions(optsOld)); + }); } function populateAnkiDeckAndModel() { @@ -72,20 +73,34 @@ function populateAnkiDeckAndModel() { yomi.api_getModelNames({callback: (names) => { if (names !== null) { names.forEach((name) => ankiModel.append($('