From 20d357c46eb98be1e8ba3669f5e8438451b2461b Mon Sep 17 00:00:00 2001 From: Dan Popescu Date: Fri, 30 Mar 2018 10:48:52 +0300 Subject: [PATCH] Allow dialog and action-sheet plugins to receive a resolver token --- dev/components/global/dialog.vue | 16 ++++++++++++---- src/utils/modal-fn.js | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/dev/components/global/dialog.vue b/dev/components/global/dialog.vue index 887da2788fab..562e28b341d6 100644 --- a/dev/components/global/dialog.vue +++ b/dev/components/global/dialog.vue @@ -41,6 +41,8 @@ + + @@ -87,7 +89,13 @@ export default { Promise.resolve(okFn()).then(() => this.$q.notify(`Ok ${this.name}, going with ${hero}`)) } }, - adHoc () { + adHoc (autoclose, autoResolve) { + const resolver = autoclose > 0 + ? new Promise((resolve, reject) => { + setTimeout(() => autoResolve ? resolve(autoResolve) : reject(new Error('Autoclosed')), autoclose) + }) + : undefined + this.$q.dialog({ title: 'Prompt', message: 'Modern HTML5 Single Page Application front-end framework on steroids.', @@ -98,10 +106,10 @@ export default { cancel: true, // preventClose: true, color: 'secondary' - }).then(data => { + }, resolver).then(data => { console.log('>>>> OK, received:', data) - }).catch(() => { - console.log('>>>> Cancel') + }).catch(error => { + console.log('>>>> Cancel', String(error)) }) }, adHoc2 () { diff --git a/src/utils/modal-fn.js b/src/utils/modal-fn.js index f555a00eac06..33e34b980713 100644 --- a/src/utils/modal-fn.js +++ b/src/utils/modal-fn.js @@ -1,5 +1,5 @@ export default function (Component, Vue) { - return props => { + return (props, resolver) => { const node = document.createElement('div') document.body.appendChild(node) @@ -17,8 +17,8 @@ export default function (Component, Vue) { resolve(data) vm.$destroy() }, - cancel: () => { - reject(new Error()) + cancel: reason => { + reject(reason || new Error()) vm.$destroy() } } @@ -27,6 +27,15 @@ export default function (Component, Vue) { this.$refs.modal.show() } }) + if (resolver) { + resolver.then(data => { + resolve(data) + vm.$destroy() + }).catch(reason => { + reject(reason || new Error()) + vm.$destroy() + }) + } }) } }