Prompt for columns to print as well as row count when printing a nextmatch

This commit is contained in:
Nathan Gray 2016-04-20 23:05:43 +00:00
parent 1019046a0d
commit e869788263
2 changed files with 178 additions and 118 deletions

View File

@ -2023,139 +2023,186 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
this.old_height = this.controller._grid._scrollHeight; this.old_height = this.controller._grid._scrollHeight;
var loaded_count = range.bottom - range.top +1; var loaded_count = range.bottom - range.top +1;
var total = this.controller._grid.getTotalCount(); var total = this.controller._grid.getTotalCount();
if(loaded_count != total ||
this.controller._grid.getTotalCount() > 100) // Defer the printing to ask about columns & rows
var defer = jQuery.Deferred();
var pref = this.options.settings.columnselection_pref;
var app = this.getInstanceManager().app;
var columns = {};
var columnMgr = this.dataview.getColumnMgr();
pref += '_print';
var columns_selected = [];
// Get column names
for (var i = 0; i < columnMgr.columns.length; i++)
{ {
// Defer the printing var col = columnMgr.columns[i];
var defer = jQuery.Deferred(); var widget = this.columns[i].widget;
var colName = this._getColumnName(widget);
// Something not in the grid, lets ask if(col.caption && col.visibility !== ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
et2_dialog.show_prompt(jQuery.proxy(function(button, value) { col.visibility !== ET2_COL_VISIBILITY_DISABLED)
if(button == 'dialog[cancel]') { {
// Give dialog a chance to close, or it will be in the print columns[colName] = col.caption;
window.setTimeout(function() {defer.reject();}, 0); if(col.visibility === ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName);
return; }
} // Custom fields get listed separately
value = parseInt(value); if(widget.instanceOf(et2_nextmatch_customfields))
if(value > total) {
{ if(jQuery.isEmptyObject(widget.customfields))
value = total; {
} // No customfields defined, don't show column
delete(columns[col.id]);
continue;
}
for(var field_name in widget.customfields)
{
columns[widget.prefix+field_name] = " - "+widget.customfields[field_name].label;
if(widget.options.fields[field_name]) columns_selected.push(et2_customfields_list.prototype.prefix+field_name);
}
}
}
// If they want the whole thing, treat it as all // Preference exists? Set it now
if(button == 'dialog[ok]' && value == this.controller._grid.getTotalCount()) if(this.egw().preference(pref,app))
{ {
button = 'dialog[all]'; this.set_columns(jQuery.extend([],this.egw().preference(pref,app)));
// Add the class, gives more reliable sizing }
this.div.addClass('print');
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
}
// We need more rows
if(button == 'dialog[all]' || value > loaded_count)
{
var count = 0;
var fetchedCount = 0;
var cancel = false;
var nm = this;
var dialog = et2_dialog.show_dialog(
// Abort the long task if they canceled the data load
function() {count = total; cancel=true;window.setTimeout(function() {defer.reject();},0);},
egw.lang('Loading'), egw.lang('please wait...'),{},[
{"button_id": et2_dialog.CANCEL_BUTTON,"text": 'cancel',id: 'dialog[cancel]',image: 'cancel'}
]
);
// dataFetch() is asyncronous, so all these requests just get fired off... var callback = jQuery.proxy(function(button, value) {
// 200 rows chosen arbitrarily to reduce requests. if(button === et2_dialog.CANCEL_BUTTON) {
do { // Give dialog a chance to close, or it will be in the print
var ctx = { window.setTimeout(function() {defer.reject();}, 0);
"self": this.controller, return;
"start": count, }
"count": Math.min(value,200),
"lastModification": this.controller._lastModification // Handle columns
}; this.set_columns(value.columns);
if(nm.controller.dataStorePrefix) this.egw().set_preference(app,pref,value.columns);
var rows = parseInt(value.row_count);
if(rows > total)
{
rows = total;
}
// If they want the whole thing, style it as all
if(button === et2_dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount())
{
// Add the class, gives more reliable sizing
this.div.addClass('print');
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
}
// We need more rows
if(button === 'dialog[all]' || rows > loaded_count)
{
var count = 0;
var fetchedCount = 0;
var cancel = false;
var nm = this;
var dialog = et2_dialog.show_dialog(
// Abort the long task if they canceled the data load
function() {count = total; cancel=true;window.setTimeout(function() {defer.reject();},0);},
egw.lang('Loading'), egw.lang('please wait...'),{},[
{"button_id": et2_dialog.CANCEL_BUTTON,"text": 'cancel',id: 'dialog[cancel]',image: 'cancel'}
]
);
// dataFetch() is asyncronous, so all these requests just get fired off...
// 200 rows chosen arbitrarily to reduce requests.
do {
var ctx = {
"self": this.controller,
"start": count,
"count": Math.min(rows,200),
"lastModification": this.controller._lastModification
};
if(nm.controller.dataStorePrefix)
{
ctx.prefix = nm.controller.dataStorePrefix;
}
nm.controller.dataFetch({start:count, num_rows: Math.min(rows,200)}, function(data) {
// Keep track
if(data && data.order)
{
fetchedCount += data.order.length;
}
nm.controller._fetchCallback.apply(this, arguments);
if(fetchedCount >= rows)
{
if(cancel)
{ {
ctx.prefix = nm.controller.dataStorePrefix; dialog.destroy();
defer.reject();
return;
} }
nm.controller.dataFetch({start:count, num_rows: Math.min(value,200)}, function(data) { // Use CSS to hide all but the requested rows
// Keep track // Prevents us from showing more than requested, if actual height was less than average
if(data && data.order) nm.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+rows+"))";
{ egw.css(nm.print_row_selector, 'display: none');
fetchedCount += data.order.length;
}
nm.controller._fetchCallback.apply(this, arguments);
if(fetchedCount >= value) // No scrollbar in print view
{ $j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
if(cancel) // Show it all
{ $j('.egwGridView_scrollarea',this.div).css('height','auto');
dialog.destroy();
defer.reject();
return;
}
// Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average
nm.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+value+"))";
egw.css(nm.print_row_selector, 'display: none');
// No scrollbar in print view // Grid needs to redraw before it can be printed, so wait
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden'); window.setTimeout(jQuery.proxy(function() {
// Show it all dialog.destroy();
$j('.egwGridView_scrollarea',this.div).css('height','auto');
// Grid needs to redraw before it can be printed, so wait // Should be OK to print now
window.setTimeout(jQuery.proxy(function() { defer.resolve();
dialog.destroy(); },nm),ET2_GRID_INVALIDATE_TIMEOUT);
// Should be OK to print now }
defer.resolve();
},nm),ET2_GRID_INVALIDATE_TIMEOUT);
} },ctx);
count += 200;
} while (count < rows)
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows+1));
}
else
{
// Don't need more rows, limit to requested and finish
},ctx); // Show it all
count += 200; $j('.egwGridView_scrollarea',this.div).css('height','auto');
} while (count < value)
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1));
}
else
{
// Don't need more rows, limit to requested and finish
// Show it all // Use CSS to hide all but the requested rows
$j('.egwGridView_scrollarea',this.div).css('height','auto'); // Prevents us from showing more than requested, if actual height was less than average
this.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+rows+"))";
egw.css(this.print_row_selector, 'display: none');
// Use CSS to hide all but the requested rows // No scrollbar in print view
// Prevents us from showing more than requested, if actual height was less than average $j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
this.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+value+"))"; // Give dialog a chance to close, or it will be in the print
egw.css(this.print_row_selector, 'display: none'); window.setTimeout(function() {defer.resolve();}, 0);
}
},this);
// No scrollbar in print view var dialog = et2_createWidget("dialog",{
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden'); // If you use a template, the second parameter will be the value of the template, as if it were submitted.
// Give dialog a chance to close, or it will be in the print callback: callback, // return false to prevent dialog closing
window.setTimeout(function() {defer.resolve();}, 0); buttons: et2_dialog.BUTTONS_OK_CANCEL,
} title: 'Print',
},this), template:this.egw().link(this.getInstanceManager().template_base_url+'/api/templates/default/nm_print_dialog.xet'),
egw.lang('How many rows to print'), egw.lang('Print'), value: {
Math.min(100, total), content: {
[ row_count: Math.min(100,total),
{"button_id": 1,"text": egw.lang('Ok'), id: 'dialog[ok]', image: 'check', "default":true}, columns: this.egw().preference(pref,app) || columns_selected
// Nice for small lists, kills server for large lists },
//{"button_id": 2,"text": egw.lang('All'), id: 'dialog[all]', image: ''}, sel_options: {
{"button_id": 0,"text": egw.lang('Cancel'), id: 'dialog[cancel]', image: 'cancel'} columns: columns
] }
); }
return defer; });
}
else return defer;
{
// Show all rows
this.dynheight.innerNode.css('height', 'auto');
$j('.egwGridView_scrollarea',this.div).css('height','auto');
}
// Don't return anything, just work normally
}, },
/** /**
@ -2180,6 +2227,8 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
delete this.print_row_selector; delete this.print_row_selector;
} }
// Restore columns
this.set_columns(this.egw().preference(this.options.settings.columnselection_pref,this.getInstanceManager().app));
this.dynheight.outerNode.css('max-width','inherit'); this.dynheight.outerNode.css('max-width','inherit');
this.resize(); this.resize();
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay PUBLIC "-//Stylite AG//eTemplate 2//EN" "http://www.egroupware.org/etemplate2.dtd">
<!-- $Id$ -->
<overlay>
<template id="nm_print_dialog" template="" lang="" group="0" version="16.1">
<vbox>
<select id="columns" label="Columns to print" rows="8"/>
<integer id="row_count" label="How many rows to print"/>
</vbox>
</template>
</overlay>