Prevent modal close when settings have changed
This commit is contained in:
parent
bea87f5be8
commit
c9d9feb63f
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bd-settings-modal" :class="{'bd-edited': changed}">
|
<div class="bd-settings-modal" :class="{'bd-edited': changed}">
|
||||||
<Modal :headerText="modal.headertext" :close="attemptToClose" :class="{'bd-modal-out': modal.closing}">
|
<Modal :headerText="modal.headertext" :close="modal.close" :class="{'bd-modal-out': modal.closing}">
|
||||||
<SettingsPanel :settings="configCache" :schemes="modal.schemes" :change="settingChange" slot="body" class="bd-settings-modal-body" />
|
<SettingsPanel :settings="configCache" :schemes="modal.schemes" :change="settingChange" slot="body" class="bd-settings-modal-body" />
|
||||||
<div slot="footer" class="bd-footer-alert" :class="{'bd-active': changed, 'bd-warn': warnclose}">
|
<div slot="footer" class="bd-footer-alert" :class="{'bd-active': changed, 'bd-warn': warnclose}">
|
||||||
<div class="bd-footer-alert-text">Unsaved changes</div>
|
<div class="bd-footer-alert-text">Unsaved changes</div>
|
||||||
|
@ -91,19 +91,15 @@
|
||||||
this.configCache = JSON.parse(JSON.stringify(this.modal.settings));
|
this.configCache = JSON.parse(JSON.stringify(this.modal.settings));
|
||||||
this.changed = false;
|
this.changed = false;
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
}
|
||||||
attemptToClose(e) {
|
},
|
||||||
if (!this.changed) {
|
created() {
|
||||||
this.closing = true;
|
this.modal.beforeClose = () => {
|
||||||
setTimeout(() => {
|
if (this.changed) {
|
||||||
this.modal.close();
|
this.warnclose = true;
|
||||||
}, 200);
|
setTimeout(() => this.warnclose = false, 400);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
this.warnclose = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.warnclose = false;
|
|
||||||
}, 400);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
|
|
|
@ -32,7 +32,16 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
static close(modal) {
|
static close(modal) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
if (modal.beforeClose) {
|
||||||
|
let beforeCloseResult = modal.beforeClose();
|
||||||
|
if (beforeCloseResult instanceof Promise)
|
||||||
|
beforeCloseResult = await beforeCloseResult;
|
||||||
|
|
||||||
|
if (beforeCloseResult)
|
||||||
|
return reject(beforeCloseResult);
|
||||||
|
}
|
||||||
|
|
||||||
modal.closing = true;
|
modal.closing = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this._stack = this.stack.filter(m => m !== modal);
|
this._stack = this.stack.filter(m => m !== modal);
|
||||||
|
|
Loading…
Reference in New Issue