mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 07:53:39 +01:00
Fix nm printing did not properly wait for column selection or rows before trying to print
This commit is contained in:
parent
d6bfa7d9ee
commit
8221d66ce2
@ -2853,67 +2853,39 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
const total = this.controller._grid.getTotalCount();
|
||||
|
||||
// Defer the printing to ask about columns & rows
|
||||
return new Promise((resolve, reject) =>
|
||||
return new Promise(async(resolve, reject) =>
|
||||
{
|
||||
let pref = this.options.settings.columnselection_pref;
|
||||
if (pref.indexOf('nextmatch') == 0)
|
||||
if(pref.indexOf('nextmatch') == 0)
|
||||
{
|
||||
pref = 'nextmatch-' + pref;
|
||||
}
|
||||
const app = this.getInstanceManager().app;
|
||||
|
||||
const columns = {};
|
||||
const columns = [];
|
||||
const columnMgr = this.dataview.getColumnMgr();
|
||||
pref += '_print';
|
||||
const columns_selected = [];
|
||||
|
||||
// Get column names
|
||||
for (let i = 0; i < columnMgr.columns.length; i++)
|
||||
for(var i = 0; i < columnMgr.columns.length; i++)
|
||||
{
|
||||
const col = columnMgr.columns[i];
|
||||
let col = columnMgr.columns[i];
|
||||
const widget = this.columns[i].widget;
|
||||
let colName = this._getColumnName(widget);
|
||||
|
||||
if (col.caption && col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
|
||||
col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_DISABLED)
|
||||
{
|
||||
columns[colName] = col.caption;
|
||||
if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName);
|
||||
}
|
||||
// Custom fields get listed separately
|
||||
if (widget.instanceOf(et2_nextmatch_customfields))
|
||||
{
|
||||
delete (columns[colName]);
|
||||
colName = widget.id;
|
||||
if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE && !
|
||||
jQuery.isEmptyObject((<et2_nextmatch_customfields><unknown>widget).customfields)
|
||||
)
|
||||
{
|
||||
columns[colName] = col.caption;
|
||||
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;
|
||||
if (widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0)
|
||||
{
|
||||
columns_selected.push(et2_nextmatch_customfields.PREFIX + field_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
columns.push({...col, widget: widget, name: this._getColumnName(widget)});
|
||||
}
|
||||
|
||||
// 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)));
|
||||
}
|
||||
|
||||
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
|
||||
window.setTimeout(function ()
|
||||
window.setTimeout(function()
|
||||
{
|
||||
reject();
|
||||
}, 0);
|
||||
@ -2934,7 +2906,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
style.media = 'print';
|
||||
|
||||
// @ts-ignore
|
||||
if (style.styleSheet)
|
||||
if(style.styleSheet)
|
||||
{
|
||||
// @ts-ignore
|
||||
style.styleSheet.cssText = css;
|
||||
@ -2951,17 +2923,23 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
this.dynheight.outerNode.css('max-width', this.div.css('max-width'));
|
||||
|
||||
// Handle columns
|
||||
this.set_columns(value.columns);
|
||||
this.egw().set_preference(app, pref, value.columns);
|
||||
let column_names = [];
|
||||
value.columns.forEach((col_id) =>
|
||||
{
|
||||
let name = columns.find((col) => col.id == col_id)?.name || ""
|
||||
column_names.push(name || col_id);
|
||||
})
|
||||
this.set_columns(column_names);
|
||||
this.egw().set_preference(app, pref, column_names);
|
||||
|
||||
let rows = parseInt(value.row_count);
|
||||
if (rows > total)
|
||||
if(rows > total)
|
||||
{
|
||||
rows = total;
|
||||
}
|
||||
|
||||
// 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
|
||||
this.div.addClass('print');
|
||||
@ -2969,7 +2947,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
|
||||
}
|
||||
// We need more rows
|
||||
if (button === 'dialog[all]' || rows > loaded_count)
|
||||
if(button === 'dialog[all]' || rows > loaded_count)
|
||||
{
|
||||
let count = 0;
|
||||
let fetchedCount = 0;
|
||||
@ -2977,11 +2955,11 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
const nm = this;
|
||||
const dialog = Et2Dialog.show_dialog(
|
||||
// Abort the long task if they canceled the data load
|
||||
function ()
|
||||
function()
|
||||
{
|
||||
count = total;
|
||||
cancel = true;
|
||||
window.setTimeout(function ()
|
||||
window.setTimeout(function()
|
||||
{
|
||||
reject();
|
||||
}, 0);
|
||||
@ -3006,23 +2984,23 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
"count": Math.min(rows, 200),
|
||||
"lastModification": this.controller._lastModification
|
||||
};
|
||||
if (nm.controller.dataStorePrefix)
|
||||
if(nm.controller.dataStorePrefix)
|
||||
{
|
||||
// @ts-ignore
|
||||
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
|
||||
if (data && data.order)
|
||||
if(data && data.order)
|
||||
{
|
||||
fetchedCount += data.order.length;
|
||||
}
|
||||
nm.controller._fetchCallback.apply(this, arguments);
|
||||
|
||||
if (fetchedCount >= rows)
|
||||
if(fetchedCount >= rows)
|
||||
{
|
||||
if (cancel)
|
||||
if(cancel)
|
||||
{
|
||||
dialog.destroy();
|
||||
reject();
|
||||
@ -3039,7 +3017,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
|
||||
|
||||
// Grid needs to redraw before it can be printed, so wait
|
||||
window.setTimeout(function ()
|
||||
window.setTimeout(function()
|
||||
{
|
||||
dialog.close();
|
||||
|
||||
@ -3052,7 +3030,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
}, ctx);
|
||||
count += 200;
|
||||
}
|
||||
while (count < rows);
|
||||
while(count < rows);
|
||||
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows + 1));
|
||||
}
|
||||
else
|
||||
@ -3070,23 +3048,28 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
// No scrollbar in print view
|
||||
jQuery('.egwGridView_scrollarea', this.div).css('overflow-y', 'hidden');
|
||||
// Give dialog a chance to close, or it will be in the print
|
||||
window.setTimeout(function ()
|
||||
window.setTimeout(function()
|
||||
{
|
||||
resolve();
|
||||
}, 0);
|
||||
}
|
||||
}.bind(this);
|
||||
var value = {
|
||||
const value = {
|
||||
content: {
|
||||
row_count: Math.min(100, total),
|
||||
columns: this.egw().preference(pref, app) || columns_selected,
|
||||
orientation: this.egw().preference(pref + '_orientation', app)
|
||||
},
|
||||
sel_options: {
|
||||
columns: columns
|
||||
modifications: {
|
||||
autoRefresh: {
|
||||
disabled: true
|
||||
},
|
||||
columns: {
|
||||
columns: columns,
|
||||
}
|
||||
}
|
||||
};
|
||||
this._create_print_dialog.call(this, value, callback);
|
||||
await this._create_print_dialog.call(this, value, callback).updateComplete;
|
||||
});
|
||||
}
|
||||
|
||||
@ -3121,6 +3104,8 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
|
||||
value: value
|
||||
});
|
||||
document.body.appendChild(dialog);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1386,7 +1386,7 @@ export class etemplate2
|
||||
}
|
||||
|
||||
const result = _widget.beforePrint();
|
||||
if(typeof result == "object" && result.done)
|
||||
if(typeof result == "object")
|
||||
{
|
||||
deferred.push(result);
|
||||
}
|
||||
|
@ -1307,9 +1307,11 @@ window.fw_base = (function(){ "use strict"; return Class.extend(
|
||||
appWindow.onafterprint = afterPrint;
|
||||
|
||||
// Wait for everything to be loaded, then send it off
|
||||
jQuery.when.apply(jQuery, deferred).done(function() {
|
||||
Promise.all(deferred).then(() =>
|
||||
{
|
||||
appWindow.setTimeout(appWindow.print, 0);
|
||||
}).fail(function() {
|
||||
}).catch(function ()
|
||||
{
|
||||
afterPrint();
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<template id="nm_print_dialog" template="" lang="" group="0" version="16.1">
|
||||
<vbox>
|
||||
<description value="Columns to print"/>
|
||||
<select id="columns" multiple="true" selected_first="false"/>
|
||||
<et2-nextmatch-columnselection id="columns"></et2-nextmatch-columnselection>
|
||||
<integer id="row_count" label="How many rows to print"/>
|
||||
<checkbox id="orientation" toggle_on="Portrait" toggle_off="Landscape" selected_value="portrait" unselected_value="landscape"/>
|
||||
</vbox>
|
||||
|
Loading…
Reference in New Issue
Block a user