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

99 lines
2.2 KiB
JavaScript
Executable File

Vn.Report = new Class
({
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'));
}
,print: function ()
{
this.window.print ();
}
,includeCss: function (path)
{
var basePath = location.protocol +'//'+ location.host;
basePath += location.port ? ':'+ location.port : '';
basePath += location.pathname.substring (0,
location.pathname.lastIndexOf ('/'));
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);
}
,createWindow: function (callback)
{
var reportWindow = window.open ('js/hedera/report.html', '_blank'/*this.info.path*/,
'resizable=yes,height=900,width=900,scrollbars=yes,menubar=false');
if (!reportWindow)
{
Htk.Toast.showError (
_('Please unlock popups and try again'));
return null;
}
reportWindow.addEventListener ('load', callback);
this.window = reportWindow;
return reportWindow;
}
});