prepare ui for zip dictionaries

This commit is contained in:
Alex Yatskov 2017-06-12 22:58:02 -07:00
parent a0a3bb1e12
commit 98d22a92f3
2 changed files with 24 additions and 56 deletions

View File

@ -140,9 +140,7 @@ $(document).ready(() => {
$('#scan-modifier-key').val(options.scanning.modifier); $('#scan-modifier-key').val(options.scanning.modifier);
$('#dict-purge').click(onDictionaryPurge); $('#dict-purge').click(onDictionaryPurge);
$('#dict-importer a').click(onDictionarySetUrl); $('#dict-file').change(onDictionaryImport);
$('#dict-import').click(onDictionaryImport);
$('#dict-url').on('input', onDictionaryUpdateUrl);
$('#anki-enable').prop('checked', options.anki.enable); $('#anki-enable').prop('checked', options.anki.enable);
$('#card-tags').val(options.anki.tags.join(' ')); $('#card-tags').val(options.anki.tags.join(' '));
@ -253,49 +251,32 @@ function onDictionaryPurge(e) {
} }
function onDictionaryImport() { function onDictionaryImport() {
dictionaryErrorShow(null); alert('import');
dictionarySpinnerShow(true);
const dictUrl = $('#dict-url'); // dictionaryErrorShow(null);
const dictImporter = $('#dict-importer').hide(); // dictionarySpinnerShow(true);
const dictProgress = $('#dict-import-progress').show();
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
setProgress(0.0); // const dictUrl = $('#dict-url');
// const dictImporter = $('#dict-importer').hide();
// const dictProgress = $('#dict-import-progress').show();
// const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
optionsLoad().then(options => { // setProgress(0.0);
instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => {
options.dictionaries[summary.title] = {enabled: true, priority: 0}; // optionsLoad().then(options => {
return optionsSave(options); // instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => {
}).then(() => dictionaryGroupsPopulate(options)).catch(dictionaryErrorShow).then(() => { // options.dictionaries[summary.title] = {enabled: true, priority: 0};
dictionarySpinnerShow(false); // return optionsSave(options);
dictProgress.hide(); // }).then(() => dictionaryGroupsPopulate(options)).catch(dictionaryErrorShow).then(() => {
dictImporter.show(); // dictionarySpinnerShow(false);
dictUrl.val(''); // dictProgress.hide();
dictUrl.trigger('input'); // dictImporter.show();
}); // dictUrl.val('');
}); // dictUrl.trigger('input');
// });
// });
} }
function onDictionarySetUrl(e) {
e.preventDefault();
const dictUrl = $('#dict-url');
const url = $(this).data('url');
if (url.includes('/')) {
dictUrl.val(url);
} else {
dictUrl.val(chrome.extension.getURL(`bg/lang/dict/${url}/index.json`));
}
dictUrl.trigger('input');
}
function onDictionaryUpdateUrl() {
$('#dict-import').prop('disabled', $(this).val().length === 0);
}
/* /*
* Anki * Anki
*/ */

View File

@ -145,21 +145,8 @@
</div> </div>
</div> </div>
<div class="input-group" id="dict-importer"> <div id="dict-importer">
<div class="input-group-btn"> <input type="file" id="dict-file">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" data-url="edict">JMdict <span class="text-muted">(terms)</span></a></li>
<li><a href="#" data-url="enamdict">JMnedict <span class="text-muted">(names)</span></a></li>
<li><a href="#" data-url="kanjidic">KANJIDIC2 <span class="text-muted">(characters)</span></a></li>
<li role="separator" class="divider"></li>
<li><a href="#" data-url="http://localhost:9876/index.json">Local dictionary</a></li>
</ul>
</div>
<input type="text" id="dict-url" class="form-control" placeholder="Dictionary import URL">
<div class="input-group-btn">
<button type="button" id="dict-import" class="btn btn-primary" disabled>Import</button>
</div>
</div> </div>
</div> </div>