summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-10 19:36:45 -0800
committerAlex Yatskov <alex@foosoft.net>2016-11-10 19:36:45 -0800
commit0ff41d5843b3bf39994ae32e4ab623bfe0e4e3ca (patch)
treeb1eb44335b0004c9e5243db8db5ed90b4a52a942
parent8b5ee629311065bc53537d5684931dbf775c4e3e (diff)
Delete dictionary deletion
-rw-r--r--ext/bg/js/database.js73
-rw-r--r--ext/bg/js/options-form.js33
-rw-r--r--ext/bg/js/templates.js6
-rw-r--r--ext/bg/options.html6
-rw-r--r--tmpl/dictionary.html17
5 files changed, 10 insertions, 125 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index e3a62886..24ee7c03 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -141,79 +141,6 @@ class Database {
return this.db.dictionaries.toArray();
}
- deleteDictionary(title, callback) {
- if (this.db === null) {
- return Promise.reject('database not initialized');
- }
-
- return this.db.dictionaries.where('title').equals(title).first(info => {
- if (!info) {
- return;
- }
-
- let termCounter = Promise.resolve(0);
- if (info.hasTerms) {
- termCounter = this.db.terms.where('dictionary').equals(title).count();
- }
-
- let kanjiCounter = Promise.resolve(0);
- if (info.hasKanji) {
- kanjiCounter = this.db.kanji.where('dictionary').equals(title).count();
- }
-
- return Promise.all([termCounter, kanjiCounter]).then(([termCount, kanjiCount]) => {
- const totalCount = termCount + kanjiCount;
- let deletedCount = 0;
-
- let termDeleter = Promise.resolve();
- if (info.hasTerms) {
- const termDeleterFunc = () => {
- return this.db.terms.where('dictionary').equals(title).limit(1000).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return termDeleterFunc();
- });
- };
-
- termDeleter = termDeleterFunc();
- }
-
- let kanjiDeleter = Promise.resolve();
- if (info.hasKanji) {
- const kanjiDeleterFunc = () => {
- return this.db.kanji.where('dictionary').equals(title).limit(1000).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return kanjiDeleterFunc();
- });
- };
-
- kanjiDeleter = kanjiDeleterFunc();
- }
-
- return Promise.all([termDeleter, kanjiDeleter]);
- });
- }).then(() => {
- return this.db.entities.where('dictionary').equals(title).delete();
- }).then(() => {
- return this.db.dictionaries.where('title').equals(title).delete();
- });
- }
-
importDictionary(indexUrl, callback) {
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 1f64f8d0..501848ad 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -141,7 +141,6 @@ function populateDictionaries(opts) {
});
$('.dict-enable-terms, .dict-enable.kanji').change(onOptionsChanged);
- $('.dict-delete').click(onDictionaryDelete);
}).catch(error => {
dictError.show().find('span').text(error);
}).then(() => {
@@ -149,36 +148,6 @@ function populateDictionaries(opts) {
});
}
-function onDictionaryDelete() {
- const dictGroup = $(this).closest('.dict-group');
-
- const dictError = $('#dict-error');
- dictError.hide();
-
- const dictSpinner = $('#dict-spinner');
- dictSpinner.show();
-
- const dictProgress = dictGroup.find('.dict-delete-progress');
- dictProgress.show();
-
- const dictControls = dictGroup.find('.dict-controls');
- dictControls.hide();
-
- const callback = (total, current) => {
- dictProgress.find('div').css('width', `${current / total * 100.0}%`);
- };
-
- database().deleteDictionary(dictGroup.data('title'), callback).then(() => {
- dictGroup.slideUp();
- }).catch(error => {
- dictError.show().find('span').text(error);
- }).then(() => {
- dictSpinner.hide();
- dictProgress.hide();
- dictControls.show();
- });
-}
-
function onDictionaryImport() {
const dictImport = $(this);
dictImport.prop('disabled', true);
@@ -186,7 +155,7 @@ function onDictionaryImport() {
const dictError = $('#dict-error');
dictError.hide();
- const dictProgress = $('.dict-import-progress');
+ const dictProgress = $('.dict-progress');
dictProgress.show();
const dictSpinner = $('#dict-spinner');
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index f80824f9..988533fb 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -9,17 +9,17 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
return "<div class=\"dict-group well well-sm\" data-title=\""
+ 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)))
- + "\">\n <div class=\"row\">\n <div class=\"col-xs-8\">\n <h4><span class=\"text-muted glyphicon glyphicon-book\"></span> "
+ + "\">\n <h4><span class=\"text-muted glyphicon glyphicon-book\"></span> "
+ 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-controls dict-delete btn btn-danger\">Delete</button>\n </div>\n </div>\n <div class=\"dict-delete-progress\">Dictionary data is being deleted, please be patient...</div>\n <div class=\"progress dict-delete-progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n <div class=\"checkbox dict-controls "
+ + "</small></h4>\n <div class=\"checkbox "
+ ((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-controls "
+ + "> Enable term search</label>\n </div>\n <div class=\"checkbox "
+ ((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 : "")
diff --git a/ext/bg/options.html b/ext/bg/options.html
index 4f74a58e..9026520b 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-progress,
#options-advanced {
display: none;
}
@@ -75,8 +75,8 @@
<span></span>
</div>
- <div class="dict-import-progress">Dictionary data is being imported, please be patient...</div>
- <div class="progress dict-import-progress">
+ <div class="dict-progress">Dictionary data is being imported, please be patient...</div>
+ <div class="progress dict-progress">
<div class="progress-bar progress-bar-striped" style="width: 0%"></div>
</div>
diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html
index 134209c8..7da9f660 100644
--- a/tmpl/dictionary.html
+++ b/tmpl/dictionary.html
@@ -1,20 +1,9 @@
<div class="dict-group well well-sm" data-title="{{title}}">
- <div class="row">
- <div class="col-xs-8">
- <h4><span class="text-muted glyphicon glyphicon-book"></span> {{title}} <small>v.{{version}}</small></h4>
- </div>
- <div class="col-xs-4 text-right disabled">
- <button type="button" class="dict-controls dict-delete btn btn-danger">Delete</button>
- </div>
- </div>
- <div class="dict-delete-progress">Dictionary data is being deleted, please be patient...</div>
- <div class="progress dict-delete-progress">
- <div class="progress-bar progress-bar-striped progress-bar-danger" style="width: 0%"></div>
- </div>
- <div class="checkbox dict-controls {{#unless hasTerms}}disabled{{/unless}}">
+ <h4><span class="text-muted glyphicon glyphicon-book"></span> {{title}} <small>v.{{version}}</small></h4>
+ <div class="checkbox {{#unless hasTerms}}disabled{{/unless}}">
<label><input type="checkbox" class="dict-enable-terms" {{#unless hasTerms}}disabled{{/unless}} {{#if enableTerms}}checked{{/if}}> Enable term search</label>
</div>
- <div class="checkbox dict-controls {{#unless hasKanji}}disabled{{/unless}}">
+ <div class="checkbox {{#unless hasKanji}}disabled{{/unless}}">
<label><input type="checkbox" class="dict-enable-kanji" {{#unless hasKanji}}disabled{{/unless}} {{#if enableKanji}}checked{{/if}}> Enable Kanji search</label>
</div>
</div>