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