Create function for setting up form event listeners

This commit is contained in:
toasted-nutbread 2019-09-08 12:16:12 -04:00
parent 36b39e2f65
commit 1f8c7358cb

View File

@ -121,9 +121,6 @@ async function formWrite(options) {
$('#scan-modifier-key').val(options.scanning.modifier); $('#scan-modifier-key').val(options.scanning.modifier);
$('#popup-nesting-max-depth').val(options.scanning.popupNestingMaxDepth); $('#popup-nesting-max-depth').val(options.scanning.popupNestingMaxDepth);
$('#dict-purge-link').click(utilAsync(onDictionaryPurge));
$('#dict-file').change(utilAsync(onDictionaryImport));
$('#anki-enable').prop('checked', options.anki.enable); $('#anki-enable').prop('checked', options.anki.enable);
$('#card-tags').val(options.anki.tags.join(' ')); $('#card-tags').val(options.anki.tags.join(' '));
$('#sentence-detection-extent').val(options.anki.sentenceExt); $('#sentence-detection-extent').val(options.anki.sentenceExt);
@ -131,9 +128,6 @@ async function formWrite(options) {
$('#screenshot-format').val(options.anki.screenshot.format); $('#screenshot-format').val(options.anki.screenshot.format);
$('#screenshot-quality').val(options.anki.screenshot.quality); $('#screenshot-quality').val(options.anki.screenshot.quality);
$('#field-templates').val(options.anki.fieldTemplates); $('#field-templates').val(options.anki.fieldTemplates);
$('#field-templates-reset').click(utilAsync(onAnkiFieldTemplatesReset));
$('input, select, textarea').not('.anki-model').change(utilAsync(onFormOptionsChanged));
$('.anki-model').change(utilAsync(onAnkiModelChanged));
try { try {
await dictionaryGroupsPopulate(options); await dictionaryGroupsPopulate(options);
@ -151,6 +145,15 @@ async function formWrite(options) {
formUpdateVisibility(options); formUpdateVisibility(options);
} }
function formSetupEventListeners() {
$('#dict-purge-link').click(utilAsync(onDictionaryPurge));
$('#dict-file').change(utilAsync(onDictionaryImport));
$('#field-templates-reset').click(utilAsync(onAnkiFieldTemplatesReset));
$('input, select, textarea').not('.anki-model').not('.profile-form *').change(utilAsync(onFormOptionsChanged));
$('.anki-model').change(utilAsync(onAnkiModelChanged));
}
function formUpdateVisibility(options) { function formUpdateVisibility(options) {
const general = $('#anki-general'); const general = $('#anki-general');
if (options.anki.enable) { if (options.anki.enable) {
@ -237,6 +240,7 @@ async function onReady() {
const optionsContext = getOptionsContext(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext); const options = await apiOptionsGet(optionsContext);
formSetupEventListeners();
await formWrite(options); await formWrite(options);
storageInfoInitialize(); storageInfoInitialize();