cleanup
This commit is contained in:
parent
a22facec98
commit
dcaf345549
@ -49,7 +49,7 @@ async function formRead() {
|
|||||||
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
|
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
|
||||||
optionsNew.anki.server = $('#interface-server').val();
|
optionsNew.anki.server = $('#interface-server').val();
|
||||||
|
|
||||||
if (optionsOld.anki.enable && !$('#anki-error').is(':visible')) {
|
if (optionsOld.anki.enable && !ankiErrorShown()) {
|
||||||
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
|
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
|
||||||
optionsNew.anki.terms.model = $('#anki-terms-model').val();
|
optionsNew.anki.terms.model = $('#anki-terms-model').val();
|
||||||
optionsNew.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value'));
|
optionsNew.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value'));
|
||||||
@ -69,7 +69,7 @@ async function formRead() {
|
|||||||
return {optionsNew, optionsOld};
|
return {optionsNew, optionsOld};
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVisibility(options) {
|
function formUpdateVisibility(options) {
|
||||||
const general = $('#anki-general');
|
const general = $('#anki-general');
|
||||||
if (options.anki.enable) {
|
if (options.anki.enable) {
|
||||||
general.show();
|
general.show();
|
||||||
@ -94,7 +94,7 @@ function updateVisibility(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onOptionsChanged(e) { (async () => {
|
async function onFormOptionsChanged(e) { (async () => {
|
||||||
if (!e.originalEvent && !e.isTrigger) {
|
if (!e.originalEvent && !e.isTrigger) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ async function onOptionsChanged(e) { (async () => {
|
|||||||
const {optionsNew, optionsOld} = await formRead();
|
const {optionsNew, optionsOld} = await formRead();
|
||||||
await optionsSave(optionsNew);
|
await optionsSave(optionsNew);
|
||||||
|
|
||||||
updateVisibility(optionsNew);
|
formUpdateVisibility(optionsNew);
|
||||||
|
|
||||||
const ankiUpdated =
|
const ankiUpdated =
|
||||||
optionsNew.anki.enable !== optionsOld.anki.enable ||
|
optionsNew.anki.enable !== optionsOld.anki.enable ||
|
||||||
@ -153,7 +153,7 @@ function onReady() {(async () => {
|
|||||||
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
|
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
|
||||||
$('#sentence-detection-extent').val(options.anki.sentenceExt);
|
$('#sentence-detection-extent').val(options.anki.sentenceExt);
|
||||||
$('#interface-server').val(options.anki.server);
|
$('#interface-server').val(options.anki.server);
|
||||||
$('input, select').not('.anki-model').change(onOptionsChanged);
|
$('input, select').not('.anki-model').change(onFormOptionsChanged);
|
||||||
$('.anki-model').change(onAnkiModelChanged);
|
$('.anki-model').change(onAnkiModelChanged);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -168,7 +168,7 @@ function onReady() {(async () => {
|
|||||||
ankiErrorShow(e);
|
ankiErrorShow(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVisibility(options);
|
formUpdateVisibility(options);
|
||||||
})();}
|
})();}
|
||||||
|
|
||||||
$(document).ready(onReady);
|
$(document).ready(onReady);
|
||||||
@ -235,11 +235,11 @@ async function dictionaryGroupsPopulate(options) {
|
|||||||
dictGroups.append($(dictHtml));
|
dictGroups.append($(dictHtml));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVisibility(options);
|
formUpdateVisibility(options);
|
||||||
|
|
||||||
$('.dict-enabled, .dict-priority').change(e => {
|
$('.dict-enabled, .dict-priority').change(e => {
|
||||||
dictionaryGroupsSort();
|
dictionaryGroupsSort();
|
||||||
onOptionsChanged(e);
|
onFormOptionsChanged(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +322,10 @@ function ankiErrorShow(error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ankiErrorShown() {
|
||||||
|
return $('#anki-error').is(':visible');
|
||||||
|
}
|
||||||
|
|
||||||
function ankiFieldsToDict(selection) {
|
function ankiFieldsToDict(selection) {
|
||||||
const result = {};
|
const result = {};
|
||||||
selection.each((index, element) => {
|
selection.each((index, element) => {
|
||||||
@ -333,6 +337,11 @@ function ankiFieldsToDict(selection) {
|
|||||||
|
|
||||||
async function ankiDeckAndModelPopulate(options) {
|
async function ankiDeckAndModelPopulate(options) {
|
||||||
const ankiFormat = $('#anki-format').hide();
|
const ankiFormat = $('#anki-format').hide();
|
||||||
|
const ankiTermsModel = $('#anki-terms-model').val(options.anki.terms.model);
|
||||||
|
const ankiKanjiModel = $('#anki-kanji-model').val(options.anki.kanji.model);
|
||||||
|
|
||||||
|
$('#anki-terms-deck').val(options.anki.terms.deck);
|
||||||
|
$('#anki-kanji-deck').val(options.anki.kanji.deck);
|
||||||
|
|
||||||
const deckNames = await instAnki().getDeckNames();
|
const deckNames = await instAnki().getDeckNames();
|
||||||
const ankiDeck = $('.anki-deck');
|
const ankiDeck = $('.anki-deck');
|
||||||
@ -344,11 +353,8 @@ async function ankiDeckAndModelPopulate(options) {
|
|||||||
ankiModel.find('option').remove();
|
ankiModel.find('option').remove();
|
||||||
modelNames.sort().forEach(name => ankiModel.append($('<option/>', {value: name, text: name})));
|
modelNames.sort().forEach(name => ankiModel.append($('<option/>', {value: name, text: name})));
|
||||||
|
|
||||||
$('#anki-terms-deck').val(options.anki.terms.deck);
|
await ankiFieldsPopulate(ankiTermsModel, options);
|
||||||
await ankiFieldsPopulate($('#anki-terms-model').val(options.anki.terms.model), options);
|
await ankiFieldsPopulate(ankiKanjiModel, options);
|
||||||
|
|
||||||
$('#anki-kanji-deck').val(options.anki.kanji.deck);
|
|
||||||
await ankiFieldsPopulate($('#anki-kanji-model').val(options.anki.kanji.model), options);
|
|
||||||
|
|
||||||
ankiFormat.show();
|
ankiFormat.show();
|
||||||
}
|
}
|
||||||
@ -397,12 +403,14 @@ async function ankiFieldsPopulate(element, options) {
|
|||||||
container.append($(html));
|
container.append($(html));
|
||||||
}
|
}
|
||||||
|
|
||||||
tab.find('.anki-field-value').change(onOptionsChanged);
|
tab.find('.anki-field-value').change(onFormOptionsChanged);
|
||||||
tab.find('.marker-link').click(e => {
|
tab.find('.marker-link').click(onAnkiMarkerClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAnkiMarkerClicked(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const link = e.target;
|
const link = e.target;
|
||||||
$(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change');
|
$(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAnkiModelChanged(e) { (async () => {
|
function onAnkiModelChanged(e) { (async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user