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