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,11 +2898,10 @@ 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)
{ {
pref = 'nextmatch-' + pref; pref = 'nextmatch-' + pref;
} }
@ -2914,32 +2913,32 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const columns_selected = []; const columns_selected = [];
// Get column names // Get column names
for(let i = 0; i < columnMgr.columns.length; i++) for (let i = 0; i < columnMgr.columns.length; i++)
{ {
const col = columnMgr.columns[i]; const col = columnMgr.columns[i];
const widget = this.columns[i].widget; const widget = this.columns[i].widget;
let colName = this._getColumnName(widget); let colName = this._getColumnName(widget);
if(col.caption && col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_ALWAYS_NOSELECT && if (col.caption && col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_DISABLED) col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_DISABLED)
{ {
columns[colName] = col.caption; columns[colName] = col.caption;
if(col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName); if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName);
} }
// Custom fields get listed separately // Custom fields get listed separately
if(widget.instanceOf(et2_nextmatch_customfields)) if (widget.instanceOf(et2_nextmatch_customfields))
{ {
delete (columns[colName]); delete (columns[colName]);
colName = widget.id; colName = widget.id;
if(col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE && ! if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE && !
jQuery.isEmptyObject((<et2_nextmatch_customfields><unknown>widget).customfields) jQuery.isEmptyObject((<et2_nextmatch_customfields><unknown>widget).customfields)
) )
{ {
columns[colName] = col.caption; columns[colName] = col.caption;
for(let field_name in (<et2_nextmatch_customfields><unknown>widget).customfields) for (let field_name in (<et2_nextmatch_customfields><unknown>widget).customfields)
{ {
columns[et2_nextmatch_customfields.PREFIX + field_name] = " - " + (<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label; columns[et2_nextmatch_customfields.PREFIX + field_name] = " - " + (<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label;
if(widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0) if (widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0)
{ {
columns_selected.push(et2_nextmatch_customfields.PREFIX + field_name); columns_selected.push(et2_nextmatch_customfields.PREFIX + field_name);
} }
@ -2949,19 +2948,19 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
} }
// Preference exists? Set it now // Preference exists? Set it now
if(this.egw().preference(pref, app)) if (this.egw().preference(pref, app))
{ {
this.set_columns(jQuery.extend([], this.egw().preference(pref, app))); this.set_columns(jQuery.extend([], this.egw().preference(pref, app)));
} }
const callback = function(button, value) const callback = function (button, value)
{ {
if(button === Et2Dialog.CANCEL_BUTTON) if (button === Et2Dialog.CANCEL_BUTTON)
{ {
// 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;
} }
@ -2980,7 +2979,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
style.media = 'print'; style.media = 'print';
// @ts-ignore // @ts-ignore
if(style.styleSheet) if (style.styleSheet)
{ {
// @ts-ignore // @ts-ignore
style.styleSheet.cssText = css; style.styleSheet.cssText = css;
@ -3001,13 +3000,13 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
this.egw().set_preference(app, pref, value.columns); this.egw().set_preference(app, pref, value.columns);
let rows = parseInt(value.row_count); let rows = parseInt(value.row_count);
if(rows > total) if (rows > total)
{ {
rows = total; rows = total;
} }
// If they want the whole thing, style it as all // If they want the whole thing, style it as all
if(button === Et2Dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount()) if (button === Et2Dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount())
{ {
// Add the class, gives more reliable sizing // Add the class, gives more reliable sizing
this.div.addClass('print'); this.div.addClass('print');
@ -3015,7 +3014,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto'); jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
} }
// We need more rows // We need more rows
if(button === 'dialog[all]' || rows > loaded_count) if (button === 'dialog[all]' || rows > loaded_count)
{ {
let count = 0; let count = 0;
let fetchedCount = 0; let fetchedCount = 0;
@ -3023,17 +3022,22 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const nm = this; const nm = this;
const dialog = Et2Dialog.show_dialog( const dialog = Et2Dialog.show_dialog(
// Abort the long task if they canceled the data load // Abort the long task if they canceled the data load
function() function ()
{ {
count = total; count = total;
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'
}
] ]
); );
@ -3047,26 +3051,26 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
"count": Math.min(rows, 200), "count": Math.min(rows, 200),
"lastModification": this.controller._lastModification "lastModification": this.controller._lastModification
}; };
if(nm.controller.dataStorePrefix) if (nm.controller.dataStorePrefix)
{ {
// @ts-ignore // @ts-ignore
ctx.prefix = nm.controller.dataStorePrefix; ctx.prefix = nm.controller.dataStorePrefix;
} }
nm.controller.dataFetch({start: count, num_rows: Math.min(rows, 200)}, function(data) nm.controller.dataFetch({start: count, num_rows: Math.min(rows, 200)}, function (data)
{ {
// Keep track // Keep track
if(data && data.order) if (data && data.order)
{ {
fetchedCount += data.order.length; fetchedCount += data.order.length;
} }
nm.controller._fetchCallback.apply(this, arguments); nm.controller._fetchCallback.apply(this, arguments);
if(fetchedCount >= rows) if (fetchedCount >= rows)
{ {
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
@ -3080,12 +3084,12 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto'); jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
// Grid needs to redraw before it can be printed, so wait // Grid needs to redraw before it can be printed, so wait
window.setTimeout(function() window.setTimeout(function ()
{ {
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);
} }
@ -3093,7 +3097,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
}, ctx); }, ctx);
count += 200; count += 200;
} }
while(count < rows); while (count < rows);
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows + 1)); nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows + 1));
} }
else else
@ -3111,9 +3115,9 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// No scrollbar in print view // No scrollbar in print view
jQuery('.egwGridView_scrollarea', this.div).css('overflow-y', 'hidden'); jQuery('.egwGridView_scrollarea', this.div).css('overflow-y', 'hidden');
// 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"]);