]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt.js
more output support, more report editor options, etc.
[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
12         fetchHighestPermOrgs(SESSION, USER.id(), ['RUN_REPORTS']);
13         if( PERMS['RUN_REPORTS'] == -1 ) {
14                 unHideMe(DOM.oils_rpt_permission_denied);
15                 hideMe(DOM.oils_rpt_tree_loading);
16                 return false;
17         }
18
19         oilsRptCookie = new HTTP.Cookies();
20         oilsRptCurrentOrg = USER.ws_ou();
21         cookieManager.write(COOKIE_SES, SESSION, -1, '/');
22         cookieManager.write('ws_ou', USER.ws_ou(), -1, '/');
23
24         oilsRptFetchOrgTree(
25                 function() {
26                         oilsLoadRptTree(
27                                 function() {
28                                         hideMe(DOM.oils_rpt_tree_loading); 
29                                         unHideMe(DOM.oils_rpt_folder_table);
30                                 }
31                         )
32                 }
33         );
34         return true;
35 }
36
37 function oilsRtpInitFolders() {
38         oilsRptCurrentFolderManager = 
39                 new oilsRptFolderManager(DOM.oils_rpt_folder_tree_div);
40         oilsRptCurrentFolderManager.draw(SESSION);
41 }
42
43 function oilsCleanupReports() {
44         try {oilsRptDebugWindow.close();} catch(e) {}
45         DOM = null;
46         oilsRptObjectCache = null;
47         oilsRptObject.objectCache =  null;
48 }
49
50
51
52
53 /* ---------------------------------------------------------------------
54         Define the report object
55         --------------------------------------------------------------------- */
56 function oilsReport(templateObj, reportObj) {
57         this.def = {
58                 select  : [],
59                 from            : {},
60                 where           : [],
61                 having  : [],
62                 order_by : []
63         };
64
65         this.params     = {};
66         this.name       = "";
67         this.templateObject = templateObj;
68         this.reportObject = reportObj;
69
70         if( templateObj ) {
71                 this.def = JSON2js(templateObj.data());
72                 this.name = templateObj.name();
73         }
74
75         if( reportObj ) 
76                 this.params = JSON2js(reportObj.data());
77         if(!this.params) this.params = {};
78 }
79
80 oilsReport.prototype.toString = function() {
81         return formatJSON(js2JSON(this));
82 }
83
84 oilsReport.prototype.toHTMLString = function() {
85         return formatJSONHTML(js2JSON(this));
86 }
87
88 oilsReport.prototype.gatherParams = function() {
89         //if(oilsRptObjectKeys(this.params).length == 0) return;
90         _debug("we have params: " + js2JSON(this.params));
91
92         var params      = [];
93         this._gatherParams(params, this.def.where, 'where', 'condition');
94         this._gatherParams(params, this.def.having, 'having', 'condition');
95         return params;
96 }
97
98 oilsReport.prototype._gatherParams = function(params, arr, type, field) {
99         if(!arr) return;
100         for( var i = 0; i < arr.length; i++ ) {
101
102                 var obj = arr[i];
103                 node = obj[field];
104                 var key; 
105                 var op;
106
107                 /* add select transform support */
108
109                 if( typeof node == 'string' ) {
110                         key = node.match(/::.*/);
111                 } else {
112                         op = oilsRptObjectKeys(node)[0];
113                         key = (node[op] +'').match(/::.*/);
114                 }
115
116                 if(!key) continue;
117                 key = key[0].replace(/::/,'');
118                 _debug("key = "+key+", param = " + this.params[key]);
119
120                 params.push( { 
121                         key             : key,
122                         op                      : op,
123                         value           : this.params[key],
124                         column  : obj.column,
125                         type            : type, 
126                         relation : obj.relation,
127                         field           : field
128                 });
129         }
130 }
131
132
133
134