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() { created() {
this.modal.beforeClose = () => { this.modal.beforeClose = force => {
if (this.changed) { if (this.changed && !force) {
this.warnclose = true; this.warnclose = true;
setTimeout(() => this.warnclose = false, 400); 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; } created() { modal.vue = this; }
}; };
modal.closing = false; modal.closing = false;
modal.close = () => this.close(modal); modal.close = force => this.close(modal, force);
this.stack.push(modal); this.stack.push(modal);
Events.emit('bd-refresh-modals'); Events.emit('bd-refresh-modals');
return modal; return modal;
} }
static close(modal) { static close(modal, force) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
if (modal.beforeClose) { if (modal.beforeClose) {
let beforeCloseResult = modal.beforeClose(); try {
if (beforeCloseResult instanceof Promise) let beforeCloseResult = modal.beforeClose(force);
beforeCloseResult = await beforeCloseResult; if (beforeCloseResult instanceof Promise)
beforeCloseResult = await beforeCloseResult;
if (beforeCloseResult) if (beforeCloseResult && !force) return reject(beforeCloseResult);
return reject(beforeCloseResult); } catch (err) {
if (!force) return reject(err);
}
} }
modal.closing = true; modal.closing = true;