aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-01-14 20:38:11 -0800
committerAlex Yatskov <alex@foosoft.net>2017-01-14 20:38:11 -0800
commit6ad860bd728d8cca8f30ef83c34bdba8801f0238 (patch)
tree9c3d70fdc12face72b68a217fe5d22378b31963f /ext/bg
parent8fe82573cc456fe1256989e0c3e524590a1a0acf (diff)
WIP
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/options-form.js39
-rw-r--r--ext/bg/js/options.js6
2 files changed, 22 insertions, 23 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index fcb3d50f..c0a9b22f 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -57,24 +57,23 @@ function getFormValues() {
optsNew.dictionaries[title] = {enableTerms, enableKanji};
});
- return {
- optsNew: sanitizeOptions(optsNew),
- optsOld: sanitizeOptions(optsOld)
- };
+ return {optsNew, optsOld};
});
}
function updateVisibility(opts) {
+ const general = $('#anki-general');
if (opts.anki.enable) {
- $('#anki-general').show();
+ general.show();
} else {
- $('#anki-general').hide();
+ general.hide();
}
+ const advanced = $('.options-advanced');
if (opts.general.showAdvanced) {
- $('.options-advanced').show();
+ advanced.show();
} else {
- $('.options-advanced').hide();
+ advanced.hide();
}
}
@@ -93,18 +92,17 @@ $(document).ready(() => {
$('#scan-delay').val(opts.scanning.delay);
$('#scan-length').val(opts.scanning.length);
+ $('#dict-purge').click(onDictionaryPurge);
+ $('#dict-importer a').click(onDictionarySetUrl);
+ $('#dict-import').click(onDictionaryImport);
+ $('#dict-url').on('input', onDictionaryUpdateUrl);
+
$('#anki-enable').prop('checked', opts.anki.enable);
$('#anki-card-tags').val(opts.anki.tags.join(' '));
$('#sentence-extent').val(opts.anki.sentenceExt);
-
$('input, select').not('.anki-model').change(onOptionsChanged);
$('.anki-model').change(onAnkiModelChanged);
- $('#dict-purge').click(onDictionaryPurge);
- $('#dict-importer a').click(onDictionarySetUrl);
- $('#dict-import').click(onDictionaryImport);
- $('#dict-url').on('input', onDictionaryUpdateUrl);
-
populateDictionaries(opts);
populateAnkiDeckAndModel(opts);
updateVisibility(opts);
@@ -301,10 +299,10 @@ function fieldsToDict(selection) {
return result;
}
-function modelIdToFieldOptKey(id) {
+function modelIdToCard(id) {
return {
- 'anki-term-model': 'anki.terms.fields',
- 'anki-kanji-model': 'anki.kanji.fields'
+ 'anki-term-model': 'terms',
+ 'anki-kanji-model': 'kanji'
}[id];
}
@@ -374,12 +372,12 @@ function populateAnkiFields(element, opts) {
}
const modelId = element.attr('id');
- const optKey = modelIdToFieldOptKey(modelId);
+ const card = modelIdToCard(modelId);
const markers = modelIdToMarkers(modelId);
return anki().getModelFieldNames(modelName).then(names => {
names.forEach(name => {
- const html = Handlebars.templates['model.html']({name, markers, value: opts[optKey][name] || ''});
+ const html = Handlebars.templates['model.html']({name, markers, value: opts.anki[card].fields[name] || ''});
container.append($(html));
});
@@ -401,7 +399,8 @@ function onAnkiModelChanged(e) {
showAnkiSpinner(true);
getFormValues().then(({optsNew, optsOld}) => {
- optsNew[modelIdToFieldOptKey($(this).id)] = {};
+ const card = modelIdToCard($(this).id);
+ optsNew.anki[card].fields = {};
populateAnkiFields($(this), optsNew).then(() => {
optionsSave(optsNew).then(() => yomichan().setOptions(optsNew));
}).catch(error => {
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index cc813dbf..19e028fb 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -69,7 +69,7 @@ function optionsVersion(options) {
targetDict[targetKey] = sourceDict[sourceKey] || targetDict[targetKey];
};
- const version = options.version || 0;
+ options.version = options.version || 0;
const fixups = [
() => {
optionsSetDefaults(options);
@@ -98,8 +98,8 @@ function optionsVersion(options) {
},
];
- if (version < fixups.length) {
- fixups[version]();
+ if (options.version < fixups.length) {
+ fixups[options.version]();
++options.version;
optionsVersion(options);
}