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