WIP
This commit is contained in:
parent
6eab90b89c
commit
ed2091ae1b
@ -131,7 +131,7 @@ class Dictionary {
|
||||
});
|
||||
}
|
||||
|
||||
getInfo() {
|
||||
getDictionaries() {
|
||||
if (this.db === null) {
|
||||
return Promise.reject('database not initialized');
|
||||
}
|
||||
@ -139,6 +139,22 @@ class Dictionary {
|
||||
return this.db.dictionaries.toArray();
|
||||
}
|
||||
|
||||
deleteDictionary(title) {
|
||||
if (this.db === null) {
|
||||
return Promise.reject('database not initialized');
|
||||
}
|
||||
|
||||
const tasks = [
|
||||
this.db.terms.where('dictionary').equals(title).delete(),
|
||||
this.db.kanji.where('dictionary').equals(title).delete(),
|
||||
this.db.entities.where('dictionary').equals(title).delete()
|
||||
];
|
||||
|
||||
return Promise.all(tasks).then(() => {
|
||||
return this.db.dictionaries.where('title').equals(title).delete();
|
||||
});
|
||||
}
|
||||
|
||||
importDb(indexUrl, callback) {
|
||||
if (this.db === null) {
|
||||
return Promise.reject('database not initialized');
|
||||
|
@ -166,7 +166,7 @@ function populateDictionaries(opts) {
|
||||
const container = $('.dicts');
|
||||
container.empty();
|
||||
|
||||
yomichan().translator.dictionary.getInfo().then(rows => {
|
||||
yomichan().translator.dictionary.getDictionaries().then(rows => {
|
||||
rows.forEach(row => {
|
||||
const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false};
|
||||
const html = Handlebars.templates['dictionary.html']({
|
||||
@ -181,6 +181,13 @@ function populateDictionaries(opts) {
|
||||
container.append($(html));
|
||||
});
|
||||
|
||||
const dictDelete = $('.dict-delete');
|
||||
dictDelete.click(() => {
|
||||
const dict = dictDelete.closest('.dict');
|
||||
const title = dict.data('title');
|
||||
yomichan().translator.dictionary.deleteDictionary(title).then(() => dict.slideUp());
|
||||
});
|
||||
|
||||
container.find('.dict input').change(onOptionsChanged);
|
||||
});
|
||||
}
|
||||
@ -301,8 +308,9 @@ $(document).ready(() => {
|
||||
control.trigger('input');
|
||||
});
|
||||
|
||||
$('#dict-import-url').on('input', () => {
|
||||
const disable = $('#dict-import-url').val().trim().length === 0;
|
||||
const dictImportUrl = $('#dict-import-url');
|
||||
dictImportUrl.on('input', () => {
|
||||
const disable = dictImportUrl.val().trim().length === 0;
|
||||
$('#dict-import-start').prop('disabled', disable);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user