From a9eea9f63497f2fe829f5b8d1ecf6c58f18b2b79 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 13 Nov 2016 13:29:35 -0800 Subject: WIP --- ext/bg/js/database.js | 4 +-- ext/bg/js/options-form.js | 79 ++++++++++++++++++++++++++--------------------- ext/bg/options.html | 7 ++++- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 6a171dd4..23041e40 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -159,7 +159,7 @@ class Database { let termDeleter = Promise.resolve(); if (info.hasTerms) { const termDeleterFunc = () => { - return this.db.terms.where('dictionary').equals(title).limit(1000).delete().then(count => { + return this.db.terms.where('dictionary').equals(title).limit(500).delete().then(count => { if (count === 0) { return Promise.resolve(); } @@ -179,7 +179,7 @@ class Database { let kanjiDeleter = Promise.resolve(); if (info.hasKanji) { const kanjiDeleterFunc = () => { - return this.db.kanji.where('dictionary').equals(title).limit(1000).delete().then(count => { + return this.db.kanji.where('dictionary').equals(title).limit(500).delete().then(count => { if (count === 0) { return Promise.resolve(); } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 736ec023..2cabe162 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -115,40 +115,6 @@ function updateVisibility(opts) { } } -function populateDictionaries(opts) { - const dictGroups = $('#dict-groups'); - dictGroups.empty(); - - const dictError = $('#dict-error'); - dictError.hide(); - - const dictSpinner = $('#dict-spinner'); - dictSpinner.show(); - - return database().getDictionaries().then(rows => { - rows.forEach(row => { - const dictOpts = opts.dictionaries[row.title] || {enableTerms: false, enableKanji: false}; - const html = Handlebars.templates['dictionary.html']({ - title: row.title, - version: row.version, - hasTerms: row.hasTerms, - hasKanji: row.hasKanji, - enableTerms: dictOpts.enableTerms, - enableKanji: dictOpts.enableKanji - }); - - dictGroups.append($(html)); - }); - - $('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged); - $('.dict-delete').click(onDictionaryDelete); - }).catch(error => { - dictError.show().find('span').text(error); - }).then(() => { - dictSpinner.hide(); - }); -} - function onDictionaryDelete() { const dictGroup = $(this).closest('.dict-group'); @@ -199,7 +165,7 @@ function onDictionaryImport() { const dictUrl = $('#dict-url'); loadOptions().then(opts => { database().importDictionary(dictUrl.val(), callback).then(summary => { - opts.dictionaries[summary.title] = {hasTerms: summary.hasTerms, hasKanji: summary.hasKanji}; + opts.dictionaries[summary.title] = {enableTerms: summary.hasTerms, enableKanji: summary.hasKanji}; return saveOptions(opts); }).then(() => { return populateDictionaries(opts); @@ -302,6 +268,49 @@ function populateAnkiFields(element, opts) { }); } +function populateDictionaries(opts) { + const dictGroups = $('#dict-groups'); + dictGroups.empty(); + + const dictError = $('#dict-error'); + dictError.hide(); + + const dictWarning = $('#dict-warning'); + dictWarning.hide(); + + const dictSpinner = $('#dict-spinner'); + dictSpinner.show(); + + let dictCount = 0; + return database().getDictionaries().then(rows => { + rows.forEach(row => { + const dictOpts = opts.dictionaries[row.title] || {enableTerms: false, enableKanji: false}; + const html = Handlebars.templates['dictionary.html']({ + title: row.title, + version: row.version, + hasTerms: row.hasTerms, + hasKanji: row.hasKanji, + enableTerms: dictOpts.enableTerms, + enableKanji: dictOpts.enableKanji + }); + + dictGroups.append($(html)); + ++dictCount; + }); + + $('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged); + $('.dict-delete').click(onDictionaryDelete); + }).catch(error => { + dictError.show().find('span').text(error); + }).then(() => { + if (dictCount === 0) { + dictWarning.show(); + } + + dictSpinner.hide(); + }); +} + function onOptionsChanged(e) { if (!e.originalEvent && !e.isTrigger) { return; diff --git a/ext/bg/options.html b/ext/bg/options.html index 4f74a58e..5d949bc2 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -7,7 +7,7 @@