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, hint) {
93 var parts = path.split(/-/);
95 for( var i = 0; i < parts.length; i++ ) {
96 if(i%2 == 0) { // IDL class names
98 str += oilsIDL[parts[i]].label;
99 } else { // Field names
101 name = name.replace(/>.*/,''); // field name may be appended with >join-type
102 var f = oilsRptFindField(oilsIDL[parts[i-1]], name);
103 str += " -> "+f.label;
108 str += '<br/><b><i>' + hint + '</i></b>'
117 function oilsRptResetParams() {
121 function nodeText(id) {
123 return $(id).innerHTML;
128 function oilsRptDebug() {
129 if(!oilsRptDebugEnabled) return;
131 _debug("\n-------------------------------------\n");
132 _debug(oilsRpt.toString());
133 _debug("\n-------------------------------------\n");
136 if(!oilsRptDebugWindow)
137 oilsRptDebugWindow = window.open('','Debug','resizable,width=700,height=500,scrollbars=1,chrome');
138 oilsRptDebugWindow.document.body.innerHTML = oilsRpt.toHTMLString();
143 function print_tabs_html(t) {
145 for (var j = 0; j < t; j++ ) { r = r + " "; }
149 function formatJSONHTML(s) {
150 var r = ''; var t = 0;
152 if (s[i] == '{' || s[i] == '[') {
153 r = r + s[i] + "<br/>" + print_tabs_html(++t);
154 } else if (s[i] == '}' || s[i] == ']') {
155 t--; r = r + "<br/>" + print_tabs_html(t) + s[i];
156 } else if (s[i] == ',') {
158 r = r + "<br/>" + print_tabs_html(t);
166 function setMousePos(e) {
169 oilsPageXMid = parseInt(window.innerHeight / 2);
170 oilsPageYMid = parseInt(window.innerWidth / 2);
173 function buildFloatingDiv(div, width) {
174 var left = parseInt((window.innerWidth / 2) - (width/2));
175 var halfh = parseInt(div.clientHeight / 2);
176 var top = oilsMouseY - halfh + 50;
177 var dbot = top + halfh;
178 if( dbot > window.innerHeight ) {
179 top = oilsMouseY - div.clientHeight - 10;
181 div.setAttribute('style', 'left:'+left+'px; top:'+top+'px; width:'+width+'px');
182 //div.setAttribute('style', 'top:'+top+'px;');
183 //alert(DOM.oils_rpt_filter_selector.style.top);
187 function mergeObjects( src, obj ) {
188 for( var i in obj ) {
189 if( typeof obj[i] == 'string' ) {
192 if(src[i]) mergeObjects(src[i], obj[i]);
193 else src[i] = obj[i];
199 /* scours the doc for elements with IDs. When it finds one,
200 it grabs the dom node and sets a reference to the node at DOM[id]; */
201 function oilsRptIdObjects(node) {
202 if(!node) node = document.documentElement;
203 if( node.nodeType != 1 ) return;
204 var id = node.getAttribute('id');
205 if( id ) eval("DOM."+id+"=$('"+id+"');");
206 var children = node.childNodes;
207 for( var c = 0; c < children.length; c++ )
208 oilsRptIdObjects(children[c]);
212 function oilsRptObjectKeys(obj) {
214 for( var i in obj ) k.push(i);
219 /* makes cls a subclass of parent */
220 function oilsRptSetSubClass(cls, parent) {
221 var str = cls+'.prototype = new '+parent+'();\n';
222 str += cls+'.prototype.constructor = '+cls+';\n';
223 str += cls+'.baseClass = '+parent+'.prototype.constructor;\n';
224 str += cls+'.prototype.super = '+parent+'.prototype;\n';
229 function oilsRptUpdateFolder(folder, type, callback) {
231 _debug("updating folder " + js2JSON(folder));
233 var req = new Request(OILS_RPT_UPDATE_FOLDER, SESSION, type, folder);
237 if( r.getResultObject() == 1 )
239 else callback(false);
249 function oilsRptCreateFolder(folder, type, callback) {
250 _debug("creating folder "+ js2JSON(folder));
251 var req = new Request(OILS_RPT_CREATE_FOLDER, SESSION, type, folder);
255 if( r.getResultObject() > 0 )
257 else callback(false);
267 function oilsRptUpdateTemplate(template, callback) {
268 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_TEMPLATE, template, callback);
271 function oilsRptUpdateReport(report, callback) {
272 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_REPORT, report, callback);
275 function oilsRptUpdateSchedule(schedule, callback) {
276 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_SCHEDULE, schedule, callback);
279 function oilsRptDoGenericUpdate( method, arg, callback ) {
280 _debug("generic update running: "+method);
281 var req = new Request(method, SESSION, arg);
284 if( r.getResultObject() > 0 )
286 else callback(false);
292 function oilsRptFetchReport(id, callback) {
293 var r = oilsRptGetCache('rr', id);
294 if(r) return callback(r);
295 var req = new Request(OILS_RPT_FETCH_REPORT, SESSION, id);
298 var rpt = res.getResultObject();
299 oilsRptCacheObject('rr', rpt, id);
306 function oilsRptFetchUser(id, callback) {
307 var r = oilsRptGetCache('au', id);
308 if(r) return callback(r);
309 var req = new Request(FETCH_FLESHED_USER, SESSION, id, []);
312 var user = res.getResultObject();
313 oilsRptCacheObject('au', user, id);
320 function oilsRptFetchTemplate(id, callback) {
321 var t = oilsRptGetCache('rt', id);
322 if(t) return callback(t);
323 var r = new Request(OILS_RPT_FETCH_TEMPLATE, SESSION, id);
326 var tmpl = res.getResultObject();
327 oilsRptCacheObject('rt', tmpl, id);
335 function oilsRptAlertSuccess() { alertId('oils_rpt_generic_success'); }
336 function oilsRptAlertFailure() { alertId('oils_rpt_generic_failure'); }
339 function oilsRptBuildOutputLink(tid, rid, sid) {
340 return OILS_IDL_OUTPUT_URL + tid+'/'+rid+'/'+sid+'/'+ OILS_IDL_OUTPUT_FILE;