From 9eaadd2a6e6b4c3e2ee4eb80103eca78d3c595d5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 16 Oct 2016 12:12:31 -0700 Subject: WIP --- ext/bg/js/ankiconnect.js | 9 ++-- ext/bg/js/options-form.js | 20 +++++++- ext/bg/options.html | 117 ++++++++++++++++++++++++---------------------- 3 files changed, 86 insertions(+), 60 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/ankiconnect.js b/ext/bg/js/ankiconnect.js index de199b2c..9de17159 100644 --- a/ext/bg/js/ankiconnect.js +++ b/ext/bg/js/ankiconnect.js @@ -51,7 +51,7 @@ class AnkiConnect { return this.ankiInvoke('version', {}, null).then(version => { this.remoteVersion = version; 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]; } - const resp = xhr.responseText; - resolve(resp ? JSON.parse(resp) : null); + if (xhr.responseText) { + resolve(JSON.parse(resp)); + } else { + reject('unable to connect to plugin'); + } }); xhr.open('POST', 'http://127.0.0.1:8765'); diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 163660e4..fb8ef77b 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -130,6 +130,9 @@ function updateVisibility(opts) { } function populateAnkiDeckAndModel(opts) { + $('.options-anki-format').hide(); + $('.status-dlg').hide(); + const ankiDeck = $('.anki-deck'); ankiDeck.find('option').remove(); @@ -147,6 +150,14 @@ function populateAnkiDeckAndModel(opts) { populateAnkiFields($('#anki-term-model').val(opts.ankiTermModel), opts); }).then(() => { 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) { getAnkiOptions().then(({optsNew, optsOld}) => { 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); $('.options-basic').change(onOptionsBasicChanged); - $('.options-anki').not('.anki-model').change(onOptionsAnkiChanged); $('.anki-model').change(onAnkiModelChanged); + $('.options-anki').not('.anki-model').change(onOptionsAnkiChanged); populateAnkiDeckAndModel(opts); updateVisibility(opts); diff --git a/ext/bg/options.html b/ext/bg/options.html index e48a0735..a42af97e 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -17,7 +17,7 @@ padding: 10px; } - .error-dlg { + .status-dlg { display: none; } @@ -89,6 +89,16 @@

Anki Options

+
+ Error + Unable to connect +
+ +
+ Success + Connection established +
+
-
- Unable to Connect
- Is the AnkiConnect extension for Anki installed and running? This software is required for Anki-related features. -
-
- - -
-
-
- -
- +
+ + +
+
+
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- - - - - - - - - -
FieldValue
-
+ + + + + + + + + +
FieldValue
+
-
-
- -
- +
+
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- - - - - - - - - -
FieldValue
+ + + + + + + + + +
FieldValue
+
-- cgit v1.2.3