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,36 +2023,82 @@ 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
{
// Defer the printing
var defer = jQuery.Deferred(); var defer = jQuery.Deferred();
// Something not in the grid, lets ask
et2_dialog.show_prompt(jQuery.proxy(function(button, value) { var pref = this.options.settings.columnselection_pref;
if(button == 'dialog[cancel]') { 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++)
{
var col = columnMgr.columns[i];
var widget = this.columns[i].widget;
var colName = this._getColumnName(widget);
if(col.caption && col.visibility !== ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
col.visibility !== ET2_COL_VISIBILITY_DISABLED)
{
columns[colName] = col.caption;
if(col.visibility === ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName);
}
// Custom fields get listed separately
if(widget.instanceOf(et2_nextmatch_customfields))
{
if(jQuery.isEmptyObject(widget.customfields))
{
// 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);
}
}
}
// Preference exists? Set it now
if(this.egw().preference(pref,app))
{
this.set_columns(jQuery.extend([],this.egw().preference(pref,app)));
}
var callback = jQuery.proxy(function(button, value) {
if(button === et2_dialog.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() {defer.reject();}, 0); window.setTimeout(function() {defer.reject();}, 0);
return; return;
} }
value = parseInt(value);
if(value > total) // Handle columns
this.set_columns(value.columns);
this.egw().set_preference(app,pref,value.columns);
var rows = parseInt(value.row_count);
if(rows > total)
{ {
value = total; rows = total;
} }
// If they want the whole thing, treat it as all // If they want the whole thing, style it as all
if(button == 'dialog[ok]' && value == this.controller._grid.getTotalCount()) if(button === et2_dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount())
{ {
button = 'dialog[all]';
// Add the class, gives more reliable sizing // Add the class, gives more reliable sizing
this.div.addClass('print'); this.div.addClass('print');
// Show it all // Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto'); $j('.egwGridView_scrollarea',this.div).css('height','auto');
} }
// We need more rows // We need more rows
if(button == 'dialog[all]' || value > loaded_count) if(button === 'dialog[all]' || rows > loaded_count)
{ {
var count = 0; var count = 0;
var fetchedCount = 0; var fetchedCount = 0;
@ -2072,14 +2118,14 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
var ctx = { var ctx = {
"self": this.controller, "self": this.controller,
"start": count, "start": count,
"count": Math.min(value,200), "count": Math.min(rows,200),
"lastModification": this.controller._lastModification "lastModification": this.controller._lastModification
}; };
if(nm.controller.dataStorePrefix) if(nm.controller.dataStorePrefix)
{ {
ctx.prefix = nm.controller.dataStorePrefix; ctx.prefix = nm.controller.dataStorePrefix;
} }
nm.controller.dataFetch({start:count, num_rows: Math.min(value,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)
{ {
@ -2087,7 +2133,7 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
} }
nm.controller._fetchCallback.apply(this, arguments); nm.controller._fetchCallback.apply(this, arguments);
if(fetchedCount >= value) if(fetchedCount >= rows)
{ {
if(cancel) if(cancel)
{ {
@ -2097,7 +2143,7 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
} }
// Use CSS to hide all but the requested rows // Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average // 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+"))"; nm.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+rows+"))";
egw.css(nm.print_row_selector, 'display: none'); egw.css(nm.print_row_selector, 'display: none');
// No scrollbar in print view // No scrollbar in print view
@ -2117,8 +2163,8 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
},ctx); },ctx);
count += 200; count += 200;
} while (count < value) } while (count < rows)
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1)); nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows+1));
} }
else else
{ {
@ -2129,7 +2175,7 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([et2_
// Use CSS to hide all but the requested rows // Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average // 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+"+value+"))"; this.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+rows+"))";
egw.css(this.print_row_selector, 'display: none'); egw.css(this.print_row_selector, 'display: none');
// No scrollbar in print view // No scrollbar in print view
@ -2137,25 +2183,26 @@ var et2_nextmatch = (function(){ "use strict"; return et2_DOMWidget.extend([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() {defer.resolve();}, 0); window.setTimeout(function() {defer.resolve();}, 0);
} }
},this), },this);
egw.lang('How many rows to print'), egw.lang('Print'),
Math.min(100, total), var dialog = et2_createWidget("dialog",{
[ // If you use a template, the second parameter will be the value of the template, as if it were submitted.
{"button_id": 1,"text": egw.lang('Ok'), id: 'dialog[ok]', image: 'check', "default":true}, callback: callback, // return false to prevent dialog closing
// Nice for small lists, kills server for large lists buttons: et2_dialog.BUTTONS_OK_CANCEL,
//{"button_id": 2,"text": egw.lang('All'), id: 'dialog[all]', image: ''}, title: 'Print',
{"button_id": 0,"text": egw.lang('Cancel'), id: 'dialog[cancel]', image: 'cancel'} template:this.egw().link(this.getInstanceManager().template_base_url+'/api/templates/default/nm_print_dialog.xet'),
] value: {
); content: {
row_count: Math.min(100,total),
columns: this.egw().preference(pref,app) || columns_selected
},
sel_options: {
columns: columns
}
}
});
return defer; return defer;
}
else
{
// 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>