Improve saving indicator
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b94611b160
commit
86d1a25d4e
|
@ -37,7 +37,8 @@ function isMultiline(input) {
|
|||
function addSaver(editor, saveUrl, page, beforeSave) {
|
||||
return {
|
||||
save() {
|
||||
return editor.save().then(outputData => {
|
||||
return editor.save()
|
||||
.then(outputData => {
|
||||
beforeSave()
|
||||
let data = {
|
||||
'json': 1,
|
||||
|
@ -58,16 +59,22 @@ function Indicator(element, timeout) {
|
|||
done() {
|
||||
timeoutId = setTimeout(() => {
|
||||
element.classList.add('hide')
|
||||
element.classList.remove('error')
|
||||
}, timeout * 1000);
|
||||
},
|
||||
|
||||
addError(message) {
|
||||
element.classList.add('error')
|
||||
this.setText(message)
|
||||
},
|
||||
|
||||
setText(text) {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = null;
|
||||
}
|
||||
element.innerText = text;
|
||||
element.classList.remove('hide')
|
||||
element.innerText = text;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -75,11 +82,16 @@ function Indicator(element, timeout) {
|
|||
function addIndicator(editor, indicator) {
|
||||
return {
|
||||
save() {
|
||||
editor.save().then(() => {
|
||||
return editor.save()
|
||||
.then(() => {
|
||||
console.log('success while saving')
|
||||
indicator.setText('saved!');
|
||||
indicator.done();
|
||||
}).catch(() => {
|
||||
console.log('error while saving')
|
||||
return true
|
||||
})
|
||||
.catch(reason => {
|
||||
console.warn('error while saving: '+ reason)
|
||||
indicator.addError('error!')
|
||||
indicator.done();
|
||||
})
|
||||
}
|
||||
|
@ -288,11 +300,10 @@ function Editor(holder, input) {
|
|||
let saveUrl = element.dataset.saveurl;
|
||||
let page = element.dataset.page;
|
||||
|
||||
indicator.setText('has changes...');
|
||||
addIndicator(
|
||||
addSaver(editor, saveUrl, page, () => indicator.setText('saving...')),
|
||||
indicator
|
||||
).save()
|
||||
).save().then(() => indicator.done())
|
||||
})
|
||||
|
||||
// editor.on('rendered', function () {
|
||||
|
|
|
@ -82,6 +82,10 @@ body {
|
|||
color: white;
|
||||
padding: 3px;
|
||||
z-index: 50;
|
||||
|
||||
&.error {
|
||||
background: red;
|
||||
}
|
||||
}
|
||||
|
||||
#autocomplete.hidden {
|
||||
|
|
|
@ -58,8 +58,6 @@ function editor(root, inputData, options) {
|
|||
if (store.hasChanged()) {
|
||||
resolve(store.debug().result)
|
||||
store.clearChanged()
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user