This commit is contained in:
Alex Yatskov 2016-10-16 18:44:36 -07:00
parent 1fe2626443
commit c076821e37
2 changed files with 13 additions and 26 deletions

View File

@ -120,9 +120,7 @@ function updateVisibility(opts) {
} }
function populateAnkiDeckAndModel(opts) { function populateAnkiDeckAndModel(opts) {
$('.status-dlg').hide(); const ankiSpinner = $('#anki-spinner');
const ankiSpinner = $('#ankiSpinner');
ankiSpinner.show(); ankiSpinner.show();
const ankiFormat = $('#anki-format'); const ankiFormat = $('#anki-format');
@ -146,12 +144,10 @@ function populateAnkiDeckAndModel(opts) {
}).then(() => { }).then(() => {
return populateAnkiFields($('#anki-kanji-model').val(opts.ankiKanjiModel), opts); return populateAnkiFields($('#anki-kanji-model').val(opts.ankiKanjiModel), opts);
}).then(() => { }).then(() => {
$('#anki-error').hide();
ankiFormat.show(); ankiFormat.show();
if (opts.ankiMethod !== 'none') {
$('#success-dlg').show();
}
}).catch(error => { }).catch(error => {
$('#error-dlg').show().find('span').text(error); $('#anki-error').show().find('span').text(error);
}).then(() => { }).then(() => {
ankiSpinner.hide(); ankiSpinner.hide();
}); });
@ -218,6 +214,7 @@ function onOptionsChanged(e) {
saveOptions(optsNew).then(() => { saveOptions(optsNew).then(() => {
yomichan().setOptions(optsNew); yomichan().setOptions(optsNew);
updateVisibility(optsNew); updateVisibility(optsNew);
if (optsNew.ankiMethod !== optsOld.ankiMethod) { if (optsNew.ankiMethod !== optsOld.ankiMethod) {
populateAnkiDeckAndModel(optsNew); populateAnkiDeckAndModel(optsNew);
} }
@ -233,16 +230,15 @@ function onAnkiModelChanged(e) {
getFormValues().then(({optsNew, optsOld}) => { getFormValues().then(({optsNew, optsOld}) => {
optsNew[modelIdToFieldOptKey($(this).id)] = {}; optsNew[modelIdToFieldOptKey($(this).id)] = {};
const ankiSpinner = $('#ankiSpinner'); const ankiSpinner = $('#anki-spinner');
ankiSpinner.show(); ankiSpinner.show();
populateAnkiFields($(this), optsNew).then(() => { populateAnkiFields($(this), optsNew).then(() => {
saveOptions(optsNew).then(() => yomichan().setOptions(optsNew)); saveOptions(optsNew).then(() => yomichan().setOptions(optsNew));
}).catch(error => { }).catch(error => {
$('#success-dlg').hide(); $('#anki-error').show().find('span').text(error);
$('#error-dlg').show().find('span').text(error);
}).then(() => { }).then(() => {
$('#success-dlg').show(); $('#anki-error').hide();
ankiSpinner.hide(); ankiSpinner.hide();
}); });
}); });

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
<style> <style>
#anki-spinner, #anki-general, #options-advanced { #anki-spinner, #anki-general, #anki-error, #options-advanced {
display: none; display: none;
} }
@ -16,10 +16,6 @@
border-right: 1px #ddd solid; border-right: 1px #ddd solid;
padding: 10px; padding: 10px;
} }
.status-dlg {
display: none;
}
</style> </style>
</head> </head>
<body> <body>
@ -91,6 +87,11 @@
<h3>Anki Options</h3> <h3>Anki Options</h3>
<div class="alert alert-danger" id="anki-error">
<strong>Error</strong>
<span></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">
@ -100,16 +101,6 @@
</select> </select>
</div> </div>
<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>
<form class="form-horizontal" id="anki-general"> <form class="form-horizontal" id="anki-general">
<div class="form-group anki-login"> <div class="form-group 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>