4 function oilsNextId() {
5 return 'oils_'+ (oilsRptID++);
8 function oilsNextNumericId() {
12 function oilsRptNextParam() {
13 return '::P'+ (oilsRptID2++);
16 function oilsRptFetchOrgTree(callback) {
17 var req = new Request(OILS_RPT_FETCH_ORG_TREE);
20 globalOrgTree = r.getResultObject();
21 if( callback ) callback();
29 function oilsRptCacheObject(obj) {
30 var id = oilsNextId();
31 oilsRptObjectCache[id] = obj;
35 function oilsRptFindObject(id) {
36 return oilsRptObjectCache[id];
40 function oilsRptCacheObject(type, obj, id) {
41 if( !oilsRptObjectCache[type] )
42 oilsRptObjectCache[type] = {};
43 oilsRptObjectCache[type][id] = obj;
46 function oilsRptGetCache(type, id) {
47 if( !oilsRptObjectCache[type] )
49 return oilsRptObjectCache[type][id];
53 /* -------------------------------------------- */
54 function oilsRptObject() {}
55 oilsRptObject.prototype.init = function(obj) {
57 oilsRptObject.cache(obj);
59 oilsRptObject.objectCache = {};
60 oilsRptObject.find = function(id) {
61 return oilsRptObject.objectCache[id];
63 oilsRptObject.cache = function(obj) {
64 obj.id = oilsNextNumericId();
65 oilsRptObject.objectCache[obj.id] = obj;
68 /* -------------------------------------------- */
71 /* returns just the column name */
72 function oilsRptPathCol(path) {
73 var parts = path.split(/-/);
77 /* returns the IDL class of the selected column */
78 function oilsRptPathClass(path) {
79 var parts = path.split(/-/);
84 /* returns everything prior to the column name */
85 function oilsRptPathRel(path) {
86 var parts = path.split(/-/);
88 return parts.join('-');
91 /* creates a label "path" based on the column path */
92 function oilsRptMakeLabel(path) {
93 if (!path) return path;
94 if (path.indexOf(' ') > -1) return path
96 var parts = path.split(/-/);
98 for( var i = 0; i < parts.length; i++ ) {
99 if(i%2 == 0) { // IDL class names
101 str += oilsIDL[parts[i]].label;
102 } else { // Field names
104 name = name.replace(/>.*/,''); // field name may be appended with >join-type
105 var f = oilsRptFindField(oilsIDL[parts[i-1]], name);
106 str += " -> "+f.label;
116 function oilsRptResetParams() {
120 function nodeText(id) {
122 return $(id).innerHTML;
127 function oilsRptDebug() {
128 if(!oilsRptDebugEnabled) return;
130 _debug("\n-------------------------------------\n");
131 _debug(oilsRpt.toString());
132 _debug("\n-------------------------------------\n");
135 if(!oilsRptDebugWindow)
136 oilsRptDebugWindow = window.open('','Debug','resizable,width=700,height=500,scrollbars=1,chrome');
137 oilsRptDebugWindow.document.body.innerHTML = oilsRpt.toHTMLString();
142 function print_tabs_html(t) {
144 for (var j = 0; j < t; j++ ) { r = r + " "; }
148 function formatJSONHTML(s) {
149 var r = ''; var t = 0;
151 if (s[i] == '{' || s[i] == '[') {
152 r = r + s[i] + "<br/>" + print_tabs_html(++t);
153 } else if (s[i] == '}' || s[i] == ']') {
154 t--; r = r + "<br/>" + print_tabs_html(t) + s[i];
155 } else if (s[i] == ',') {
157 r = r + "<br/>" + print_tabs_html(t);
165 function setMousePos(e) {
168 oilsPageXMid = parseInt(window.innerHeight / 2);
169 oilsPageYMid = parseInt(window.innerWidth / 2);
172 function buildFloatingDiv(div, width) {
173 var left = parseInt((window.innerWidth / 2) - (width/2));
174 var halfh = parseInt(div.clientHeight / 2);
175 var top = oilsMouseY - halfh + 50;
176 var dbot = top + halfh;
177 if( dbot > window.innerHeight ) {
178 top = oilsMouseY - div.clientHeight - 10;
180 div.setAttribute('style', 'left:'+left+'px; top:'+top+'px; width:'+width+'px');
181 //div.setAttribute('style', 'top:'+top+'px;');
182 //alert(DOM.oils_rpt_filter_selector.style.top);
186 function mergeObjects( src, obj ) {
187 for( var i in obj ) {
188 if( typeof obj[i] == 'string' ) {
191 if(src[i]) mergeObjects(src[i], obj[i]);
192 else src[i] = obj[i];
198 /* scours the doc for elements with IDs. When it finds one,
199 it grabs the dom node and sets a reference to the node at DOM[id]; */
200 function oilsRptIdObjects(node) {
201 if(!node) node = document.documentElement;
202 if( node.nodeType != 1 ) return;
203 var id = node.getAttribute('id');
204 /* Create node references only for IDs that are likely
205 valid function names. This avoids an issue where
206 the interface fails to load if the DOM contains
207 elements with a hyphen in their ID. For example,
208 a script element loaded by the BitWarden browser
209 plugin - see LP#2052567 */
210 if( id && id.match(/^[A-Za-z][0-9A-Za-z_]*$/) ) eval("DOM."+id+"=$('"+id+"');");
211 var children = node.childNodes;
212 for( var c = 0; c < children.length; c++ )
213 oilsRptIdObjects(children[c]);
217 function oilsRptObjectKeys(obj) {
219 for( var i in obj ) k.push(i);
224 /* makes cls a subclass of parent */
225 function oilsRptSetSubClass(cls, parent) {
226 var str = cls+'.prototype = new '+parent+'();\n';
227 str += cls+'.prototype.constructor = '+cls+';\n';
228 str += cls+'.baseClass = '+parent+'.prototype.constructor;\n';
229 str += cls+'.prototype.super = '+parent+'.prototype;\n';
234 function oilsRptUpdateFolder(folder, type, callback) {
236 _debug("updating folder " + js2JSON(folder));
238 var req = new Request(OILS_RPT_UPDATE_FOLDER, SESSION, type, folder);
242 if( r.getResultObject() == 1 )
244 else callback(false);
254 function oilsRptCreateFolder(folder, type, callback) {
255 _debug("creating folder "+ js2JSON(folder));
256 var req = new Request(OILS_RPT_CREATE_FOLDER, SESSION, type, folder);
260 if( r.getResultObject() > 0 )
262 else callback(false);
272 function oilsRptUpdateTemplate(template, callback) {
273 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_TEMPLATE, template, callback);
276 function oilsRptUpdateReport(report, callback) {
277 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_REPORT, report, callback);
280 function oilsRptUpdateSchedule(schedule, callback) {
281 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_SCHEDULE, schedule, callback);
284 function oilsRptDoGenericUpdate( method, arg, callback ) {
285 _debug("generic update running: "+method);
286 var req = new Request(method, SESSION, arg);
289 if( r.getResultObject() > 0 )
291 else callback(false);
297 function oilsRptFetchReport(id, callback) {
298 var r = oilsRptGetCache('rr', id);
299 if(r) return callback(r);
300 var req = new Request(OILS_RPT_FETCH_REPORT, SESSION, id);
303 var rpt = res.getResultObject();
304 oilsRptCacheObject('rr', rpt, id);
311 function oilsRptFetchUser(id, callback) {
312 var r = oilsRptGetCache('au', id);
313 if(r) return callback(r);
314 var req = new Request(FETCH_FLESHED_USER, SESSION, id, []);
317 var user = res.getResultObject();
318 oilsRptCacheObject('au', user, id);
325 function oilsRptFetchTemplate(id, callback) {
326 var t = oilsRptGetCache('rt', id);
327 if(t) return callback(t);
328 var r = new Request(OILS_RPT_FETCH_TEMPLATE, SESSION, id);
331 var tmpl = res.getResultObject();
332 oilsRptCacheObject('rt', tmpl, id);
339 function oilsRptAlertSuccess() { alertId('oils_rpt_generic_success'); }
340 function oilsRptAlertFailure() { alertId('oils_rpt_generic_failure'); }
343 function oilsRptBuildOutputLink(tid, rid, sid) {
344 return OILS_IDL_OUTPUT_URL + tid+'/'+rid+'/'+sid+'/'+ OILS_IDL_OUTPUT_FILE;