mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +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;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dynheight.innerNode.css('height', 'auto');
|
||||
}
|
||||
// Don't return anything, just work normally
|
||||
},
|
||||
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
|
||||
* 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
|
||||
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 widgets from a different etemplate (home)
|
||||
if(_widget.getInstanceManager() != et2[i]) return;
|
||||
var result = _widget.beforePrint();
|
||||
if (typeof result == "object" && result.done)
|
||||
{
|
||||
deferred.push(result);
|
||||
}
|
||||
},et2,et2_IPrint);
|
||||
}
|
||||
// Skip hidden etemplates
|
||||
if(!jQuery(this.DOMContainer).filter(':visible').length) return [];
|
||||
|
||||
// Try to clean up after - not guaranteed
|
||||
var afterPrint = function() {
|
||||
for(var i = 0; i < et2.length; i++)
|
||||
// Allow any widget to change for printing
|
||||
this.widgetContainer.iterateOver(function(_widget) {
|
||||
// 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
|
||||
if(!jQuery(et2[i].DOMContainer).filter(':visible')) continue;
|
||||
et2[i].widgetContainer.iterateOver(function(_widget) {
|
||||
_widget.afterPrint();
|
||||
},et2,et2_IPrint);
|
||||
deferred.push(result);
|
||||
}
|
||||
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);
|
||||
}
|
||||
},this,et2_IPrint);
|
||||
|
||||
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();
|
||||
});
|
||||
return deferred;
|
||||
}
|
||||
|
||||
// Some static things to make getting into widget context a little easier //
|
||||
|
@ -960,9 +960,48 @@ var fw_base = Class.extend({
|
||||
appWindow.focus();
|
||||
|
||||
// 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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user