Printing improvements

This commit is contained in:
Nathan Gray 2015-02-23 18:07:29 +00:00
parent b7d00df071
commit 29d0f737d5
2 changed files with 58 additions and 30 deletions

View File

@ -1875,7 +1875,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
this.resize(); this.resize();
// Reset height to auto (after width resize) so there's no restrictions // Reset height to auto (after width resize) so there's no restrictions
this.dynheight.innerNode.css('height', 'auto'); this.dynheight.innerNode.css('height', 'auto');
// Check for rows that aren't loaded yet, or lots of rows // Check for rows that aren't loaded yet, or lots of rows
var range = this.controller._grid.getIndexRange(); var range = this.controller._grid.getIndexRange();
this.old_height = this.controller._grid._scrollHeight; this.old_height = this.controller._grid._scrollHeight;
@ -1953,30 +1953,20 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
defer.reject(); defer.reject();
return; return;
} }
if(value < total) // Use CSS to hide all but the requested rows
{ // Prevents us from showing more than requested, if actual height was less than average
// Set height to the requested number of rows, using the average height. nm.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+value+"))";
// We add one, in case there's some larger rows we egw.css(nm.print_row_selector, 'display: none');
// try to get most of it but that's pretty hacky
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1)); // No scrollbar in print view
} $j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
// Show it all
$j('.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(jQuery.proxy(function() { window.setTimeout(jQuery.proxy(function() {
dialog.destroy(); dialog.destroy();
if(value < total)
{
// Show requested number, based on average height
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value));
// No scrollbar in print view
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
}
else
{
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
}
// Should be OK to print now // Should be OK to print now
defer.resolve(); defer.resolve();
},nm),ET2_GRID_INVALIDATE_TIMEOUT); },nm),ET2_GRID_INVALIDATE_TIMEOUT);
@ -1991,7 +1981,15 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
else else
{ {
// Don't need more rows, limit to requested and finish // Don't need more rows, limit to requested and finish
this.controller._grid.setScrollHeight(this.controller._grid.getAverageHeight() * (value));
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
// Use CSS to hide all but the requested rows
// 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+"))";
egw.css(this.print_row_selector, 'display: none');
// No scrollbar in print view // No scrollbar in print view
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden'); $j('.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
@ -2017,10 +2015,29 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
} }
// Don't return anything, just work normally // Don't return anything, just work normally
}, },
/**
* Try to clean up the mess we made getting ready for printing
* in beforePrint()
*/
afterPrint: function() { afterPrint: function() {
this.div.removeClass('print'); this.div.removeClass('print');
// Put scrollbar back
$j('.egwGridView_scrollarea',this.div).css('overflow-y','');
// Correct size of grid, and trigger resize to fix it
this.controller._grid.setScrollHeight(this.old_height); this.controller._grid.setScrollHeight(this.old_height);
delete this.old_height; delete this.old_height;
// Remove CSS rule hiding extra rows
if(this.print_row_selector)
{
egw.css(this.print_row_selector, false);
delete this.print_row_selector;
}
this.dynheight.outerNode.css('max-width','inherit'); this.dynheight.outerNode.css('max-width','inherit');
this.resize(); this.resize();
} }

View File

@ -975,20 +975,29 @@ var fw_base = Class.extend({
{ {
// Try to clean up after - not guaranteed // Try to clean up after - not guaranteed
var afterPrint = function() { var afterPrint = function() {
for(var i = 0; i < et2_list.length; i++) // Reset after removing margin
{ $j('#egw_fw_main').css('margin-left', (framework.activeApp.sideboxWidth -1)+ "px");
et2_list[i].widgetContainer.iterateOver(function(_widget) { var app = framework.activeApp;
_widget.afterPrint(); framework.activeApp = '';
},et2_list[i],et2_IPrint); framework.setActiveApp(app);
}
// Give framework a chance to deal, then reset the etemplates
window.setTimeout(function() {
for(var i = 0; i < et2_list.length; i++)
{
et2_list[i].widgetContainer.iterateOver(function(_widget) {
_widget.afterPrint();
},et2_list[i],et2_IPrint);
}
},100);
appWindow.onafterprint = null; appWindow.onafterprint = null;
}; };
if(appWindow.matchMedia) { if(appWindow.matchMedia) {
var mediaQueryList = appWindow.matchMedia('print'); var mediaQueryList = appWindow.matchMedia('print');
var listener = function(mql) { var listener = function(mql) {
if (!mql.matches) { if (!mql.matches) {
afterPrint();
mediaQueryList.removeListener(listener); mediaQueryList.removeListener(listener);
afterPrint();
} }
}; };
mediaQueryList.addListener(listener); mediaQueryList.addListener(listener);
@ -998,7 +1007,9 @@ var fw_base = Class.extend({
// 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() { jQuery.when.apply(jQuery, deferred).done(function() {
appWindow.print(); // Despite being set in the print CSS, this just doesn't work
$j('#egw_fw_main').css('margin-left','0px');
appWindow.setTimeout(appWindow.print, 0);
}).fail(function() { }).fail(function() {
afterPrint(); afterPrint();
}); });