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 var parts = path.split(/-/);
95 for( var i = 0; i < parts.length; i++ ) {
98 str += oilsIDL[parts[i]].label;
100 var f = oilsRptFindField(oilsIDL[parts[i-1]], parts[i]);
110 function oilsRptResetParams() {
114 function nodeText(id) {
116 return $(id).innerHTML;
121 function oilsRptDebug() {
122 if(!oilsRptDebugEnabled) return;
124 _debug("\n-------------------------------------\n");
125 _debug(oilsRpt.toString());
126 _debug("\n-------------------------------------\n");
129 if(!oilsRptDebugWindow)
130 oilsRptDebugWindow = window.open('','Debug','resizable,width=700,height=500,scrollbars=1');
131 oilsRptDebugWindow.document.body.innerHTML = oilsRpt.toHTMLString();
136 function print_tabs_html(t) {
138 for (var j = 0; j < t; j++ ) { r = r + " "; }
142 function formatJSONHTML(s) {
143 var r = ''; var t = 0;
145 if (s[i] == '{' || s[i] == '[') {
146 r = r + s[i] + "<br/>" + print_tabs_html(++t);
147 } else if (s[i] == '}' || s[i] == ']') {
148 t--; r = r + "<br/>" + print_tabs_html(t) + s[i];
149 } else if (s[i] == ',') {
151 r = r + "<br/>" + print_tabs_html(t);
159 function setMousePos(e) {
162 oilsPageXMid = parseInt(window.innerHeight / 2);
163 oilsPageYMid = parseInt(window.innerWidth / 2);
166 function buildFloatingDiv(div, width) {
167 var left = parseInt((window.innerWidth / 2) - (width/2));
168 var halfh = parseInt(div.clientHeight / 2);
169 var top = oilsMouseY - halfh + 50;
170 var dbot = top + halfh;
171 if( dbot > window.innerHeight ) {
172 top = oilsMouseY - div.clientHeight - 10;
174 div.setAttribute('style', 'left:'+left+'px; top:'+top+'px; width:'+width+'px');
175 //div.setAttribute('style', 'top:'+top+'px;');
176 //alert(DOM.oils_rpt_filter_selector.style.top);
180 function mergeObjects( src, obj ) {
181 for( var i in obj ) {
182 if( typeof obj[i] == 'string' ) {
185 if(src[i]) mergeObjects(src[i], obj[i]);
186 else src[i] = obj[i];
192 /* scours the doc for elements with IDs. When it finds one,
193 it grabs the dom node and sets a reference to the node at DOM[id]; */
194 function oilsRptIdObjects(node) {
195 if(!node) node = document.documentElement;
196 if( node.nodeType != 1 ) return;
197 var id = node.getAttribute('id');
198 if( id ) eval("DOM."+id+"=$('"+id+"');");
199 var children = node.childNodes;
200 for( var c = 0; c < children.length; c++ )
201 oilsRptIdObjects(children[c]);
205 function oilsRptObjectKeys(obj) {
207 for( var i in obj ) k.push(i);
212 /* makes cls a subclass of parent */
213 function oilsRptSetSubClass(cls, parent) {
214 var str = cls+'.prototype = new '+parent+'();\n';
215 str += cls+'.prototype.constructor = '+cls+';\n';
216 str += cls+'.baseClass = '+parent+'.prototype.constructor;\n';
217 str += cls+'.prototype.super = '+parent+'.prototype;\n';
222 function oilsRptUpdateFolder(folder, type, callback) {
224 _debug("updating folder " + js2JSON(folder));
226 var req = new Request(OILS_RPT_UPDATE_FOLDER, SESSION, type, folder);
230 if( r.getResultObject() == 1 )
232 else callback(false);
242 function oilsRptCreateFolder(folder, type, callback) {
243 _debug("creating folder "+ js2JSON(folder));
244 var req = new Request(OILS_RPT_CREATE_FOLDER, SESSION, type, folder);
248 if( r.getResultObject() > 0 )
250 else callback(false);
260 function oilsRptUpdateTemplate(template, callback) {
261 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_TEMPLATE, template, callback);
264 function oilsRptUpdateReport(report, callback) {
265 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_REPORT, report, callback);
268 function oilsRptUpdateSchedule(schedule, callback) {
269 oilsRptDoGenericUpdate(OILS_RPT_UPDATE_SCHEDULE, schedule, callback);
272 function oilsRptDoGenericUpdate( method, arg, callback ) {
273 _debug("generic update running: "+method);
274 var req = new Request(method, SESSION, arg);
277 if( r.getResultObject() > 0 )
279 else callback(false);
285 function oilsRptFetchReport(id, callback) {
286 var r = oilsRptGetCache('rr', id);
287 if(r) return callback(r);
288 var req = new Request(OILS_RPT_FETCH_REPORT, SESSION, id);
291 var rpt = res.getResultObject();
292 oilsRptCacheObject('rr', rpt, id);
299 function oilsRptFetchUser(id, callback) {
300 var r = oilsRptGetCache('au', id);
301 if(r) return callback(r);
302 var req = new Request(FETCH_FLESHED_USER, SESSION, id, []);
305 var user = res.getResultObject();
306 oilsRptCacheObject('au', user, id);
313 function oilsRptFetchTemplate(id, callback) {
314 var t = oilsRptGetCache('rt', id);
315 if(t) return callback(t);
316 var r = new Request(OILS_RPT_FETCH_TEMPLATE, SESSION, id);
319 var tmpl = res.getResultObject();
320 oilsRptCacheObject('rt', tmpl, id);
328 function oilsRptAlertSuccess() { alertId('oils_rpt_generic_success'); }
329 function oilsRptAlertFailure() { alertId('oils_rpt_generic_failure'); }
332 function oilsRptBuildOutputLink(tid, rid, sid) {
333 return OILS_IDL_OUTPUT_URL + tid+'/'+rid+'/'+sid+'/'+ OILS_IDL_OUTPUT_FILE;