summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-01-16 22:30:53 -0800
committerAlex Yatskov <alex@foosoft.net>2017-01-16 22:30:53 -0800
commit404f3f1b164fd924a8d34521f86bf3660acdc008 (patch)
treee197a07b87a71c0907a337902aecb0e300d5d4b3 /ext/bg/js
parent268e00435f081b81ac0426bd3e316acb1bb33915 (diff)
unify dictionary enabled state
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/options-form.js14
-rw-r--r--ext/bg/js/options.js4
-rw-r--r--ext/bg/js/templates.js22
-rw-r--r--ext/bg/js/util.js12
-rw-r--r--ext/bg/js/yomichan.js38
5 files changed, 28 insertions, 62 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index f58c26cc..7139958a 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -55,9 +55,8 @@ function getFormData() {
const dictionary = $(element);
const title = dictionary.data('title');
const priority = parseInt(dictionary.find('.dict-priority').val(), 10);
- const enableTerms = dictionary.find('.dict-enable-terms').prop('checked');
- const enableKanji = dictionary.find('.dict-enable-kanji').prop('checked');
- optionsNew.dictionaries[title] = {priority, enableTerms, enableKanji};
+ const enabled = dictionary.find('.dict-enabled').prop('checked');
+ optionsNew.dictionaries[title] = {priority, enabled};
});
return {optionsNew, optionsOld};
@@ -153,18 +152,15 @@ function populateDictionaries(options) {
title: row.title,
version: row.version,
revision: row.revision,
- hasTerms: row.hasTerms,
- hasKanji: row.hasKanji,
priority: dictOptions.priority,
- enableTerms: dictOptions.enableTerms,
- enableKanji: dictOptions.enableKanji
+ enabled: dictOptions.enabled
});
dictGroups.append($(html));
++dictCount;
});
- $('.dict-enable-terms, .dict-enable-kanji, .dict-priority').change(onOptionsChanged);
+ $('.dict-enabled, .dict-priority').change(onOptionsChanged);
$('.dict-delete').click(onDictionaryDelete);
}).catch(error => {
showDictionaryError(error);
@@ -233,7 +229,7 @@ function onDictionaryImport() {
optionsLoad().then(options => {
database().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => {
- options.dictionaries[summary.title] = {enableTerms: summary.hasTerms, enableKanji: summary.hasKanji};
+ options.dictionaries[summary.title] = {enabled: true, priority: 0};
return optionsSave(options).then(() => yomichan().setOptions(options));
}).then(() => {
return populateDictionaries(options);
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 027a1539..4470c48a 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -97,7 +97,9 @@ function optionsVersion(options) {
copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
for (const title in options.dictionaries) {
- options.dictionaries[title].priority = 0;
+ const dictionary = options.dictionaries[title];
+ dictionary.enabled = dictionary.enableTerms || dictionary.enableKanji;
+ dictionary.priority = 0;
}
}
];
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 85b36de3..a36e4674 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -1,8 +1,6 @@
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) {
- return "disabled";
-},"3":function(container,depth0,helpers,partials,data) {
return "checked";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
@@ -17,25 +15,15 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ " <small>v."
+ alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper)))
- + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"form-group dict-group-controls\">\n <label for=\"dict-"
+ + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"checkbox dict-group-controls\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enabled : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + "> Enable search</label>\n </div>\n <div class=\"form-group dict-group-controls\">\n <label for=\"dict-"
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
- + "\">Priority</label>\n <input type=\"number\" value=\""
+ + "\">Result priority</label>\n <input type=\"number\" value=\""
+ alias4(((helper = (helper = helpers.priority || (depth0 != null ? depth0.priority : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"priority","hash":{},"data":data}) : helper)))
+ "\" id=\"dict-"
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
- + "\" class=\"form-control dict-priority\">\n </div>\n <div class=\"checkbox dict-group-controls "
- + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "\">\n <label><input type=\"checkbox\" class=\"dict-enable-terms\" "
- + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + " "
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enableTerms : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Enable term search</label>\n </div>\n <div class=\"checkbox dict-group-controls "
- + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "\">\n <label><input type=\"checkbox\" class=\"dict-enable-kanji\" "
- + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + " "
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enableKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Enable Kanji search</label>\n </div>\n</div>\n";
+ + "\" class=\"form-control dict-priority\">\n </div>\n</div>\n";
},"useData":true});
templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {};
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index bba4d797..dcaf1e47 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -39,6 +39,18 @@ function isKanji(c) {
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
}
+function enabledDicts(options) {
+ const dictionaries = {};
+ for (const title in options.dictionaries) {
+ const dictionary = options.dictionaries[title];
+ if (dictionary.enabled) {
+ dictionaries[title] = dictionary;
+ }
+ }
+
+ return dictionaries;
+}
+
function promiseCallback(promise, callback) {
return promise.then(result => {
callback({result});
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 494b9cda..1f337680 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -157,54 +157,22 @@ class Yomichan {
}
api_findKanji({text, callback}) {
- const dictionaries = {};
- for (const title in this.options.dictionaries) {
- const dictionary = this.options.dictionaries[title];
- if (dictionary.enableKanji) {
- dictionaries[title] = dictionary;
- }
- }
-
promiseCallback(
- this.translator.findKanji(text, dictionaries),
+ this.translator.findKanji(text, enabledDicts(this.options)),
callback
);
}
api_findTerms({text, callback}) {
- const dictionaries = {};
- for (const title in this.options.dictionaries) {
- const dictionary = this.options.dictionaries[title];
- if (dictionary.enableTerms) {
- dictionaries[title] = dictionary;
- }
- }
-
promiseCallback(
- this.translator.findTerms(
- text,
- dictionaries,
- this.options.general.softKatakana
- ),
+ this.translator.findTerms(text, enabledDicts(this.options), this.options.general.softKatakana),
callback
);
}
api_findTermsGrouped({text, callback}) {
- const dictionaries = {};
- for (const title in this.options.dictionaries) {
- const dictionary = this.options.dictionaries[title];
- if (dictionary.enableTerms) {
- dictionaries[title] = dictionary;
- }
- }
-
promiseCallback(
- this.translator.findTermsGrouped(
- text,
- dictionaries,
- this.options.general.softKatakana
- ),
+ this.translator.findTermsGrouped(text, enabledDicts(this.options), this.options.general.softKatakana),
callback
);
}