diff options
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/database.js | 12 | ||||
-rw-r--r-- | ext/bg/js/options-form.js | 27 |
2 files changed, 33 insertions, 6 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 5931e172..0621f1d6 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -39,6 +39,18 @@ class Database { return this.db.open(); } + purge() { + if (this.db === null) { + return Promise.reject('database not initialized'); + } + + this.db.close(); + return this.db.delete().then(() => { + this.db = null; + this.prepare(); + }); + } + findTerm(term, dictionaries) { if (this.db === null) { return Promise.reject('database not initialized'); diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 015c9a0a..68a18d8f 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -134,20 +134,19 @@ function onDictionaryDelete() { dictProgress.find('div').css('width', `${current / total * 100.0}%`); }; - database().deleteDictionary(dictGroup.data('title'), callback).then(() => { - dictGroup.slideUp(); - }).catch(error => { + database().deleteDictionary(dictGroup.data('title'), callback).catch(error => { dictError.show().find('span').text(error); }).then(() => { dictSpinner.hide(); dictProgress.hide(); dictControls.show(); + return loadOptions().then(opts => populateDictionaries(opts)); }); } function onDictionaryImport() { - const dictImport = $(this); - dictImport.prop('disabled', true); + const dictImporter = $('#dict-importer'); + dictImporter.hide(); const dictError = $('#dict-error'); dictError.hide(); @@ -174,7 +173,7 @@ function onDictionaryImport() { }).catch(error => { dictError.show().find('span').text(error); }).then(() => { - dictImport.prop('disabled', false); + dictImporter.show(); dictUrl.val(''); dictUrl.trigger('input'); dictProgress.hide(); @@ -313,6 +312,21 @@ function populateDictionaries(opts) { }); } +function onPurgeDb() { + const dictError = $('#dict-error'); + dictError.hide(); + + const dictSpinner = $('#dict-spinner'); + dictSpinner.show(); + + return database().purge().catch(error => { + dictError.show().find('span').text(error); + }).then(() => { + dictSpinner.hide(); + return loadOptions().then(opts => populateDictionaries(opts)); + }); +} + function onOptionsChanged(e) { if (!e.originalEvent && !e.isTrigger) { return; @@ -383,6 +397,7 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + $('#dict-purge').click(onPurgeDb); $('#dict-importer a').click(onDictionarySetUrl); $('#dict-import').click(onDictionaryImport); $('#dict-url').on('input', onDictionaryUpdateUrl); |