]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt.js
LP#1332138 Report template / field docs repairs
[working/Evergreen.git] / Open-ILS / web / reports / oils_rpt.js
1 var perms = [ 'RUN_REPORTS', 'SHARE_REPORT_FOLDER', 'VIEW_REPORT_OUTPUT' ];
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         if( cgi.param('dbg') ) oilsRptDebugEnabled = true;
17
18         fetchHighestPermOrgs(SESSION, USER.id(), perms);
19         if( PERMS.RUN_REPORTS == -1 && PERMS.VIEW_REPORT_OUTPUT == -1 ) {
20                 unHideMe(DOM.oils_rpt_permission_denied);
21                 hideMe(DOM.oils_rpt_tree_loading);
22                 return false;
23         }
24
25
26     dojo.require('dojo.cookie');
27         oilsRptCurrentOrg = USER.ws_ou();
28         dojo.cookie(COOKIE_SES, SESSION, { 'path' : '/', 'secure' : true});
29         dojo.cookie('ws_ou', USER.ws_ou(), { 'path' : '/', 'secure' : true});
30
31         oilsRptFetchOrgTree(
32                 function() {
33                         oilsLoadRptTree(
34                                 function() {
35                                         hideMe(DOM.oils_rpt_tree_loading); 
36                                         unHideMe(DOM.oils_rpt_folder_table);
37                                 }
38                         )
39                 }
40         );
41         return true;
42 }
43
44 function oilsRtpInitFolders() {
45         oilsRptCurrentFolderManager = 
46                 new oilsRptFolderManager(DOM.oils_rpt_folder_tree_div);
47         oilsRptCurrentFolderManager.draw(SESSION);
48 }
49
50 function oilsCleanupReports() {
51         try {oilsRptDebugWindow.close();} catch(e) {}
52         DOM = null;
53         oilsRptObjectCache = null;
54         oilsRptObject.objectCache =  null;
55 }
56
57
58
59
60 /* ---------------------------------------------------------------------
61         Define the report object
62         --------------------------------------------------------------------- */
63 function oilsReport(templateObj, reportObj) {
64         this.def = {
65                 select  : [],
66                 from            : {},
67                 where           : [],
68                 having  : [],
69                 order_by : []
70         };
71
72         this.params     = {};
73         this.name       = "";
74         this.reportObject = reportObj;
75
76         if(templateObj) this.setTemplate(templateObj);
77
78         if( reportObj ) 
79                 this.params = JSON2js(reportObj.data());
80         if(!this.params) this.params = {};
81 }
82
83
84 oilsReport.prototype.setTemplate = function(template) {
85         this.def                = JSON2js(template.data());
86         this.name       = template.name();
87         this.templateObject = template;
88 }
89
90 oilsReport.prototype.toString = function() {
91         return formatJSON(js2JSON(this));
92 }
93
94 oilsReport.prototype.toHTMLString = function() {
95         return formatJSONHTML(js2JSON(this));
96 }
97
98 oilsReport.prototype.gatherParams = function() {
99         //if(oilsRptObjectKeys(this.params).length == 0) return;
100         _debug("we have params: " + js2JSON(this.params));
101
102         var params      = [];
103         this._gatherParams(params, this.def.where, 'where', 'condition');
104         this._gatherParams(params, this.def.having, 'having', 'condition');
105         return params;
106 }
107
108 oilsReport.prototype._gatherParams = function(params, arr, type, field) {
109         if(!arr) return;
110         for( var i = 0; i < arr.length; i++ ) {
111
112                 var obj = arr[i];
113                 node = obj[field];
114                 var key; 
115                 var op;
116
117                 /* add select transform support */
118
119                 if( typeof node == 'string' ) {
120                         key = node.match(/::.*/);
121                 } else {
122                         op = oilsRptObjectKeys(node)[0];
123                         key = (node[op] +'').match(/::.*/);
124                 }
125
126                 if(!key) continue;
127                 key = key[0].replace(/::/,'');
128                 _debug("key = "+key+", param = " + this.params[key]);
129
130                 params.push( { 
131                         key             : key,
132                         op                      : op,
133                         value           : this.params[key],
134                         column  : obj.column,
135                         path            : obj.path,
136                         type            : type, 
137                         relation : obj.relation,
138                         field           : field,
139             field_doc : obj.field_doc
140                 });
141         }
142 }
143
144
145
146 oilsReport.prototype.gatherTemplateParams = function() {
147     var arr = this.__gatherTemplateParams(this.def.where, 'where');
148     arr.concat(this.__gatherTemplateParams(this.def.having, 'having'));
149     _debug("template params: " + js2JSON(arr));
150     return arr;
151 }
152
153 oilsReport.prototype.__gatherTemplateParams = function(arr, type) {
154
155     if(!arr) return [];
156     var params = [];
157
158         for( var i = 0; i < arr.length; i++ ) {
159
160                 var obj = arr[i];
161                 var node = obj.condition;
162             var op = oilsRptObjectKeys(node)[0];
163                 var key = node[op];
164
165         /** if this is a dynamic param, skip it */
166         if( key && (key+'').match(/::.*/) ) continue;
167
168                 _debug("template params: op = " + op + ", value = " + js2JSON(key));
169
170                 params.push( { 
171                         key             : key, /* key == value, since this is not a dynamic param */
172                         op              : op,
173             value   : key,
174                         column  : obj.column,
175                         path    : obj.path,
176                         type    : type, 
177                         relation : obj.relation,
178                         field   : field
179                 });
180         }
181
182     return params;
183 }
184
185