]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_widget.js
added report description creation at run-time and so much more
[working/Evergreen.git] / Open-ILS / web / reports / oils_rpt_widget.js
1 oilsRptSetSubClass('oilsRptWidget', 'oilsRptObject');
2 oilsRptWidget.OILS_RPT_TRANSFORM_WIDGET = 0;
3 oilsRptWidget.OILS_RPT_OPERATION_WIDGET = 1;
4
5 function oilsRptWidget(args) {
6         this.initWidget(args);
7         this.dest = elem('input',{type:'text'});
8 }
9
10 oilsRptWidget.prototype.initWidget = function(args) {
11         if(!args) return;
12         this.init();
13         this.node       = args.node;
14         this.type       = args.type;
15         this.action = args.action;
16         this.column     = args.column;
17 }
18
19 oilsRptWidget.prototype.getValue = function() {
20         return this.dest.value;
21 }
22
23 oilsRptWidget.prototype.draw = function() {
24         appendClear(this.node, this.dest);
25 }
26
27 /* ----------------------------------------------------------- */
28
29 /* multiple input boxes */
30 oilsRptSetSubClass('oilsRptMultiInputWidget', 'oilsRptWidget');
31 function oilsRptMultiInputWidget(args) {
32         this.initInputWidget(args);
33 }
34
35 oilsRptMultiInputWidget.prototype.initInputWidget = function(args) {
36         if(!args) return;
37         this.initWidget(args);
38         this.count = (args.count) ? args.count : 2;
39         this.dest = [];
40         for( var i = 0; i < this.count; i++ )
41                 this.dest.push(elem('input',{type:'text'}));
42 }
43
44 oilsRptMultiInputWidget.prototype.getValue = function() {
45         var vals = [];
46         for( var i = 0; i < this.dest.length; i++ )
47                 vals.push(this.dest.value);
48         return vals;
49 }
50
51 oilsRptMultiInputWidget.prototype.draw = function() {
52         removeChildren(this.node);
53         for( var i = 0; i < this.dest.length; i++ ) {
54                 this.node.appendChild(this.label[i]);
55                 this.node.appendChild(this.dest[i]);
56         }
57 }
58
59 oilsRptMultiInputWidget.prototype.setLabels = function(labels) {
60         this.labels = labels;   
61 }
62
63
64
65
66 /* ----------------------------------------------------------- */
67
68 oilsRptSetSubClass('oilsRptMultiWidget', 'oilsRptWidget');
69 function oilsRptMultiWidget(args) {
70         this.initMultiWidget(args);
71 }
72
73 oilsRptMultiWidget.prototype.initMultiWidget = function(args) {
74         if(!args) return;
75         this.initWidget(args);
76         this.dest = elem('select',
77                 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
78
79         var obj = this;
80
81         this.addButton = elem('input',{type:'submit',value:"Add"})
82         this.addButton.onclick = this.getSourceCollector();
83         this.delButton = elem('input',{type:'submit',value:"Del"})
84         this.delButton.onclick = function(){obj.removeSelected()};
85 }
86
87 oilsRptMultiWidget.prototype.getValue = function() {
88         var vals = [];
89         for( var i = 0; i < this.dest.options.length; i++ )
90                 vals.push(this.dest.options[i].value);
91         return vals;
92 }
93
94 oilsRptMultiWidget.prototype.removeSelected = function() {
95         oilsDelSelectedItems(this.dest);
96 }
97
98 oilsRptMultiWidget.prototype.addItem = function(name, val) {
99         for( var i = 0; i < this.dest.options.length; i++ ) {
100                 if( this.dest.options[i].value == val ) 
101                         return;
102         }
103         insertSelectorVal(this.dest, -1, name, val);
104 }
105
106 oilsRptMultiWidget.prototype.setSource = function(src) {
107         this.source = src;
108 }
109
110 oilsRptMultiWidget.prototype.drawMultiWidget = function() {
111         appendClear(this.node, this.source);
112         this.node.appendChild(elem('br'))
113         this.node.appendChild(this.addButton);
114         this.node.appendChild(this.delButton);
115         this.node.appendChild(elem('br'))
116         this.node.appendChild(this.dest);
117 }
118
119
120 /* ----------------------------------------------------------- */
121
122 oilsRptSetSubClass('oilsRptInputMultiWidget', 'oilsRptMultiWidget');
123 function oilsRptInputMultiWidget(args) {
124         this.initInputMultiWidget(args);
125 }
126 oilsRptInputMultiWidget.prototype.initInputMultiWidget = function(args) {
127         if(!args) return;
128         this.initMultiWidget(args);
129         this.setSource(elem('input',{type:'text'}));
130 }
131
132 oilsRptInputMultiWidget.prototype.draw = function() {
133         this.drawMultiWidget();
134 }
135
136 oilsRptInputMultiWidget.prototype.getSourceCollector = function() {
137         var obj = this;
138         return function() {
139                 obj.addItem(obj.source.value, obj.source.value);
140         }
141 }
142
143
144 /* ----------------------------------------------------------- */
145
146 oilsRptSetSubClass('oilsRptSelectorMultiWidget', 'oilsRptMultiWidget');
147 function oilsRptSelectorMultiWidget(args) {
148         this.initSelectorMultiWidget(args);
149 }
150 oilsRptSelectorMultiWidget.prototype.initSelectorMultiWidget = function(args) {
151         if(!args) return;
152         this.initMultiWidget(args);
153         this.setSource(
154                 elem('select',{multiple:'multiple', 'class':'oils_rpt_small_info_selector'}));
155 }
156
157 oilsRptSelectorMultiWidget.prototype.getSourceCollector = function() {
158         var obj = this;
159         return function() {
160                 for( var i = 0; i < obj.source.options.length; i++ ) {
161                         if( obj.source.options[i].selected )
162                                 obj.addItem(obj.source.options[i].innerHTML, 
163                                         obj.source.options[i].value);
164                 }
165         }
166 }
167
168 /* ----------------------------------------------------------- */
169
170 oilsRptSetSubClass('oilsRptRemoteWidget', 'oilsRptSelectorMultiWidget');
171 function oilsRptRemoteWidget(args) {
172         this.initRemoteWidget(args);
173 }
174 oilsRptRemoteWidget.prototype.initRemoteWidget = function(args) {
175         if(!args) return;
176         this.initSelectorMultiWidget(args);
177         this.selector = args.selector;
178 }
179
180 oilsRptRemoteWidget.prototype.draw = function() {
181         this.fetch();
182         //this.draw();
183 }
184
185 oilsRptRemoteWidget.prototype.setFetch = function(func) {
186         this.fetch = func;
187 }
188
189
190 /* --------------------------------------------------------------------- */
191
192 /* standalone org widget */
193 function oilsRptMyOrgsWidget(node, orgid) {
194         this.node = node;
195         this.orgid = orgid;
196 }
197
198 oilsRptMyOrgsWidget.prototype.draw = function() {
199         var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
200         var obj = this;
201         req.callback(
202                 function(r) { obj.drawWidget(r.getResultObject()); }
203         );
204         req.send();
205 }
206
207 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
208         var sel = this.node;
209         for( var i = 0; i < orglist.length; i++ ) {
210                 var org = orglist[i];
211                 var opt = insertSelectorVal( this.node, -1, 
212                         org.name(), org.id(), null, findOrgDepth(org) );
213                 if( org.id() == this.orgid )
214                         opt.selected = true;
215         }
216 }
217
218 oilsRptMyOrgsWidget.prototype.getValue = function() {
219         return getSelectorVal(this.node);
220 }
221
222 /* --------------------------------------------------------------------- */
223
224 oilsRptSetSubClass('oilsRptOrgMultiSelect','oilsRptSelectorMultiWidget');
225 function oilsRptOrgMultiSelect(args) {
226         this.initSelectorMultiWidget(args);
227 }
228
229 oilsRptOrgMultiSelect.prototype.draw = function(org) {
230         if(!org) org = globalOrgTree;
231         var opt = insertSelectorVal( this.source, -1, 
232                 org.shortname(), org.id(), null, findOrgDepth(org) );
233         if( org.id() == oilsRptCurrentOrg )
234                 opt.selected = true;
235         if( org.children() ) {
236                 for( var c = 0; c < org.children().length; c++ )
237                         this.draw(org.children()[c]);
238         }
239         this.drawMultiWidget();
240 }
241
242
243
244
245