Throw an error instead

This commit is contained in:
Samuel Elliott 2018-02-14 18:19:20 +00:00
parent c9d9feb63f
commit a9d488b748
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 13 additions and 10 deletions

View File

@ -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'};
}
}
},

View File

@ -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;