]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_utils.js
made the folder window more generic, showing contents via fm_table objects
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_utils.js
1 var oilsRptID = 0;
2 var oilsRptID2 = 0;
3 var oilsRptID3 = 0;
4 function oilsNextId() {
5         return 'oils_'+ (oilsRptID++);
6 }
7
8 function oilsNextNumericId() {
9         return oilsRptID3++;
10 }
11
12 function oilsRptNextParam() {
13         return '::PARAM'+ (oilsRptID2++);
14 }
15
16
17 function oilsRptCacheObject(obj) {
18         var id = oilsNextId();
19         oilsRptObjectCache[id] = obj;
20         return id;
21 }
22
23 function oilsRptFindObject(id) {
24         return oilsRptObjectCache[id];
25 }
26
27 function oilsRptCacheObject(type, obj, id) {
28         if( !oilsRptObjectCache[type] )
29                 oilsRptObjectCache[type] = {};
30         oilsRptObjectCache[type][id] = obj;
31 }
32
33 function oilsRptGetCache(type, id) {
34         if( !oilsRptObjectCache[type] )
35                 return null;
36         return oilsRptObjectCache[type][i];
37 }
38
39
40 /* -------------------------------------------- */
41 function oilsRptObject() {}
42 oilsRptObject.prototype.init = function() {
43         oilsRptObject.cache(this);
44 }
45 oilsRptObject.objectCache = {};
46 oilsRptObject.find = function(id) {
47         return oilsRptObject.objectCache[id];
48 }
49 oilsRptObject.cache = function(obj) {
50         obj.id = oilsNextNumericId();
51         oilsRptObject.objectCache[obj.id] = obj;
52         return obj.id;
53 }
54 /* -------------------------------------------- */
55
56
57 /* returns just the column name */
58 function oilsRptPathCol(path) {
59         var parts = path.split(/-/);
60         return parts.pop();
61 }
62
63 /* returns the IDL class of the selected column */
64 function oilsRptPathClass(path) {
65         var parts = path.split(/-/);
66         parts.pop();
67         return parts.pop();
68 }
69
70 /* returns everything prior to the column name */
71 function oilsRptPathRel(path) {
72         var parts = path.split(/-/);
73         parts.pop();
74         return parts.join('-');
75 }
76
77
78
79 function oilsRptResetParams() {
80         oilsRptID2 = 0;
81 }
82
83 function nodeText(id) {
84         if($(id))
85                 return $(id).innerHTML;
86         return "";
87 }
88
89 function print_tabs(t) {
90         var r = '';
91         for (var j = 0; j < t; j++ ) { r = r + "  "; }
92         return r;
93 }
94
95
96 function oilsRptDebug() {
97         _debug("\n-------------------------------------\n");
98         _debug(oilsRpt.toString());
99         _debug("\n-------------------------------------\n");
100         if(!oilsRptDebugEnabled) return;
101         if(!oilsRptDebugWindow)
102                 oilsRptDebugWindow = window.open('','Debug','resizable,width=700,height=500,scrollbars=1'); 
103
104         oilsRptDebugWindow.document.body.innerHTML = oilsRpt.toHTMLString();
105 }
106
107 /* pretty print JSON */
108 function formatJSON(s) {
109         var r = ''; var t = 0;
110         for (var i in s) {
111                 if (s[i] == '{' || s[i] == '[' ) {
112                         r = r + s[i] + "\n" + print_tabs(++t);
113                 } else if (s[i] == '}' || s[i] == ']') {
114                         t--; r = r + "\n" + print_tabs(t) + s[i];
115                 } else if (s[i] == ',') {
116                         r = r + s[i] + "\n" + print_tabs(t);
117                 } else {
118                         r = r + s[i];
119                 }
120         }
121         return r;
122 }
123
124
125 function print_tabs_html(t) {
126         var r = '';
127         for (var j = 0; j < t; j++ ) { r = r + "&nbsp;&nbsp;"; }
128         return r;
129 }
130
131 function formatJSONHTML(s) {
132         var r = ''; var t = 0;
133         for (var i in s) {
134                 if (s[i] == '{' || s[i] == '[') {
135                         r = r + s[i] + "<br/>" + print_tabs_html(++t);
136                 } else if (s[i] == '}' || s[i] == ']') {
137                         t--; r = r + "<br/>" + print_tabs_html(t) + s[i];
138                 } else if (s[i] == ',') {
139                         r = r + s[i];
140                         r = r + "<br/>" + print_tabs_html(t);
141                 } else {
142                         r = r + s[i];
143                 }
144         }
145         return r;
146 }
147
148 function setMousePos(e) {
149         oilsMouseX = e.pageX
150         oilsMouseY = e.pageY
151         oilsPageXMid = parseInt(window.innerHeight / 2);
152         oilsPageYMid = parseInt(window.innerWidth / 2);
153 }  
154
155 function buildFloatingDiv(div, width) {
156         var left = parseInt((window.innerWidth / 2) - (width/2));
157         var halfh = parseInt(div.clientHeight / 2);
158         var top = oilsMouseY - halfh + 50;
159         var dbot = top + halfh;
160         if( dbot > window.innerHeight ) {
161                 top = oilsMouseY - div.clientHeight - 10;
162         }
163         div.setAttribute('style', 'left:'+left+'px; top:'+top+'px; width:'+width+'px');
164 }
165
166
167 function mergeObjects( src, obj ) {
168         for( var i in obj ) {
169                 if( typeof obj[i] == 'string' ) {
170                         src[i] = obj[i];
171                 } else {
172                         if(src[i]) mergeObjects(src[i], obj[i]);
173                         else src[i] = obj[i];
174                 }
175         }
176 }
177
178
179 /* scours the doc for elements with IDs.  When it finds one,
180         it grabs the dom node and sets a reference to the node at DOM[id]; */
181 function oilsRptIdObjects(node) {
182         if(!node) node = document.documentElement;
183         if( node.nodeType != 1 ) return;
184         var id = node.getAttribute('id');
185         if( id ) eval("DOM."+id+"=$('"+id+"');");
186         var children = node.childNodes;
187         for( var c = 0; c < children.length; c++ ) 
188                 oilsRptIdObjects(children[c]);
189 }
190
191
192 function oilsRptObjectKeys(obj) {
193         var k = [];
194         for( var i in obj ) k.push(i);
195         return k;
196 }
197
198
199 /* makes cls a subclass of parent */
200 function oilsRptSetSubClass(cls, parent) {
201         var str = cls+'.prototype = new '+parent+'();\n';
202         str += cls+'.prototype.constructor = '+cls+';\n';
203         str += cls+'.baseClass = '+parent+'.prototype.constructor;\n';
204         str += cls+'.prototype.super = '+parent+'.prototype;\n';
205         eval(str);
206 }
207