mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 09:04:53 +01:00
Extend printing support to work with multiple etemplates on the printed tab
This commit is contained in:
parent
2edc2d831b
commit
82f36e6de4
@ -1978,6 +1978,10 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
|
|||||||
);
|
);
|
||||||
return defer;
|
return defer;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.dynheight.innerNode.css('height', 'auto');
|
||||||
|
}
|
||||||
// Don't return anything, just work normally
|
// Don't return anything, just work normally
|
||||||
},
|
},
|
||||||
afterPrint: function() {
|
afterPrint: function() {
|
||||||
|
@ -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
|
||||||
// Skip widgets from a different etemplate (home)
|
if(!jQuery(this.DOMContainer).filter(':visible').length) return [];
|
||||||
if(_widget.getInstanceManager() != et2[i]) return;
|
|
||||||
var result = _widget.beforePrint();
|
|
||||||
if (typeof result == "object" && result.done)
|
|
||||||
{
|
|
||||||
deferred.push(result);
|
|
||||||
}
|
|
||||||
},et2,et2_IPrint);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to clean up after - not guaranteed
|
// Allow any widget to change for printing
|
||||||
var afterPrint = function() {
|
this.widgetContainer.iterateOver(function(_widget) {
|
||||||
for(var i = 0; i < et2.length; i++)
|
// Skip widgets from a different etemplate (home)
|
||||||
|
if(_widget.getInstanceManager() != this) return;
|
||||||
|
var result = _widget.beforePrint();
|
||||||
|
if (typeof result == "object" && result.done)
|
||||||
{
|
{
|
||||||
// Skip hidden templates
|
deferred.push(result);
|
||||||
if(!jQuery(et2[i].DOMContainer).filter(':visible')) continue;
|
|
||||||
et2[i].widgetContainer.iterateOver(function(_widget) {
|
|
||||||
_widget.afterPrint();
|
|
||||||
},et2,et2_IPrint);
|
|
||||||
}
|
}
|
||||||
var mediaQueryList = window.matchMedia('print');
|
},this,et2_IPrint);
|
||||||
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;
|
return deferred;
|
||||||
|
|
||||||
// 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 //
|
||||||
|
@ -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'))
|
||||||
|
{
|
||||||
|
deferred = deferred.concat(et2.print());
|
||||||
|
et2_list.push(et2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(et2_list.length)
|
||||||
{
|
{
|
||||||
etemplate2.print(this.activeApp.appName);
|
// 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
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user