views/mdc/assets/js/components/events/dialog.js in voom-presenters-0.2.0 vs views/mdc/assets/js/components/events/dialog.js in voom-presenters-2.0.0

- old
+ new

@@ -1,25 +1,43 @@ export class VDialog { - constructor(options, params, event) { + constructor(options, params, event, root) { this.dialogId = options.target; this.params = params; this.event = event; + this.root = root; } call(results) { - var dialog = document.querySelector('#' + this.dialogId); - if(dialog) { - if (!dialog.showModal) { - dialogPolyfill.registerDialog(dialog); - } + const dialog = this.root.querySelector('#' + this.dialogId); - dialog.showModal(); - }else { - console.error("Unable to find dialog with id: "+this.dialogId+". Usually this means you forgot to attach it to the currently rendered page."); + if (!(dialog && dialog.vComponent)) { + const err = new Error( + `Unable to find dialog ${this.dialogId}. ` + + 'Did you forget to attach it?' + ); + + results.push({ + action: 'dialog', + contentType: 'v/errors', + content: {exception: err.message}, + }); + + return new Promise((_, reject) => reject(results)); } - var promiseObj = new Promise(function (resolve) { - results.push({action:'dialog', statusCode: 200}); - resolve(results); + + return new Promise(function(resolve, reject) { + const comp = dialog.vComponent.mdcComponent; + + comp.listen('MDCDialog:closed', (event) => { + results.push({ + action: 'dialog', + statusCode: 200, + dialogAction: event.detail.action, + }); + + resolve(results); + }); + + dialog.vComponent.open(); }); - return promiseObj; } }