From 94b1e3f80dc9c9802e3f3bc6052d12b2ffb826e3 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 24 Jan 2024 16:42:22 -0700 Subject: [PATCH] Fix Et2Dialog getComplete() promise did not work more than once when destroyOnClose = false --- api/js/etemplate/Et2Dialog/Et2Dialog.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/api/js/etemplate/Et2Dialog/Et2Dialog.ts b/api/js/etemplate/Et2Dialog/Et2Dialog.ts index 5269d5e866..3fbd202007 100644 --- a/api/js/etemplate/Et2Dialog/Et2Dialog.ts +++ b/api/js/etemplate/Et2Dialog/Et2Dialog.ts @@ -27,6 +27,7 @@ import {Et2Button} from "../Et2Button/Et2Button"; import shoelace from "../Styles/shoelace"; import {SlDialog} from "@shoelace-style/shoelace"; import {egwIsMobile} from "../../egw_action/egw_action_common"; +import {waitForEvent} from "../Et2Widget/event"; export interface DialogButton { @@ -562,7 +563,10 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog)) this.addOpenListeners(); this._button_id = null; - this._complete_promise = this._complete_promise || new Promise<[number, Object]>((resolve) => this._completeResolver); + this._complete_promise = this._complete_promise || new Promise<[number, Object]>((resolve) => + { + this._completeResolver = value => resolve(value); + }); // Now consumers can listen for "open" event, though getUpdateComplete().then(...) also works this.dispatchEvent(new Event('open')); @@ -581,19 +585,23 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog)) this.removeOpenListeners(); this._completeResolver([this._button_id, this.value]); - this._button_id = null; - this._complete_promise = undefined; this.dispatchEvent(new Event('close')); - if(this.destroyOnClose) + waitForEvent(this, 'sl-after-hide').then(() => { - if(this._template_widget) + this._button_id = null; + + this._complete_promise = undefined; + if(this.destroyOnClose) { - this._template_widget.clear(); + if(this._template_widget) + { + this._template_widget.clear(); + } + this.remove(); } - this.remove(); - } + }); } /**