Fix nm printing did not properly wait for column selection or rows before trying to print

This commit is contained in:
nathan 2022-10-06 15:39:35 -06:00
parent d6bfa7d9ee
commit 8221d66ce2
4 changed files with 49 additions and 62 deletions

View File

@ -2853,7 +2853,7 @@ 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
return new Promise((resolve, reject) => return new Promise(async(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)
@ -2862,44 +2862,16 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
} }
const app = this.getInstanceManager().app; const app = this.getInstanceManager().app;
const columns = {}; const columns = [];
const columnMgr = this.dataview.getColumnMgr(); const columnMgr = this.dataview.getColumnMgr();
pref += '_print'; pref += '_print';
const columns_selected = []; const columns_selected = [];
// Get column names for(var i = 0; i < columnMgr.columns.length; i++)
for (let i = 0; i < columnMgr.columns.length; i++)
{ {
const col = columnMgr.columns[i]; let col = columnMgr.columns[i];
const widget = this.columns[i].widget; const widget = this.columns[i].widget;
let colName = this._getColumnName(widget); columns.push({...col, widget: widget, name: 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);
}
}
}
}
} }
// Preference exists? Set it now // Preference exists? Set it now
@ -2951,8 +2923,14 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
this.dynheight.outerNode.css('max-width', this.div.css('max-width')); this.dynheight.outerNode.css('max-width', this.div.css('max-width'));
// Handle columns // Handle columns
this.set_columns(value.columns); let column_names = [];
this.egw().set_preference(app, pref, value.columns); 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); let rows = parseInt(value.row_count);
if(rows > total) if(rows > total)
@ -3076,17 +3054,22 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
}, 0); }, 0);
} }
}.bind(this); }.bind(this);
var value = { const value = {
content: { content: {
row_count: Math.min(100, total), row_count: Math.min(100, total),
columns: this.egw().preference(pref, app) || columns_selected, columns: this.egw().preference(pref, app) || columns_selected,
orientation: this.egw().preference(pref + '_orientation', app) orientation: this.egw().preference(pref + '_orientation', app)
}, },
sel_options: { modifications: {
columns: columns 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 value: value
}); });
document.body.appendChild(dialog); document.body.appendChild(dialog);
return dialog;
} }
/** /**

View File

@ -1386,7 +1386,7 @@ export class etemplate2
} }
const result = _widget.beforePrint(); const result = _widget.beforePrint();
if(typeof result == "object" && result.done) if(typeof result == "object")
{ {
deferred.push(result); deferred.push(result);
} }

View File

@ -1307,9 +1307,11 @@ window.fw_base = (function(){ "use strict"; return Class.extend(
appWindow.onafterprint = afterPrint; appWindow.onafterprint = afterPrint;
// Wait for everything to be loaded, then send it off // 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); appWindow.setTimeout(appWindow.print, 0);
}).fail(function() { }).catch(function ()
{
afterPrint(); afterPrint();
}); });
} }

View File

@ -5,7 +5,7 @@
<template id="nm_print_dialog" template="" lang="" group="0" version="16.1"> <template id="nm_print_dialog" template="" lang="" group="0" version="16.1">
<vbox> <vbox>
<description value="Columns to print"/> <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"/> <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"/> <checkbox id="orientation" toggle_on="Portrait" toggle_off="Landscape" selected_value="portrait" unselected_value="landscape"/>
</vbox> </vbox>