From 67990f4cb911cb3552b38bb92037b1774e58a353 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 1 Dec 2019 15:41:09 -0500 Subject: [PATCH] Move anki settings into new script --- ext/bg/js/settings/anki.js | 289 +++++++++++++++++++++++++++++++++++++ ext/bg/js/settings/main.js | 276 ----------------------------------- ext/bg/settings.html | 1 + 3 files changed, 290 insertions(+), 276 deletions(-) create mode 100644 ext/bg/js/settings/anki.js diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js new file mode 100644 index 00000000..5b8e5eec --- /dev/null +++ b/ext/bg/js/settings/anki.js @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +function ankiSpinnerShow(show) { + const spinner = $('#anki-spinner'); + if (show) { + spinner.show(); + } else { + spinner.hide(); + } +} + +function ankiErrorShow(error) { + const dialog = $('#anki-error'); + if (error) { + dialog.show().text(error); + } + else { + dialog.hide(); + } +} + +function ankiErrorShown() { + return $('#anki-error').is(':visible'); +} + +function ankiFieldsToDict(selection) { + const result = {}; + selection.each((index, element) => { + result[$(element).data('field')] = $(element).val(); + }); + + return result; +} + +async function ankiDeckAndModelPopulate(options) { + const ankiFormat = $('#anki-format').hide(); + + const deckNames = await utilAnkiGetDeckNames(); + const ankiDeck = $('.anki-deck'); + ankiDeck.find('option').remove(); + deckNames.sort().forEach((name) => ankiDeck.append($('