Throw an error instead
This commit is contained in:
parent
c9d9feb63f
commit
a9d488b748
|
@ -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'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue