replace jQuery.Deferred with regular Promise

trying to fix not working restore of splitter size in mail, thought it did NOT help in that regard :(
This commit is contained in:
ralf 2022-03-25 10:02:14 +02:00
parent 467e2ca8e2
commit 55da72a661
3 changed files with 240 additions and 243 deletions

View File

@ -2898,9 +2898,8 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const total = this.controller._grid.getTotalCount(); const total = this.controller._grid.getTotalCount();
// Defer the printing to ask about columns & rows // Defer the printing to ask about columns & rows
const defer = jQuery.Deferred(); return new Promise((resolve, reject) =>
{
let pref = this.options.settings.columnselection_pref; let pref = this.options.settings.columnselection_pref;
if (pref.indexOf('nextmatch') == 0) if (pref.indexOf('nextmatch') == 0)
{ {
@ -2961,7 +2960,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Give dialog a chance to close, or it will be in the print // Give dialog a chance to close, or it will be in the print
window.setTimeout(function () window.setTimeout(function ()
{ {
defer.reject(); reject();
}, 0); }, 0);
return; return;
} }
@ -3029,11 +3028,16 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
cancel = true; cancel = true;
window.setTimeout(function () window.setTimeout(function ()
{ {
defer.reject(); reject();
}, 0); }, 0);
}, },
egw.lang('Loading'), egw.lang('please wait...'), {}, [ egw.lang('Loading'), egw.lang('please wait...'), {}, [
{"button_id": Et2Dialog.CANCEL_BUTTON, label: 'cancel', id: 'dialog[cancel]', image: 'cancel'} {
"button_id": Et2Dialog.CANCEL_BUTTON,
label: 'cancel',
id: 'dialog[cancel]',
image: 'cancel'
}
] ]
); );
@ -3066,7 +3070,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
if (cancel) if (cancel)
{ {
dialog.destroy(); dialog.destroy();
defer.reject(); reject();
return; return;
} }
// Use CSS to hide all but the requested rows // Use CSS to hide all but the requested rows
@ -3085,7 +3089,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
dialog.close(); dialog.close();
// Should be OK to print now // Should be OK to print now
defer.resolve(); resolve();
}.bind(nm), et2_dataview_grid.ET2_GRID_INVALIDATE_TIMEOUT); }.bind(nm), et2_dataview_grid.ET2_GRID_INVALIDATE_TIMEOUT);
} }
@ -3113,7 +3117,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Give dialog a chance to close, or it will be in the print // Give dialog a chance to close, or it will be in the print
window.setTimeout(function () window.setTimeout(function ()
{ {
defer.resolve(); resolve();
}, 0); }, 0);
} }
}.bind(this); }.bind(this);
@ -3128,8 +3132,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
} }
}; };
this._create_print_dialog.call(this, value, callback); this._create_print_dialog.call(this, value, callback);
});
return defer;
} }
/** /**
@ -3592,7 +3595,7 @@ export class et2_nextmatch_header_bar extends et2_DOMWidget implements et2_INext
header.loadingFinished(deferred); header.loadingFinished(deferred);
// Wait until all child widgets are loaded, then bind // Wait until all child widgets are loaded, then bind
jQuery.when.apply(jQuery, deferred).then(function() Promise.all(deferred).then(() =>
{ {
// fix order in DOM by reattaching templates in correct position // fix order in DOM by reattaching templates in correct position
switch(id) switch(id)

View File

@ -180,18 +180,19 @@ export class et2_description extends expose(class et2_description extends et2_ba
else else
{ {
// Target widget is not done yet, need to wait // Target widget is not done yet, need to wait
var tab_deferred = jQuery.Deferred(); return new Promise((resolve) =>
window.setTimeout(function() { {
window.setTimeout(() =>
{
for_id = for_widget.dom_id; for_id = for_widget.dom_id;
if (for_widget.instanceOf(et2_inputWidget) && for_widget.getInputNode() && for_widget.dom_id !== for_widget.getInputNode()?.id) if (for_widget.instanceOf(et2_inputWidget) && for_widget.getInputNode() && for_widget.dom_id !== for_widget.getInputNode()?.id)
{ {
for_id = for_widget.getInputNode().id; for_id = for_widget.getInputNode().id;
} }
this.span.attr("for", for_id); this.span.attr("for", for_id);
tab_deferred.resolve(); resolve();
}.bind(this),0); }, 0);
});
return tab_deferred.promise();
} }
} }
return true; return true;
@ -199,7 +200,7 @@ export class et2_description extends expose(class et2_description extends et2_ba
set_label(_value) set_label(_value)
{ {
// Abort if ther was no change in the label // Abort if there was no change in the label
if (_value == this.label) if (_value == this.label)
{ {
return; return;

View File

@ -96,9 +96,6 @@ export class et2_split extends et2_DOMWidget implements et2_IResizeable, et2_IPr
this.left = jQuery("<div>Top / Left</div>").appendTo(this.div); this.left = jQuery("<div>Top / Left</div>").appendTo(this.div);
this.right = jQuery("<div>Bottom / Right</div>").appendTo(this.div); this.right = jQuery("<div>Bottom / Right</div>").appendTo(this.div);
// Deferred object so we can wait for children
this.loading = jQuery.Deferred();
// Flag to temporarily ignore resizing // Flag to temporarily ignore resizing
this.stop_resize = false; this.stop_resize = false;
} }
@ -163,21 +160,18 @@ export class et2_split extends et2_DOMWidget implements et2_IResizeable, et2_IPr
{ {
super.doLoadingFinished(); super.doLoadingFinished();
// Use a timeout to give the children a chance to finish
var self = this;
window.setTimeout(function() {
self._init_splitter();
},1);
// Not done yet, but widget will let you know // Not done yet, but widget will let you know
return this.loading.promise(); return new Promise((resolve) => {
// Use a timeout to give the children a chance to finish
window.setTimeout(() => this._init_splitter(resolve),1);
});
} }
/** /**
* Initialize the splitter UI * Initialize the splitter UI
* Internal. * Internal.
*/ */
private _init_splitter() private _init_splitter(resolve? : Function)
{ {
if(!this.isAttached()) return; if(!this.isAttached()) return;
@ -299,10 +293,10 @@ export class et2_split extends et2_DOMWidget implements et2_IResizeable, et2_IPr
// Ok, update children // Ok, update children
self.iterateOver(function(widget) { self.iterateOver(function(widget) {
// Extra resize would cause stalling chrome // Extra resize would cause stalling chrome
// as resize might confilict with bottom download bar // as resize might conflict with bottom download bar
// in chrome which does a window resize, so better to not // in chrome which does a window resize, so better to not
// trigger second resize and leave that to an application // trigger second resize and leave that to an application
// if it is neccessary. // if it is necessary.
// Above forcing is not enough for Firefox, defer // Above forcing is not enough for Firefox, defer
window.setTimeout(jQuery.proxy(function() {this.resize();}, widget),200); window.setTimeout(jQuery.proxy(function() {this.resize();}, widget),200);
@ -310,7 +304,7 @@ export class et2_split extends et2_DOMWidget implements et2_IResizeable, et2_IPr
}); });
} }
this.loading.resolve(); if (resolve) resolve();
} }
/** /**
@ -460,4 +454,3 @@ export class et2_split extends et2_DOMWidget implements et2_IResizeable, et2_IPr
} }
} }
et2_register_widget(et2_split, ["split"]); et2_register_widget(et2_split, ["split"]);