]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_widget.js
more user param and widget work
[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 oilsRptSetSubClass('oilsRptMultiInputWidget', 'oilsRptWidget');
30 function oilsRptMultiInputWidget(args) {
31         this.initInputWidget(args);
32 }
33
34 oilsRptMultiInputWidget.prototype.initInputWidget = function(args) {
35         if(!args) return;
36         this.initWidget(args);
37         this.count = (args.count) ? args.count : 2;
38         this.dest = [];
39         for( var i = 0; i < this.count; i++ )
40                 this.dest.push(elem('input',{type:'text'}));
41 }
42
43 oilsRptMultiInputWidget.prototype.getValue = function() {
44         var vals = [];
45         for( var i = 0; i < this.dest.length; i++ )
46                 vals.push(this.dest.value);
47         return vals;
48 }
49
50 oilsRptMultiInputWidget.prototype.draw = function() {
51         removeChildren(this.node);
52         for( var i = 0; i < this.dest.length; i++ ) {
53                 this.node.appendChild(this.label[i]);
54                 this.node.appendChild(this.dest[i]);
55         }
56 }
57
58 oilsRptMultiInputWidget.prototype.setLabels = function(labels) {
59         this.labels = labels;   
60 }
61
62
63
64
65 /* ----------------------------------------------------------- */
66
67 oilsRptSetSubClass('oilsRptMultiWidget', 'oilsRptWidget');
68 function oilsRptMultiWidget(args) {
69         this.initMultiWidget(args);
70 }
71
72 oilsRptMultiWidget.prototype.initMultiWidget = function(args) {
73         if(!args) return;
74         this.initWidget(args);
75         this.dest = elem('select',
76                 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
77
78         var obj = this;
79
80         this.addButton = elem('input',{type:'submit',value:"Add"})
81         this.addButton.onclick = this.getSourceCollector();
82         this.delButton = elem('input',{type:'submit',value:"Del"})
83         this.delButton.onclick = function(){obj.removeSelected()};
84 }
85
86 oilsRptMultiWidget.prototype.getValue = function() {
87         var vals = [];
88         for( var i = 0; i < this.dest.options.length; i++ )
89                 vals.push(this.dest.options[i].value);
90         return vals;
91 }
92
93 oilsRptMultiWidget.prototype.removeSelected = function() {
94         oilsDelSelectedItems(this.dest);
95 }
96
97 oilsRptMultiWidget.prototype.addItem = function(name, val) {
98         for( var i = 0; i < this.dest.options.length; i++ ) {
99                 if( this.dest.options[i].value == val ) 
100                         return;
101         }
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 /*
133 oilsRptInputMultiWidget.prototype.addItem = function(name, val) {
134         //this.addItem(name, val);
135         this.source.value = "";
136         this.source.focus();
137 }
138 */
139
140 oilsRptInputMultiWidget.prototype.getSourceCollector = function() {
141         var obj = this;
142         return function() {
143                 obj.addItem(obj.source.value, obj.source.value);
144         }
145 }
146
147 /* ----------------------------------------------------------- */
148
149 oilsRptSetSubClass('oilsRptSelectorMultiWidget', 'oilsRptMultiWidget');
150 function oilsRptSelectorMultiWidget(args) {
151         this.initSelectorMultiWidget(args);
152 }
153 oilsRptSelectorMultiWidget.prototype.initSelectorMultiWidget = function(args) {
154         if(!args) return;
155         this.initMultiWidget(args);
156         this.setSource(
157                 elem('select',{multiple:'multiple', 'class':'oils_rpt_small_info_selector'}));
158 }
159
160 oilsRptSelectorMultiWidget.prototype.getSourceCollector = function() {
161         var obj = this;
162         return function() {
163                 for( var i = 0; i < obj.source.options.length; i++ ) {
164                         if( obj.source.options[i].selected )
165                                 obj.addItem(obj.source.options[i].innerHTML, 
166                                         obj.source.options[i].value);
167                 }
168         }
169 }
170
171 /* ----------------------------------------------------------- */
172
173 oilsRptSetSubClass('oilsRptRemoteWidget', 'oilsRptSelectorMultiWidget');
174 function oilsRptRemoteWidget(args) {
175         this.initRemoteWidget(args);
176 }
177 oilsRptRemoteWidget.prototype.initRemoteWidget = function(args) {
178         if(!args) return;
179         this.initSelectorMultiWidget(args);
180         this.selector = args.selector;
181 }
182
183 oilsRptRemoteWidget.prototype.draw = function() {
184         this.fetch();
185         //this.draw();
186 }
187
188 oilsRptRemoteWidget.prototype.setFetch = function(func) {
189         this.fetch = func;
190 }
191
192
193 /* --------------------------------------------------------------------- */
194
195 /* standalone org widget */
196 function oilsRptMyOrgsWidget(node, orgid) {
197         this.node = node;
198         this.orgid = orgid;
199 }
200
201 oilsRptMyOrgsWidget.prototype.draw = function() {
202         var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
203         var obj = this;
204         req.callback(
205                 function(r) { obj.drawWidget(r.getResultObject()); }
206         );
207         req.send();
208 }
209
210 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
211         var sel = this.node;
212         for( var i = 0; i < orglist.length; i++ ) {
213                 var org = orglist[i];
214                 var opt = insertSelectorVal( this.node, -1, 
215                         org.name(), org.id(), null, findOrgDepth(org) );
216                 if( org.id() == this.orgid )
217                         opt.selected = true;
218         }
219 }
220
221 oilsRptMyOrgsWidget.prototype.getValue = function() {
222         return getSelectorVal(this.node);
223 }
224
225 /* --------------------------------------------------------------------- */
226
227 oilsRptSetSubClass('oilsRptOrgMultiSelect','oilsRptSelectorMultiWidget');
228 function oilsRptOrgMultiSelect(args) {
229         this.initSelectorMultiWidget(args);
230 }
231
232 oilsRptOrgMultiSelect.prototype.draw = function(org) {
233         if(!org) org = globalOrgTree;
234         var opt = insertSelectorVal( this.source, -1, 
235                 org.shortname(), org.id(), null, findOrgDepth(org) );
236         if( org.id() == oilsRptCurrentOrg )
237                 opt.selected = true;
238         if( org.children() ) {
239                 for( var c = 0; c < org.children().length; c++ )
240                         this.draw(org.children()[c]);
241         }
242         this.drawMultiWidget();
243 }
244
245 /*
246 oilsRptOrgMultiSelectWidget.prototype.getSourceCollector = function() {
247         var obj = this;
248         return function() {
249                 for( var i = 0; i < obj.source.options.length; i++ )
250                         obj.addItem(obj.source.options.name, obj.source.options.value);
251         }
252 }
253 */
254
255 /*
256 oilsRptOrgMultiSelect.prototype.getValue = function() {
257         return getSelectedList(this.select);
258 }
259 */
260
261
262