This commit is contained in:
Alex Yatskov 2017-01-12 20:14:05 -08:00
parent c574ef4bc0
commit 94034890cc
4 changed files with 17 additions and 31 deletions

View File

@ -39,7 +39,7 @@ function getFormValues() {
optsNew.scanDelay = parseInt($('#scan-delay').val(), 10); optsNew.scanDelay = parseInt($('#scan-delay').val(), 10);
optsNew.scanLength = parseInt($('#scan-length').val(), 10); optsNew.scanLength = parseInt($('#scan-length').val(), 10);
optsNew.ankiMethod = $('#anki-method').val(); optsNew.ankiEnable = $('#anki-enable').prop('checked');
optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/); optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/);
optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10); optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10);
optsNew.ankiTermDeck = $('#anki-term-deck').val(); optsNew.ankiTermDeck = $('#anki-term-deck').val();
@ -65,13 +65,10 @@ function getFormValues() {
} }
function updateVisibility(opts) { function updateVisibility(opts) {
switch (opts.ankiMethod) { if (opts.ankiEnable) {
case 'ankiconnect':
$('#anki-general').show(); $('#anki-general').show();
break; } else {
default:
$('#anki-general').hide(); $('#anki-general').hide();
break;
} }
if (opts.showAdvancedOptions) { if (opts.showAdvancedOptions) {
@ -96,7 +93,7 @@ $(document).ready(() => {
$('#scan-delay').val(opts.scanDelay); $('#scan-delay').val(opts.scanDelay);
$('#scan-length').val(opts.scanLength); $('#scan-length').val(opts.scanLength);
$('#anki-method').val(opts.ankiMethod); $('#anki-enable').prop('checked', opts.ankiEnable);
$('#anki-card-tags').val(opts.ankiCardTags.join(' ')); $('#anki-card-tags').val(opts.ankiCardTags.join(' '));
$('#sentence-extent').val(opts.sentenceExtent); $('#sentence-extent').val(opts.sentenceExtent);
@ -424,7 +421,7 @@ function onOptionsChanged(e) {
return saveOptions(optsNew).then(() => { return saveOptions(optsNew).then(() => {
yomichan().setOptions(optsNew); yomichan().setOptions(optsNew);
updateVisibility(optsNew); updateVisibility(optsNew);
if (optsNew.ankiMethod !== optsOld.ankiMethod) { if (optsNew.ankiEnable !== optsOld.ankiEnable) {
showAnkiError(null); showAnkiError(null);
showAnkiSpinner(true); showAnkiSpinner(true);
return populateAnkiDeckAndModel(optsNew); return populateAnkiDeckAndModel(optsNew);

View File

@ -44,7 +44,7 @@ function sanitizeOptions(options) {
dictionaries: {}, dictionaries: {},
ankiMethod: 'disabled', ankiEnable: false,
ankiCardTags: ['yomichan'], ankiCardTags: ['yomichan'],
sentenceExtent: 200, sentenceExtent: 200,
@ -62,10 +62,6 @@ function sanitizeOptions(options) {
} }
} }
if (options.ankiMethod === 'ankiweb') {
options.ankiMethod = 'disabled';
}
return options; return options;
} }

View File

@ -94,13 +94,10 @@ class Yomichan {
setOptions(options) { setOptions(options) {
this.options = options; this.options = options;
switch (options.ankiMethod) { if (options.ankiEnable) {
case 'ankiconnect':
this.anki = new AnkiConnect(); this.anki = new AnkiConnect();
break; } else {
default:
this.anki = new AnkiNull(); this.anki = new AnkiNull();
break;
} }
this.tabInvokeAll('setOptions', this.options); this.tabInvokeAll('setOptions', this.options);

View File

@ -132,19 +132,15 @@
<a href="https://foosoft.net/projects/anki-connect/">AnkiConnect</a> plugin. <a href="https://foosoft.net/projects/anki-connect/">AnkiConnect</a> plugin.
</p> </p>
<div class="checkbox">
<label><input type="checkbox" id="anki-enable"> Enable Anki integration</label>
</div>
<div class="alert alert-danger" id="anki-error"> <div class="alert alert-danger" id="anki-error">
<strong>Error:</strong> <strong>Error:</strong>
<span></span> <span></span>
</div> </div>
<div class="form-group">
<label for="anki-method">Connection method</label>
<select class="form-control" id="anki-method">
<option value="disabled">Disabled (no auto flashcard creation)</option>
<option value="ankiconnect">AnkiConnect (requires the AnkiConnect plugin)</option>
</select>
</div>
<div id="anki-general"> <div id="anki-general">
<div class="form-group"> <div class="form-group">
<label for="anki-card-tags">Card tags (comma or space separated)</label> <label for="anki-card-tags">Card tags (comma or space separated)</label>
@ -152,7 +148,7 @@
</div> </div>
<div class="form-group options-advanced"> <div class="form-group options-advanced">
<label for="sentence-extent">Sentence extent</label> <label for="sentence-extent">Sentence detection extent</label>
<input type="number" min="1" id="sentence-extent" class="form-control"> <input type="number" min="1" id="sentence-extent" class="form-control">
</div> </div>