WIP
This commit is contained in:
parent
8fe82573cc
commit
6ad860bd72
@ -57,24 +57,23 @@ function getFormValues() {
|
|||||||
optsNew.dictionaries[title] = {enableTerms, enableKanji};
|
optsNew.dictionaries[title] = {enableTerms, enableKanji};
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {optsNew, optsOld};
|
||||||
optsNew: sanitizeOptions(optsNew),
|
|
||||||
optsOld: sanitizeOptions(optsOld)
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVisibility(opts) {
|
function updateVisibility(opts) {
|
||||||
|
const general = $('#anki-general');
|
||||||
if (opts.anki.enable) {
|
if (opts.anki.enable) {
|
||||||
$('#anki-general').show();
|
general.show();
|
||||||
} else {
|
} else {
|
||||||
$('#anki-general').hide();
|
general.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const advanced = $('.options-advanced');
|
||||||
if (opts.general.showAdvanced) {
|
if (opts.general.showAdvanced) {
|
||||||
$('.options-advanced').show();
|
advanced.show();
|
||||||
} else {
|
} else {
|
||||||
$('.options-advanced').hide();
|
advanced.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,18 +92,17 @@ $(document).ready(() => {
|
|||||||
$('#scan-delay').val(opts.scanning.delay);
|
$('#scan-delay').val(opts.scanning.delay);
|
||||||
$('#scan-length').val(opts.scanning.length);
|
$('#scan-length').val(opts.scanning.length);
|
||||||
|
|
||||||
$('#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-purge').click(onDictionaryPurge);
|
||||||
$('#dict-importer a').click(onDictionarySetUrl);
|
$('#dict-importer a').click(onDictionarySetUrl);
|
||||||
$('#dict-import').click(onDictionaryImport);
|
$('#dict-import').click(onDictionaryImport);
|
||||||
$('#dict-url').on('input', onDictionaryUpdateUrl);
|
$('#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);
|
||||||
|
|
||||||
populateDictionaries(opts);
|
populateDictionaries(opts);
|
||||||
populateAnkiDeckAndModel(opts);
|
populateAnkiDeckAndModel(opts);
|
||||||
updateVisibility(opts);
|
updateVisibility(opts);
|
||||||
@ -301,10 +299,10 @@ function fieldsToDict(selection) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelIdToFieldOptKey(id) {
|
function modelIdToCard(id) {
|
||||||
return {
|
return {
|
||||||
'anki-term-model': 'anki.terms.fields',
|
'anki-term-model': 'terms',
|
||||||
'anki-kanji-model': 'anki.kanji.fields'
|
'anki-kanji-model': 'kanji'
|
||||||
}[id];
|
}[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,12 +372,12 @@ function populateAnkiFields(element, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const modelId = element.attr('id');
|
const modelId = element.attr('id');
|
||||||
const optKey = modelIdToFieldOptKey(modelId);
|
const card = modelIdToCard(modelId);
|
||||||
const markers = modelIdToMarkers(modelId);
|
const markers = modelIdToMarkers(modelId);
|
||||||
|
|
||||||
return anki().getModelFieldNames(modelName).then(names => {
|
return anki().getModelFieldNames(modelName).then(names => {
|
||||||
names.forEach(name => {
|
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));
|
container.append($(html));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -401,7 +399,8 @@ function onAnkiModelChanged(e) {
|
|||||||
showAnkiSpinner(true);
|
showAnkiSpinner(true);
|
||||||
|
|
||||||
getFormValues().then(({optsNew, optsOld}) => {
|
getFormValues().then(({optsNew, optsOld}) => {
|
||||||
optsNew[modelIdToFieldOptKey($(this).id)] = {};
|
const card = modelIdToCard($(this).id);
|
||||||
|
optsNew.anki[card].fields = {};
|
||||||
populateAnkiFields($(this), optsNew).then(() => {
|
populateAnkiFields($(this), optsNew).then(() => {
|
||||||
optionsSave(optsNew).then(() => yomichan().setOptions(optsNew));
|
optionsSave(optsNew).then(() => yomichan().setOptions(optsNew));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -69,7 +69,7 @@ function optionsVersion(options) {
|
|||||||
targetDict[targetKey] = sourceDict[sourceKey] || targetDict[targetKey];
|
targetDict[targetKey] = sourceDict[sourceKey] || targetDict[targetKey];
|
||||||
};
|
};
|
||||||
|
|
||||||
const version = options.version || 0;
|
options.version = options.version || 0;
|
||||||
const fixups = [
|
const fixups = [
|
||||||
() => {
|
() => {
|
||||||
optionsSetDefaults(options);
|
optionsSetDefaults(options);
|
||||||
@ -98,8 +98,8 @@ function optionsVersion(options) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (version < fixups.length) {
|
if (options.version < fixups.length) {
|
||||||
fixups[version]();
|
fixups[options.version]();
|
||||||
++options.version;
|
++options.version;
|
||||||
optionsVersion(options);
|
optionsVersion(options);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user