diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-11-13 19:10:28 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-11-13 19:10:28 -0800 |
commit | a9fb56688434164e30f8f94868c652be7e7d69ad (patch) | |
tree | 42ce5def7b99441e676957ef8fbad3007fbf4bfa /ext/bg/js | |
parent | 1d29dd8ba765d7f7dfec69dfd783016c086989b3 (diff) |
WIP
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); |