mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-30 14:40:34 +02:00
Et2Dialog: Second try waiting on template load
Now creating the template promise immediately on setting template name and using a resolver function to resolve after template is loaded
This commit is contained in:
@ -151,6 +151,15 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
|
|||||||
*/
|
*/
|
||||||
protected _complete_promise : Promise<[number, Object]>;
|
protected _complete_promise : Promise<[number, Object]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the template promise
|
||||||
|
*/
|
||||||
|
private _templateResolver : (value) => void;
|
||||||
|
/**
|
||||||
|
* Resolve the dialog complete promise
|
||||||
|
*/
|
||||||
|
private _completeResolver : (value) => [number, Object];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the button that was clicked. Always one of the button constants,
|
* The ID of the button that was clicked. Always one of the button constants,
|
||||||
* unless custom buttons were used
|
* unless custom buttons were used
|
||||||
@ -492,11 +501,8 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
|
|||||||
await super.getUpdateComplete();
|
await super.getUpdateComplete();
|
||||||
|
|
||||||
// Wait for template to finish loading
|
// Wait for template to finish loading
|
||||||
if(this._template_widget)
|
|
||||||
{
|
|
||||||
await this._template_promise;
|
await this._template_promise;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
getComplete() : Promise<[number, Object]>
|
getComplete() : Promise<[number, Object]>
|
||||||
{
|
{
|
||||||
@ -667,6 +673,16 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
|
|||||||
{
|
{
|
||||||
let old_template = this.__template;
|
let old_template = this.__template;
|
||||||
this.__template = new_template_name;
|
this.__template = new_template_name;
|
||||||
|
|
||||||
|
// Create the new promise here so we can wait for it immediately, not in update
|
||||||
|
this._template_promise = new Promise<boolean>((resolve) =>
|
||||||
|
{
|
||||||
|
this._templateResolver = value => resolve(value);
|
||||||
|
});
|
||||||
|
if(!this.__template)
|
||||||
|
{
|
||||||
|
this._templateResolver(true);
|
||||||
|
}
|
||||||
this.requestUpdate("template", old_template);
|
this.requestUpdate("template", old_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,7 +705,7 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
|
|||||||
if(changedProperties.has("template"))
|
if(changedProperties.has("template"))
|
||||||
{
|
{
|
||||||
// Wait until update is finished to avoid an error in Safari
|
// Wait until update is finished to avoid an error in Safari
|
||||||
this.updateComplete.then(() => this._loadTemplate());
|
super.getUpdateComplete().then(() => this._loadTemplate());
|
||||||
}
|
}
|
||||||
if(changedProperties.has("buttons"))
|
if(changedProperties.has("buttons"))
|
||||||
{
|
{
|
||||||
@ -742,14 +758,22 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
|
|||||||
template += '?' + ((new Date).valueOf() / 86400 | 0).toString();
|
template += '?' + ((new Date).valueOf() / 86400 | 0).toString();
|
||||||
}
|
}
|
||||||
// File name provided, fetch from server
|
// File name provided, fetch from server
|
||||||
this._template_promise = this._template_widget.load("", template, this.__value || {content: {}},);
|
this._template_widget.load("", template, this.__value || {content: {}},)
|
||||||
|
.then(() =>
|
||||||
|
{
|
||||||
|
this._templateResolver(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Just template name, it better be loaded already
|
// Just template name, it better be loaded already
|
||||||
this._template_promise = this._template_widget.load(this.__template, '', this.__value || {},
|
this._template_widget.load(this.__template, '', this.__value || {},
|
||||||
// true: do NOT call et2_ready, as it would overwrite this.et2 in app.js
|
// true: do NOT call et2_ready, as it would overwrite this.et2 in app.js
|
||||||
undefined, undefined, true);
|
undefined, undefined, true)
|
||||||
|
.then(() =>
|
||||||
|
{
|
||||||
|
this._templateResolver(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't let dialog closing destroy the parent session
|
// Don't let dialog closing destroy the parent session
|
||||||
|
@ -461,7 +461,8 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
|||||||
});
|
});
|
||||||
// Add to DOM, dialog will auto-open
|
// Add to DOM, dialog will auto-open
|
||||||
document.body.appendChild(dialog);
|
document.body.appendChild(dialog);
|
||||||
dialog.getUpdateComplete().then(() => {
|
dialog.updateComplete.then(() =>
|
||||||
|
{
|
||||||
// enable/disable buttons based on timer state
|
// enable/disable buttons based on timer state
|
||||||
setButtonState();
|
setButtonState();
|
||||||
// update timers in dialog
|
// update timers in dialog
|
||||||
|
Reference in New Issue
Block a user