hedera-web/js/hedera/report.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-10-21 23:34:35 +00:00
2022-05-24 21:11:12 +00:00
module.exports = new Class({
2015-10-21 23:34:35 +00:00
Extends: Vn.Object
2022-05-24 21:11:12 +00:00
,initialize: function(moduleInfo, gui) {
this.info = moduleInfo;
this.gui = gui;
this.conn = gui.conn;
2022-05-24 21:11:12 +00:00
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
2022-05-24 21:11:12 +00:00
*/
,$: function(objectId) {
if (this.scope)
return this.scope.getById(objectId);
return null;
}
2022-05-24 21:11:12 +00:00
,open: function(batch) {
this.batch = batch;
2022-05-24 21:11:12 +00:00
this.createWindow();
}
2015-10-21 23:34:35 +00:00
2022-05-24 21:11:12 +00:00
,print: function() {
this.window.print();
2015-10-21 23:34:35 +00:00
}
2022-05-24 21:11:12 +00:00
,includeCss: function(path) {
2015-10-21 23:34:35 +00:00
var basePath = location.protocol +'//'+ location.host;
basePath += location.port ? ':'+ location.port : '';
2022-05-24 21:11:12 +00:00
basePath += location.pathname.substring(0,
location.pathname.lastIndexOf('/'));
2015-10-21 23:34:35 +00:00
2022-05-24 21:11:12 +00:00
var link = this.doc.createElement('link');
2015-10-21 23:34:35 +00:00
link.rel = 'stylesheet';
link.type = 'text/css';
2022-05-24 21:11:12 +00:00
link.href = basePath +'/'+ path + Vn.getVersion();
2015-10-21 23:34:35 +00:00
2022-05-24 21:11:12 +00:00
var head = this.doc.getElementsByTagName('head')[0];
head.appendChild(link);
2015-10-21 23:34:35 +00:00
}
2022-05-24 21:11:12 +00:00
,createWindow: function() {
var reportWindow = window.open(
2015-11-19 13:57:23 +00:00
'js/hedera/report.html', '_blank',
'height=650, width=950, resizable=yes, fullscreen=no,'+
2015-11-19 13:57:23 +00:00
'titlebar=no, menubar=no, toolbar=no, location=no, scrollbars=yes'
);
2015-10-21 23:34:35 +00:00
2022-05-24 21:11:12 +00:00
if (!reportWindow) {
Htk.Toast.showError(
_('Please unlock popups and try again'));
2015-11-19 13:57:23 +00:00
return false;
2015-10-21 23:42:52 +00:00
}
2022-05-24 21:11:12 +00:00
reportWindow.addEventListener('load',
this._onWindowLoad.bind(this));
2015-10-21 23:42:52 +00:00
this.window = reportWindow;
2015-11-19 13:57:23 +00:00
return true;
}
2022-05-24 21:11:12 +00:00
,_onWindowLoad: function() {
2015-11-19 13:57:23 +00:00
this.doc = this.window.document
2022-05-24 21:11:12 +00:00
this.includeCss('reports/'+ this.info.path +'/style.css');
2015-11-19 13:57:23 +00:00
2022-05-24 21:11:12 +00:00
var printButton = this.doc.getElementById('print');
printButton.addEventListener('click', this.print.bind(this));
Vn.Node.setText(printButton, _('Print'));
2015-11-19 13:57:23 +00:00
2022-05-24 21:11:12 +00:00
this.onWindowCreate();
2015-11-19 13:57:23 +00:00
}
2022-05-24 21:11:12 +00:00
,onWindowCreate: function() {
var builder = new Vn.Builder();
builder.compileFile('reports/'+ this.info.path +'/ui.xml');
2015-11-19 13:57:23 +00:00
2022-05-24 21:11:12 +00:00
var scope = this.scope = builder.load(this.doc, this);
scope.link({
batch: this.batch,
conn: this.conn
});
2015-11-19 13:57:23 +00:00
2022-05-24 21:11:12 +00:00
this.doc.body.appendChild(scope.$('report'));
2015-10-21 23:34:35 +00:00
}
});