* All apps: improved printing: CRM view and given number or rows

r51716: Extend printing support to work with multiple etemplates on the printed tab
r51717: Better handling of printing of various row quantities:
- print < loaded row count
- print > loaded row count
- print all rows
This commit is contained in:
Ralf Becker 2015-02-12 08:06:50 +00:00
parent a7e667c2f1
commit aff689e054
7 changed files with 91 additions and 57 deletions

View File

@ -1867,6 +1867,8 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
// Trigger resize, so we can fit on a page // Trigger resize, so we can fit on a page
this.dynheight.outerNode.css('max-width',this.div.css('max-width')); this.dynheight.outerNode.css('max-width',this.div.css('max-width'));
this.resize(); this.resize();
// Reset height to auto (after width resize) so there's no restrictions
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();
@ -1898,6 +1900,8 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
button = 'dialog[all]'; 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
$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]' || value > loaded_count)
@ -1943,10 +1947,30 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
defer.reject(); defer.reject();
return; return;
} }
if(value < total)
{
// Set height to the requested number of rows, using the average height.
// We add one, in case there's some larger rows we
// try to get most of it but that's pretty hacky
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1)); nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1));
}
// 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);
@ -1961,11 +1985,12 @@ 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+1)); this.controller._grid.setScrollHeight(this.controller._grid.getAverageHeight() * (value));
// No scrollbar in print view
$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
window.setTimeout(function() {defer.resolve();}, 0); window.setTimeout(function() {defer.resolve();}, 0);
} }
//this.controller._gridCallback(0, button == et2_dialog.OK_BUTTON ? value : this.controller._grid.getTotalCount());
},this), },this),
egw.lang('How many rows to print'), egw.lang('Print'), egw.lang('How many rows to print'), egw.lang('Print'),
Math.min(100, total), Math.min(100, total),
@ -1978,6 +2003,12 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
); );
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 // Don't return anything, just work normally
}, },
afterPrint: function() { afterPrint: function() {

View File

@ -909,66 +909,34 @@ etemplate2.app_refresh = function(_msg, _app, _id, _type)
}; };
/** /**
* "Intelligently" print a given app * "Intelligently" print a given etemplate
* *
* Mostly, we let the nextmatch change how many rows it's showing, so you don't * Mostly, we let the nextmatch change how many rows it's showing, so you don't
* get just one printed page. * get just one printed page.
*
* @return {Deferred[]} A list of Deferred objects that must complete before
* actual printing can begin.
*/ */
etemplate2.print = function(_app) etemplate2.prototype.print = function()
{ {
// Allow any widget to change for printing
var et2 = etemplate2.getByApplication(_app);
// Sometimes changes take time // Sometimes changes take time
var deferred = []; var deferred = [];
for(var i = 0; i < et2.length; i++)
{
// Skip hidden templates
if(!jQuery(et2[i].DOMContainer).filter(':visible').length) continue;
et2[i].widgetContainer.iterateOver(function(_widget) { // Skip hidden etemplates
if(!jQuery(this.DOMContainer).filter(':visible').length) return [];
// Allow any widget to change for printing
this.widgetContainer.iterateOver(function(_widget) {
// Skip widgets from a different etemplate (home) // Skip widgets from a different etemplate (home)
if(_widget.getInstanceManager() != et2[i]) return; if(_widget.getInstanceManager() != this) return;
var result = _widget.beforePrint(); var result = _widget.beforePrint();
if (typeof result == "object" && result.done) if (typeof result == "object" && result.done)
{ {
deferred.push(result); deferred.push(result);
} }
},et2,et2_IPrint); },this,et2_IPrint);
}
// Try to clean up after - not guaranteed return deferred;
var afterPrint = function() {
for(var i = 0; i < et2.length; i++)
{
// Skip hidden templates
if(!jQuery(et2[i].DOMContainer).filter(':visible')) continue;
et2[i].widgetContainer.iterateOver(function(_widget) {
_widget.afterPrint();
},et2,et2_IPrint);
}
var mediaQueryList = window.matchMedia('print');
mediaQueryList
};
if(egw.window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
var listener = function(mql) {
if (!mql.matches) {
afterPrint();
mediaQueryList.removeListener(listener);
}
};
mediaQueryList.addListener(listener);
}
egw.window.onafterprint = afterPrint;
// Wait for everything to be loaded, then send it off
jQuery.when.apply(jQuery, deferred).done(function() {
egw.window.print();
}).fail(function() {
afterPrint();
});
} }
// Some static things to make getting into widget context a little easier // // Some static things to make getting into widget context a little easier //

View File

@ -468,7 +468,6 @@ These are set via javascript before printing to help tame nextmatch's layout
for printing for printing
*/ */
.et2_nextmatch.print .egwGridView_scrollarea { .et2_nextmatch.print .egwGridView_scrollarea {
height: auto !important;
width: auto !important; width: auto !important;
} }
.et2_nextmatch.print > div { .et2_nextmatch.print > div {

View File

@ -752,7 +752,6 @@ blockquote blockquote blockquote blockquote blockquote blockquote{
height: auto !important; height: auto !important;
} }
html *, .td_display { html *, .td_display {
font-size: 12pt !important;
border-right: none !important; border-right: none !important;
border-left: none !important; border-left: none !important;
} }

View File

@ -748,7 +748,6 @@ blockquote blockquote blockquote blockquote blockquote blockquote {
} }
html *, html *,
.td_display { .td_display {
font-size: 12pt !important;
border-right: none !important; border-right: none !important;
border-left: none !important; border-left: none !important;
} }

View File

@ -12,7 +12,6 @@
* @version $Id$ * @version $Id$
*/ */
@import (reference) "../../../pixelegg/less/layout_definitions.less"; @import (reference) "../../../pixelegg/less/layout_definitions.less";
@import (reference) "../../../pixelegg/less/definitions.less"; @import (reference) "../../../pixelegg/less/definitions.less";
@import (less) "../default/app.css"; @import (less) "../default/app.css";

View File

@ -960,9 +960,48 @@ var fw_base = Class.extend({
appWindow.focus(); appWindow.focus();
// et2 available, let its widgets prepare // et2 available, let its widgets prepare
if(typeof etemplate2 == "function" && etemplate2.print) var deferred = []
var et2_list = [];
$j('.et2_container',this.activeApp.tab.contDiv).each(function() {
var et2 = etemplate2.getById(this.id);
if(et2 && jQuery(et2.DOMContainer).filter(':visible'))
{ {
etemplate2.print(this.activeApp.appName); deferred = deferred.concat(et2.print());
et2_list.push(et2);
}
});
if(et2_list.length)
{
// Try to clean up after - not guaranteed
var afterPrint = function() {
for(var i = 0; i < et2_list.length; i++)
{
et2_list[i].widgetContainer.iterateOver(function(_widget) {
_widget.afterPrint();
},et2_list[i],et2_IPrint);
}
appWindow.onafterprint = null;
};
if(appWindow.matchMedia) {
var mediaQueryList = appWindow.matchMedia('print');
var listener = function(mql) {
if (!mql.matches) {
afterPrint();
mediaQueryList.removeListener(listener);
}
};
mediaQueryList.addListener(listener);
}
appWindow.onafterprint = afterPrint;
// Wait for everything to be loaded, then send it off
jQuery.when.apply(jQuery, deferred).done(function() {
appWindow.print();
}).fail(function() {
afterPrint();
});
} }
else else
{ {