From 94034890cc21a57e3ea579aab3eaa88ae3aab360 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Thu, 12 Jan 2017 20:14:05 -0800
Subject: WIP
---
ext/bg/js/options-form.js | 17 +++++++----------
ext/bg/js/options.js | 6 +-----
ext/bg/js/yomichan.js | 11 ++++-------
ext/bg/options.html | 14 +++++---------
4 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index 8cffb2f7..f53808e8 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -39,7 +39,7 @@ function getFormValues() {
optsNew.scanDelay = parseInt($('#scan-delay').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.sentenceExtent = parseInt($('#sentence-extent').val(), 10);
optsNew.ankiTermDeck = $('#anki-term-deck').val();
@@ -65,13 +65,10 @@ function getFormValues() {
}
function updateVisibility(opts) {
- switch (opts.ankiMethod) {
- case 'ankiconnect':
- $('#anki-general').show();
- break;
- default:
- $('#anki-general').hide();
- break;
+ if (opts.ankiEnable) {
+ $('#anki-general').show();
+ } else {
+ $('#anki-general').hide();
}
if (opts.showAdvancedOptions) {
@@ -96,7 +93,7 @@ $(document).ready(() => {
$('#scan-delay').val(opts.scanDelay);
$('#scan-length').val(opts.scanLength);
- $('#anki-method').val(opts.ankiMethod);
+ $('#anki-enable').prop('checked', opts.ankiEnable);
$('#anki-card-tags').val(opts.ankiCardTags.join(' '));
$('#sentence-extent').val(opts.sentenceExtent);
@@ -424,7 +421,7 @@ function onOptionsChanged(e) {
return saveOptions(optsNew).then(() => {
yomichan().setOptions(optsNew);
updateVisibility(optsNew);
- if (optsNew.ankiMethod !== optsOld.ankiMethod) {
+ if (optsNew.ankiEnable !== optsOld.ankiEnable) {
showAnkiError(null);
showAnkiSpinner(true);
return populateAnkiDeckAndModel(optsNew);
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 2f0bd189..13229d2a 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -44,7 +44,7 @@ function sanitizeOptions(options) {
dictionaries: {},
- ankiMethod: 'disabled',
+ ankiEnable: false,
ankiCardTags: ['yomichan'],
sentenceExtent: 200,
@@ -62,10 +62,6 @@ function sanitizeOptions(options) {
}
}
- if (options.ankiMethod === 'ankiweb') {
- options.ankiMethod = 'disabled';
- }
-
return options;
}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 2cdcf1c8..7debd9f3 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -94,13 +94,10 @@ class Yomichan {
setOptions(options) {
this.options = options;
- switch (options.ankiMethod) {
- case 'ankiconnect':
- this.anki = new AnkiConnect();
- break;
- default:
- this.anki = new AnkiNull();
- break;
+ if (options.ankiEnable) {
+ this.anki = new AnkiConnect();
+ } else {
+ this.anki = new AnkiNull();
}
this.tabInvokeAll('setOptions', this.options);
diff --git a/ext/bg/options.html b/ext/bg/options.html
index 6bf6fb7b..68535a64 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -132,19 +132,15 @@
AnkiConnect plugin.
+
+
+
+
Error:
-
-
-
-
-
@@ -152,7 +148,7 @@
-
+
--
cgit v1.2.3