aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-13 13:29:35 -0800
committerAlex Yatskov <alex@foosoft.net>2016-11-13 13:29:35 -0800
commita9eea9f63497f2fe829f5b8d1ecf6c58f18b2b79 (patch)
treed8b5ee5493a1cd6dd2cf8e0786c064d7e1d1099b /ext/bg
parent2587b9ae6bb9a9b5f4fc5dd17a7f043c17596a06 (diff)
WIP
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/database.js4
-rw-r--r--ext/bg/js/options-form.js79
-rw-r--r--ext/bg/options.html7
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 @@
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
<style>
#anki-spinner, #anki-general, #anki-error,
- #dict-spinner, .dict-import-progress, .dict-delete-progress,
+ #dict-spinner, #dict-error, #dict-warning, .dict-import-progress, .dict-delete-progress,
#options-advanced {
display: none;
}
@@ -70,6 +70,11 @@
<div id="dict-groups"></div>
+ <div class="alert alert-warning" id="dict-warning">
+ <strong>No dictionaries found:</strong>
+ please use the dropdown below to install packaged and external dictionaries
+ </div>
+
<div class="alert alert-danger" id="dict-error">
<strong>Error:</strong>
<span></span>