WIP
This commit is contained in:
parent
9f67e5e584
commit
9eaadd2a6e
@ -51,7 +51,7 @@ class AnkiConnect {
|
|||||||
return this.ankiInvoke('version', {}, null).then(version => {
|
return this.ankiInvoke('version', {}, null).then(version => {
|
||||||
this.remoteVersion = version;
|
this.remoteVersion = version;
|
||||||
if (this.remoteVersion !== this.localVersion) {
|
if (this.remoteVersion !== this.localVersion) {
|
||||||
return Promise.reject('browser extension and anki plugin version mismatch');
|
return Promise.reject('extension and plugin version mismatch');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -68,8 +68,11 @@ class AnkiConnect {
|
|||||||
delete this.asyncPools[pool];
|
delete this.asyncPools[pool];
|
||||||
}
|
}
|
||||||
|
|
||||||
const resp = xhr.responseText;
|
if (xhr.responseText) {
|
||||||
resolve(resp ? JSON.parse(resp) : null);
|
resolve(JSON.parse(resp));
|
||||||
|
} else {
|
||||||
|
reject('unable to connect to plugin');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
xhr.open('POST', 'http://127.0.0.1:8765');
|
xhr.open('POST', 'http://127.0.0.1:8765');
|
||||||
|
@ -130,6 +130,9 @@ function updateVisibility(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populateAnkiDeckAndModel(opts) {
|
function populateAnkiDeckAndModel(opts) {
|
||||||
|
$('.options-anki-format').hide();
|
||||||
|
$('.status-dlg').hide();
|
||||||
|
|
||||||
const ankiDeck = $('.anki-deck');
|
const ankiDeck = $('.anki-deck');
|
||||||
ankiDeck.find('option').remove();
|
ankiDeck.find('option').remove();
|
||||||
|
|
||||||
@ -147,6 +150,14 @@ function populateAnkiDeckAndModel(opts) {
|
|||||||
populateAnkiFields($('#anki-term-model').val(opts.ankiTermModel), opts);
|
populateAnkiFields($('#anki-term-model').val(opts.ankiTermModel), opts);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
populateAnkiFields($('#anki-kanji-model').val(opts.ankiKanjiModel), opts);
|
populateAnkiFields($('#anki-kanji-model').val(opts.ankiKanjiModel), opts);
|
||||||
|
}).then(() => {
|
||||||
|
$('.options-anki-format').show();
|
||||||
|
if (opts.ankiMethod !== 'none') {
|
||||||
|
$('#success-dlg').show();
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
$('#error-dlg').show();
|
||||||
|
$('#error-dlg span').text(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +224,12 @@ function onOptionsAnkiChanged(e) {
|
|||||||
if (e.originalEvent || e.isTrigger) {
|
if (e.originalEvent || e.isTrigger) {
|
||||||
getAnkiOptions().then(({optsNew, optsOld}) => {
|
getAnkiOptions().then(({optsNew, optsOld}) => {
|
||||||
updateVisibility(optsNew);
|
updateVisibility(optsNew);
|
||||||
saveOptions(optsNew).then(() => yomichan().setOptions(optsNew));
|
saveOptions(optsNew).then(() => {
|
||||||
|
yomichan().setOptions(optsNew);
|
||||||
|
if (optsNew.ankiMethod !== optsOld.ankiMethod) {
|
||||||
|
populateAnkiDeckAndModel(optsNew);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,8 +261,8 @@ $(document).ready(() => {
|
|||||||
$('#sentence-extent').val(opts.sentenceExtent);
|
$('#sentence-extent').val(opts.sentenceExtent);
|
||||||
|
|
||||||
$('.options-basic').change(onOptionsBasicChanged);
|
$('.options-basic').change(onOptionsBasicChanged);
|
||||||
$('.options-anki').not('.anki-model').change(onOptionsAnkiChanged);
|
|
||||||
$('.anki-model').change(onAnkiModelChanged);
|
$('.anki-model').change(onAnkiModelChanged);
|
||||||
|
$('.options-anki').not('.anki-model').change(onOptionsAnkiChanged);
|
||||||
|
|
||||||
populateAnkiDeckAndModel(opts);
|
populateAnkiDeckAndModel(opts);
|
||||||
updateVisibility(opts);
|
updateVisibility(opts);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error-dlg {
|
.status-dlg {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -89,6 +89,16 @@
|
|||||||
<div class="options-anki">
|
<div class="options-anki">
|
||||||
<h3>Anki Options</h3>
|
<h3>Anki Options</h3>
|
||||||
|
|
||||||
|
<div class="alert alert-danger status-dlg" id="error-dlg">
|
||||||
|
<strong>Error</strong>
|
||||||
|
<span>Unable to connect</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-success status-dlg" id="success-dlg">
|
||||||
|
<strong>Success</strong>
|
||||||
|
<span>Connection established</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="anki-method">Connection method</label>
|
<label class="control-label" for="anki-method">Connection method</label>
|
||||||
<select class="form-control" id="anki-method">
|
<select class="form-control" id="anki-method">
|
||||||
@ -98,11 +108,6 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="alert alert-danger error-dlg error-dlg-connection">
|
|
||||||
<strong>Unable to Connect</strong><br>
|
|
||||||
Is the <a href="https://foosoft.net/projects/anki-connect">AnkiConnect</a> extension for <a href="http://ankisrs.net/">Anki</a> installed and running? This software is required for Anki-related features.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form class="form-horizontal options-anki-general">
|
<form class="form-horizontal options-anki-general">
|
||||||
<div class="form-group options-anki-login">
|
<div class="form-group options-anki-login">
|
||||||
<label for="anki-username" class="control-label col-sm-2">Username</label>
|
<label for="anki-username" class="control-label col-sm-2">Username</label>
|
||||||
@ -124,6 +129,7 @@
|
|||||||
<div class="col-sm-10"><input type="number" min="1" id="sentence-extent" class="form-control"></div>
|
<div class="col-sm-10"><input type="number" min="1" id="sentence-extent" class="form-control"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="options-anki-format">
|
||||||
<ul class="nav nav-tabs col-sm-offset-2 col-sm-10">
|
<ul class="nav nav-tabs col-sm-offset-2 col-sm-10">
|
||||||
<li class="active"><a href="#term" data-toggle="tab">Terms</a></li>
|
<li class="active"><a href="#term" data-toggle="tab">Terms</a></li>
|
||||||
<li><a href="#kanji" data-toggle="tab">Kanji</a></li>
|
<li><a href="#kanji" data-toggle="tab">Kanji</a></li>
|
||||||
@ -184,6 +190,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user