0
1
Fork 0
hedera-web-mindshore/web/js/hedera/report.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-09-22 07:20:47 +00:00
Vn.Report = new Class
({
2015-08-17 18:02:14 +00:00
Extends: Vn.Object
,initialize: function (moduleInfo, gui)
{
this.info = moduleInfo;
this.gui = gui;
this.conn = gui.conn;
this.parent (null);
}
/**
* Gets an object from the builder associated to this report.
*
* @param {string} objectId The object identifier
* @return {Object} The object, or %null if not found
**/
,$: function (objectId)
{
if (this.builderResult)
return this.builderResult.getById (objectId);
return null;
}
,open: function (batch)
{
this.batch = batch;
this.createWindow (this._onWindowLoad.bind (this));
}
,_onWindowLoad: function ()
{
this.doc = this.window.document
var path = this.info.path;
this.includeCss ('reports/'+ path +'/style.css');
var printButton = this.doc.createElement ('button');
printButton.className = 'print-button';
printButton.appendChild (this.doc.createTextNode (_('Print')));
printButton.addEventListener ('click', this.print.bind (this));
this.doc.body.appendChild (printButton);
var builder = new Vn.Builder ();
builder.signalData = this;
builder.add ('batch', this.batch);
builder.add ('conn', this.conn);
builder.loadXml ('reports/'+ path +'/ui.xml');
var res = this.builderResult = builder.load ();
res.link ();
this.doc.body.appendChild (res.$('report'));
}
2015-10-21 23:42:52 +00:00
,print: function ()
2015-09-22 07:20:47 +00:00
{
2015-10-21 23:42:52 +00:00
this.window.print ();
}
2015-10-21 23:42:52 +00:00
,includeCss: function (path)
{
2015-10-21 23:42:52 +00:00
var basePath = location.protocol +'//'+ location.host;
basePath += location.port ? ':'+ location.port : '';
basePath += location.pathname.substring (0,
location.pathname.lastIndexOf ('/'));
2015-09-22 07:20:47 +00:00
2015-10-21 23:42:52 +00:00
var link = this.doc.createElement ('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = basePath +'/'+ path + Vn.getVersion ();
var head = this.doc.getElementsByTagName ('head')[0];
head.appendChild (link);
}
2015-08-17 18:02:14 +00:00
,createWindow: function (callback)
2015-08-17 18:02:14 +00:00
{
var reportWindow = window.open ('js/hedera/report.html', '_blank'/*this.info.path*/,
2015-11-05 07:30:19 +00:00
'resizable=yes,height=900,width=900,scrollbars=yes,menubar=false');
2015-10-21 23:42:52 +00:00
if (!reportWindow)
{
Htk.Toast.showError (
2015-11-05 07:30:19 +00:00
_('Please unlock popups and try again'));
return null;
2015-10-21 23:42:52 +00:00
}
reportWindow.addEventListener ('load', callback);
2015-10-21 23:42:52 +00:00
this.window = reportWindow;
return reportWindow;
2015-08-17 18:02:14 +00:00
}
});