diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 5859350b..008bc483 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -131,7 +131,7 @@ class Dictionary {
});
}
- getNames() {
+ getInfo() {
if (this.db === null) {
return Promise.reject('database not initialized');
}
@@ -144,8 +144,8 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const indexLoaded = (dictionary, version, entities) => {
- return this.db.dictionaries.add({dictionary, version}).then(() => {
+ const indexLoaded = (dictionary, version, entities, hasTerms, hasKanji) => {
+ return this.db.dictionaries.add({dictionary, version, hasTerms, hasKanji}).then(() => {
this.entities = entities || {};
const rows = [];
@@ -161,7 +161,7 @@ class Dictionary {
});
};
- const termsLoaded = (dictionary, version, entries, total, current) => {
+ const termsLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [expression, reading, tags, ...glossary] of entries) {
rows.push({
@@ -180,7 +180,7 @@ class Dictionary {
});
};
- const kanjiLoaded = (dictionary, version, entries, total, current) => {
+ const kanjiLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
rows.push({
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index 060ee269..ec603eed 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -155,25 +155,21 @@ function populateAnkiDeckAndModel(opts) {
}
function populateDictionaries() {
- // const dictGroups = $('.dictionaries');
- // dictGroups.empty();
+ const dictGroups = $('.dictionaries');
+ dictGroups.empty();
- // yomichan().translator.dictionary.getNames().then(rows => {
- // for (const row of rows) {
- // const dictPanel = $('
', {class: 'dictionary panel panel-default'});
- // const dictRow = $('
', {class: 'panel-body row'}).appendTo(dictPanel);
+ yomichan().translator.dictionary.getInfo().then(rows => {
+ for (const row of rows) {
+ const html = Handlebars.templates['dictionary.html']({
+ name: row.dictionary,
+ version: row.version,
+ hasTerms: row.hasTerms,
+ hasKanji: row.hasKanji
+ });
- // const title = $('
', {class: 'col-xs-8'});
- // $('
').append().html(` ${row.dictionary} v.${row.version} `).appendTo(title);
- // title.appendTo(dictRow);
-
- // const controls = $('', {class: 'col-xs-4 text-right'});
- // $('
', {class: 'btn btn-danger dictionary-delete'}).text('Delete').appendTo(controls);
- // controls.appendTo(dictRow);
-
- // dictGroups.append(dictPanel);
- // }
- // });
+ dictGroups.append($(html));
+ }
+ });
}
function populateAnkiFields(element, opts) {
@@ -276,6 +272,8 @@ function onAnkiModelChanged(e) {
}
$(document).ready(() => {
+ Handlebars.partials = Handlebars.templates;
+
loadOptions().then(opts => {
$('#activate-on-startup').prop('checked', opts.activateOnStartup);
$('#enable-audio-playback').prop('checked', opts.enableAudioPlayback);
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 70920cec..d9825914 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -1,5 +1,23 @@
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
+templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) {
+ return " \n Enable term search \n
\n";
+},"3":function(container,depth0,helpers,partials,data) {
+ return " \n Enable Kanji search \n
\n";
+},"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;
+
+ return "\n
\n
\n
"
+ + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
+ + " 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)))
+ + " \n \n
\n Delete \n
\n
\n\n"
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + "
\n";
+},"useData":true});
templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper;
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index eaa7dd01..e99cdeab 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -121,7 +121,13 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) {
const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
return loadJson(indexUrl).then(index => {
if (indexLoaded !== null) {
- return indexLoaded(index.title, index.version).then(() => index);
+ return indexLoaded(
+ index.title,
+ index.version,
+ index.entities,
+ index.termBanks > 0,
+ index.kanjiBanks > 0
+ ).then(() => index);
}
return index;
@@ -134,7 +140,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) {
const bankUrl = `${indexDir}/term_bank_${i}.json`;
loaders.push(() => loadJson(bankUrl).then(entries => termsLoaded(
index.title,
- index.version,
entries,
banksTotal,
banksLoaded++
@@ -145,7 +150,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) {
const bankUrl = `${indexDir}/kanji_bank_${i}.json`;
loaders.push(() => loadJson(bankUrl).then(entries => kanjiLoaded(
index.title,
- index.version,
entries,
banksTotal,
banksLoaded++
diff --git a/ext/bg/options.html b/ext/bg/options.html
index 1136eefc..acd786cf 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -124,18 +124,18 @@
@@ -217,6 +217,8 @@
+
+