Throw an error instead
This commit is contained in:
parent
c9d9feb63f
commit
a9d488b748
|
@ -94,11 +94,11 @@
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.modal.beforeClose = () => {
|
||||
if (this.changed) {
|
||||
this.modal.beforeClose = force => {
|
||||
if (this.changed && !force) {
|
||||
this.warnclose = true;
|
||||
setTimeout(() => this.warnclose = false, 400);
|
||||
return true;
|
||||
throw {message: 'Settings have been changed'};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -24,22 +24,25 @@ export default class {
|
|||
created() { modal.vue = this; }
|
||||
};
|
||||
modal.closing = false;
|
||||
modal.close = () => this.close(modal);
|
||||
modal.close = force => this.close(modal, force);
|
||||
|
||||
this.stack.push(modal);
|
||||
Events.emit('bd-refresh-modals');
|
||||
return modal;
|
||||
}
|
||||
|
||||
static close(modal) {
|
||||
static close(modal, force) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (modal.beforeClose) {
|
||||
let beforeCloseResult = modal.beforeClose();
|
||||
try {
|
||||
let beforeCloseResult = modal.beforeClose(force);
|
||||
if (beforeCloseResult instanceof Promise)
|
||||
beforeCloseResult = await beforeCloseResult;
|
||||
|
||||
if (beforeCloseResult)
|
||||
return reject(beforeCloseResult);
|
||||
if (beforeCloseResult && !force) return reject(beforeCloseResult);
|
||||
} catch (err) {
|
||||
if (!force) return reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
modal.closing = true;
|
||||
|
|
Loading…
Reference in New Issue