1 /* ---------------------------------------------------------------------
2 Represents a set of values, an inputWidget collects data and a
3 multi-select displays the data and allows the user to remove items
4 --------------------------------------------------------------------- */
5 function oilsRptSetWidget(args) {
7 this.inputWidget = new args.inputWidget(args);
8 this.dest = elem('select',
9 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
12 oilsRptSetWidget.prototype.draw = function() {
14 this.addButton = elem('input',{type:'submit',value:"Add"})
15 this.delButton = elem('input',{type:'submit',value:"Del"})
18 this.addButton.onclick = function() {
19 obj.addDisplayItems(obj.inputWidget.getDisplayValue());
22 this.delButton.onclick = function(){obj.removeSelected()};
24 removeChildren(this.node);
25 this.inputWidget.draw();
26 this.node.appendChild(elem('br'))
27 this.node.appendChild(this.addButton);
28 this.node.appendChild(this.delButton);
29 this.node.appendChild(elem('br'))
30 this.node.appendChild(this.dest);
33 oilsRptSetWidget.prototype.addDisplayItems = function(list) {
34 if( list.constructor != Array ) list = [list];
35 for(var i = 0; i < list.length; i++) {
40 iterate(this.dest.options,
41 function(o){if(o.getAttribute('value') == item.value) {exists = true; return;}});
44 _debug('Inserting SetWidget values ' + js2JSON(item));
45 insertSelectorVal(this.dest, -1, item.label, this.objToStr(item.value));
49 oilsRptSetWidget.prototype.removeSelected = function() {
50 oilsDelSelectedItems(this.dest);
53 oilsRptSetWidget.prototype.getValue = function() {
56 iterate(this.dest, function(i){vals.push(obj.strToObj(i.getAttribute('value')))});
60 oilsRptSetWidget.prototype.objToStr = function(obj) {
61 if( typeof obj == 'string' ) return obj;
62 return ':'+obj.transform+':'+obj.params[0];
65 oilsRptSetWidget.prototype.strToObj = function(str) {
66 if( str.match(/^:.*/) ) {
67 var tform = str.replace(/^:(.*):.*/,'$1');
68 var param = str.replace(/^:.*:(.*)/,'$1');
69 return { transform : tform, params : [param] };
75 /* ---------------------------------------------------------------------
76 represents a widget that has start and end values. start and end
77 are gathered from start/end widgets
78 --------------------------------------------------------------------- */
79 function oilsRptBetweenWidget(args) {
80 this.node = args.node;
81 this.startWidget = new args.startWidget(args);
82 this.endWidget = new args.endWidget(args);
84 oilsRptBetweenWidget.prototype.draw = function() {
85 removeChildren(this.node);
86 this.startWidget.draw();
87 this.node.appendChild(elem('hr'));
88 this.node.appendChild(elem('div',
89 {style:'text-align:center;width:100%;font-weight:bold'},' - And - '));
90 this.node.appendChild(elem('hr'));
91 this.endWidget.draw();
93 oilsRptBetweenWidget.prototype.getValue = function() {
95 this.startWidget.getValue(),
96 this.endWidget.getValue()
103 /* ---------------------------------------------------------------------
105 --------------------------------------------------------------------- */
108 /* ---------------------------------------------------------------------
109 Atomic text input widget
110 --------------------------------------------------------------------- */
111 function oilsRptTextWidget(args) {
112 this.node = args.node;
113 this.dest = elem('input',{type:'text',size:12});
114 oilsRptMonitorWidget(this.dest);
116 oilsRptTextWidget.prototype.draw = function() {
117 this.node.appendChild(this.dest);
120 /* returns the "real" value for the widget */
121 oilsRptTextWidget.prototype.getValue = function() {
122 return this.dest.value;
125 /* returns the label and "real" value for the widget */
126 oilsRptTextWidget.prototype.getDisplayValue = function() {
127 return { label : this.getValue(), value : this.getValue() };
132 /* ---------------------------------------------------------------------
133 Atomic bool input widget
134 --------------------------------------------------------------------- */
135 function oilsRptBoolWidget(args) {
136 this.node = args.node;
137 this.selector = elem('select');
138 insertSelectorVal(this.selector, -1,'True','t');
139 insertSelectorVal(this.selector, -1,'False','f');
142 oilsRptBoolWidget.prototype.draw = function() {
143 this.node.appendChild(this.selector);
146 /* returns the "real" value for the widget */
147 oilsRptBoolWidget.prototype.getValue = function() {
148 return getSelectorVal(this.selector);
151 /* returns the label and "real" value for the widget */
152 oilsRptBoolWidget.prototype.getDisplayValue = function() {
153 var val = getSelectorVal(this.selector);
155 if (val == 'f') labal = 'False';
156 return { label : label, value : val };
160 /* If you monitor a text widget with this function, it
161 will style the input differently to indicate the
162 field needs data. If a regex is provided, it will
163 style the field differently until the data matches
164 the regex. The style comes from OILS_RPT_INVALID_DATA. */
165 function oilsRptMonitorWidget(input, regex) {
166 addCSSClass(input, OILS_RPT_INVALID_DATA);
167 var func = function() {
168 var val = input.value;
170 addCSSClass(input, OILS_RPT_INVALID_DATA);
173 if( val && val.match(regex) )
174 removeCSSClass(input, OILS_RPT_INVALID_DATA);
176 addCSSClass(input, OILS_RPT_INVALID_DATA);
178 removeCSSClass(input, OILS_RPT_INVALID_DATA);
183 input.onkeyup = func;
184 input.onchange = func;
190 /* ---------------------------------------------------------------------
191 Atomic calendar widget
192 --------------------------------------------------------------------- */
193 function oilsRptCalWidget(args) {
194 this.node = args.node;
195 this.calFormat = args.calFormat;
196 this.input = elem('input',{type:'text',size:12});
198 oilsRptMonitorWidget(this.input, args.regex);
200 if( args.inputSize ) {
201 this.input.setAttribute('size',args.inputSize);
202 this.input.setAttribute('maxlength',args.inputSize);
206 oilsRptCalWidget.prototype.draw = function() {
207 this.button = DOM.generic_calendar_button.cloneNode(true);
208 this.button.id = oilsNextId();
209 this.input.id = oilsNextId();
211 this.node.appendChild(this.button);
212 this.node.appendChild(this.input);
213 unHideMe(this.button);
215 _debug('making calendar widget with format ' + this.calFormat);
218 inputField : this.input.id,
219 ifFormat : this.calFormat,
220 button : this.button.id,
226 oilsRptCalWidget.prototype.getValue = function() {
227 return this.input.value;
230 oilsRptCalWidget.prototype.getDisplayValue = function() {
231 return { label : this.getValue(), value : this.getValue() };
235 /* ---------------------------------------------------------------------
237 --------------------------------------------------------------------- */
238 function oilsRptOrgSelector(args) {
239 this.node = args.node;
240 this.selector = elem('select',
241 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
244 oilsRptOrgSelector.prototype.draw = function(org) {
245 if(!org) org = globalOrgTree;
246 var opt = insertSelectorVal( this.selector, -1,
247 org.shortname(), org.id(), null, findOrgDepth(org) );
248 if( org.id() == oilsRptCurrentOrg )
251 /* sometimes we need these choices
252 if( !isTrue(findOrgType(org.ou_type()).can_have_vols()) )
256 if( org.children() ) {
257 for( var c = 0; c < org.children().length; c++ )
258 this.draw(org.children()[c]);
260 this.node.appendChild(this.selector);
263 oilsRptOrgSelector.prototype.getValue = function() {
265 iterate(this.selector, /* XXX this.selector.options?? */
268 vals.push(o.getAttribute('value'))
274 oilsRptOrgSelector.prototype.getDisplayValue = function() {
276 iterate(this.selector,
279 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
286 /* ---------------------------------------------------------------------
288 --------------------------------------------------------------------- */
289 function oilsRptAgeWidget(args) {
290 this.node = args.node;
291 this.count = elem('select');
292 this.type = elem('select');
295 oilsRptAgeWidget.prototype.draw = function() {
297 //insertSelectorVal(this.count, -1, ' -- Select One -- ', '');
298 for( var i = 1; i < 25; i++ )
299 insertSelectorVal(this.count, -1, i, i);
301 //insertSelectorVal(this.type, -1, ' -- Select One -- ', '');
302 insertSelectorVal(this.type, -1, 'Day(s)', 'days');
303 insertSelectorVal(this.type, -1, 'Month(s)', 'months');
304 insertSelectorVal(this.type, -1, 'Year(s)', 'years');
305 this.node.appendChild(this.count);
306 this.node.appendChild(this.type);
309 oilsRptAgeWidget.prototype.getValue = function() {
310 var count = getSelectorVal(this.count);
311 var type = getSelectorVal(this.type);
312 return count+''+type;
315 oilsRptAgeWidget.prototype.getDisplayValue = function() {
316 var val = { value : this.getValue() };
317 var label = getSelectorVal(this.count) + ' ';
318 for( var i = 0; i < this.type.options.length; i++ ) {
319 var opt = this.type.options[i];
321 label += opt.innerHTML;
329 /* ---------------------------------------------------------------------
331 --------------------------------------------------------------------- */
332 function oilsRptNumberWidget(args) {
333 this.node = args.node;
334 this.size = args.size || 32;
335 this.start = args.start;
336 this.selector = elem('select');
338 oilsRptNumberWidget.prototype.draw = function() {
339 //insertSelectorVal(this.selector, -1, ' -- Select One -- ', '');
340 for( var i = this.start; i < (this.size + this.start); i++ )
341 insertSelectorVal(this.selector, -1, i, i);
342 this.node.appendChild(this.selector);
346 oilsRptNumberWidget.prototype.getValue = function() {
347 return getSelectorVal(this.selector);
350 oilsRptNumberWidget.prototype.getDisplayValue = function() {
351 return { label : this.getValue(), value : this.getValue() };
355 /* ---------------------------------------------------------------------
356 Relative dates widget
357 --------------------------------------------------------------------- */
358 function oilsRptTruncPicker(args) {
359 this.node = args.node;
360 this.type = args.type;
361 this.realSpan = elem('span');
362 this.relSpan = elem('span');
363 hideMe(this.relSpan);
364 args.node = this.realSpan;
365 this.calWidget = new oilsRptCalWidget(args);
366 args.node = this.node;
368 this.selector = elem('select');
369 insertSelectorVal(this.selector,-1,'Real Date',1);
370 insertSelectorVal(this.selector,-1,'Relative Date',2);
373 new oilsRptNumberWidget({node:this.relSpan,size:90,start:1});
375 this.label = 'Day(s)';
376 if(this.type == 'month') this.label = 'Month(s)';
377 if(this.type == 'quarter') this.label = 'Quarter(s)';
378 if(this.type == 'year') this.label = 'Year(s)';
379 if(this.type == 'date') this.label = 'Day(s)';
382 oilsRptTruncPicker.prototype.draw = function() {
383 this.node.appendChild(this.selector);
384 this.node.appendChild(this.realSpan);
385 this.node.appendChild(this.relSpan);
386 this.calWidget.draw();
387 this.numberPicker.draw();
388 this.relSpan.appendChild(text(this.label+' ago'));
391 this.selector.onchange = function() {
392 if( getSelectorVal(obj.selector) == 1 ) {
393 unHideMe(obj.realSpan);
396 unHideMe(obj.relSpan);
397 hideMe(obj.realSpan);
402 oilsRptTruncPicker.prototype.getValue = function() {
403 if( getSelectorVal(this.selector) == 2) {
404 var val = this.numberPicker.getValue();
405 var tform = 'relative_' + this.type;
406 return { transform : tform, params : ['-'+val] };
408 return this.calWidget.getValue();
411 oilsRptTruncPicker.prototype.getDisplayValue = function() {
412 if( getSelectorVal(this.selector) == 2) {
413 var num = this.numberPicker.getValue();
414 return { label : num +' '+this.label+' ago', value : this.getValue() };
416 return this.calWidget.getDisplayValue();
420 /* ---------------------------------------------------------------------
421 Atomic remote object picker
422 --------------------------------------------------------------------- */
424 function oilsRptRemoteWidget(args) {
425 this.node = args.node;
426 this.class = args.class;
427 this.field = args.field;
428 this.column = args.column;
429 this.source = elem('select',
430 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
433 oilsRptRemoteWidget.prototype.draw = function() {
435 iterate(oilsIDL[this.class].fields,
437 if(i.type == 'link' && i.class == 'aou')
442 if(orgcol) _debug("found org column for remote widget: " + orgcol);
445 iterate(oilsRptMyOrgs,function(i){orgs.push(i.id());});
446 var req = new Request(OILS_RPT_MAGIC_FETCH, SESSION, {
453 this.node.appendChild(this.source);
454 req.callback(function(r){obj.render(r.getResultObject())});
458 oilsRptRemoteWidget.prototype.render = function(objs) {
459 for( var i = 0; i < objs.length; i++ ) {
461 var label = obj[this.field.selector]();
462 var value = obj[this.column]();
463 _debug("inserted remote object "+label + ' : ' + value);
464 insertSelectorVal(this.source, -1, label, value);
468 oilsRptRemoteWidget.prototype.getDisplayValue = function() {
473 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
479 oilsRptRemoteWidget.prototype.getValue = function() {
484 vals.push(o.getAttribute('value'))
493 /* ---------------------------------------------------------------------
495 --------------------------------------------------------------------- */
497 /* ---------------------------------------------------------------------
498 custom my-orgs picker
499 --------------------------------------------------------------------- */
500 function oilsRptMyOrgsWidget(node, orgid, maxorg) {
501 _debug('fetching my orgs with max org of ' + maxorg);
504 this.maxorg = maxorg || 1;
507 this.node.disabled = true;
512 oilsRptMyOrgsWidget.prototype.draw = function() {
514 var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
517 function(r) { obj.drawWidget(r.getResultObject()); }
521 this.drawWidget(oilsRptMyOrgs);
525 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
528 oilsRptMyOrgs = orglist;
529 for( var i = 0; i < orglist.length; i++ ) {
530 var org = orglist[i];
531 var opt = insertSelectorVal( this.node, -1,
532 org.name(), org.id(), null, findOrgDepth(org) );
533 if( org.id() == this.orgid )
536 if( org.id() == this.maxorg )
538 else opt.disabled = true;
543 oilsRptMyOrgsWidget.prototype.getValue = function() {
544 return getSelectorVal(this.node);