]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt.js
ever more toil
[working/Evergreen.git] / Open-ILS / web / reports / oils_rpt.js
1 function oilsInitReports() {
2         oilsRptIdObjects();
3
4         /* tell FF to capture mouse movements */
5         document.captureEvents(Event.MOUSEMOVE);
6         document.onmousemove = setMousePos;
7
8         var cgi = new CGI();
9         fetchUser(cgi.param('ses'));
10         DOM.oils_rpt_user.appendChild(text(USER.usrname()));
11         oilsRptDebugEnabled = cgi.param('dbg');
12 }
13
14 function oilsRtpInitFolders() {
15         oilsRptCurrentFolderManager = 
16                 new oilsRptFolderManager(DOM.oils_rpt_folder_tree_div);
17         oilsRptCurrentFolderManager.draw(SESSION);
18 }
19
20 function oilsCleanupReports() {
21         try {oilsRptDebugWindow.close();} catch(e) {}
22         DOM = null;
23 }
24
25
26
27
28 /* ---------------------------------------------------------------------
29         Define the report object
30         --------------------------------------------------------------------- */
31 function oilsReport(templateObj, reportObj) {
32         this.def = {
33                 select  : [],
34                 from            : {},
35                 where           : [],
36                 having  : [],
37                 order_by : []
38         };
39
40         this.params     = {};
41         this.name       = "";
42         this.templateObject = templateObj;
43         this.reportObject = reportObj;
44
45         if( templateObj ) {
46                 this.def = JSON2js(templateObj.data());
47                 this.name = templateObj.name();
48         }
49
50         if( reportObj ) 
51                 this.params = JSON2js(reportObj.data());
52 }
53
54 oilsReport.prototype.toString = function() {
55         return formatJSON(js2JSON(this));
56 }
57
58 oilsReport.prototype.toHTMLString = function() {
59         return formatJSONHTML(js2JSON(this));
60 }
61
62 oilsReport.prototype.gatherParams = function() {
63         if(oilsRptObjectKeys(this.params).length == 0) return;
64
65         _debug("we have params: " + js2JSON(this.params));
66
67         var params      = [];
68         this._gatherParams(params, this.def.select, 'select', 'alias');
69         this._gatherParams(params, this.def.where, 'where', 'condition');
70         this._gatherParams(params, this.def.having, 'having', 'condition');
71         return params;
72 }
73
74 oilsReport.prototype._gatherParams = function(params, arr, type, field) {
75         if(!arr) return;
76         for( var i = 0; i < arr.length; i++ ) {
77
78                 var obj = arr[i];
79                 node = obj[field];
80                 var key; 
81                 var op;
82
83                 if( typeof node == 'string' ) {
84                         key = node.match(/::.*/);
85                 } else {
86                         op = oilsRptObjectKeys(node)[0];
87                         key = (node[op] +'').match(/::.*/);
88                 }
89
90                 if(!key) continue;
91                 key = key[0].replace(/::/,'');
92                 _debug("key = "+key+", param = " + this.params[key]);
93
94                 params.push( { 
95                         key             : key,
96                         op                      : op,
97                         value           : this.params[key],
98                         column  : obj.column,
99                         type            : type, 
100                         relation : obj.relation
101                 });
102         }
103 }
104
105
106
107