summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-05-28 14:45:10 -0700
committerAlex Yatskov <alex@foosoft.net>2016-05-28 14:45:10 -0700
commit9c51f2ecda326157a5afa5962dee79c1344c9e1f (patch)
tree83026e3f3dbf3577c01cc31f6f0e21a808f45eb4
parent5f8cd0653389ddda06055d51c92129f2225a7cdc (diff)
More work on options page
-rw-r--r--ext/bg/js/options-form.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index 2a8a086b..849916bd 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -60,25 +60,24 @@ function populateAnkiDeckAndModel(opts) {
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');
}
+
+ $('#anki-vocab-deck').val(opts.ankiVocabDeck);
+ populateAnkiFields($('#anki-vocab-model').val(opts.ankiVocabModel), opts);
+ $('#anki-kanji-deck').val(opts.ankiKanjiDeck);
+ populateAnkiFields($('#anki-kanji-model').val(opts.ankiKanjiModel), opts);
}});
}});
}
-function populateAnkiFields(control) {
- const modelName = control.val();
+function populateAnkiFields(element, opts) {
+ const modelName = element.val();
if (modelName === null) {
return;
}
yomichan().api_getModelFieldNames({modelName, callback: (names) => {
- const table = control.closest('.tab-pane').find('.anki-fields');
+ const table = element.closest('.tab-pane').find('.anki-fields');
table.find('tbody').remove();
const body = $('<tbody>');
@@ -126,7 +125,9 @@ $(document).ready(() => {
$('.options-general input').change(onOptionsGeneralChanged);
$('.options-anki input, .options-anki select').change(onOptionsAnkiChanged);
- $('.anki-model').change((e) => populateAnkiFields($(e.currentTarget)));
+ $('.anki-model').change((e) => {
+ loadOptions((opts) => populateAnkiFields($(e.currentTarget), opts));
+ });
$('#enable-anki-connect').change((e) => {
if ($(e.currentTarget).prop('checked')) {
$('.options-anki').fadeIn();