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.readonly = Boolean(args.readonly);
9 this.dest = elem('select',
10 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
11 this.dest.disabled = this.readonly;
14 oilsRptSetWidget.prototype.draw = function() {
16 this.addButton = elem('input',{type:'submit',value:"Add"})
17 this.delButton = elem('input',{type:'submit',value:"Del"})
18 this.addButton.disabled = this.readonly;
19 this.delButton.disabled = this.readonly;
22 this.addButton.onclick = function() {
23 obj.addDisplayItems(obj.inputWidget.getDisplayValue());
26 this.delButton.onclick = function(){obj.removeSelected()};
28 removeChildren(this.node);
29 this.inputWidget.draw();
30 this.node.appendChild(elem('br'))
31 this.node.appendChild(this.addButton);
32 this.node.appendChild(this.delButton);
33 this.node.appendChild(elem('br'))
34 this.node.appendChild(this.dest);
36 // propagate the values from the input widget into the our display.
37 if (this.inputWidget.seedValue)
38 this.addButton.onclick();
41 oilsRptSetWidget.prototype.addDisplayItems = function(list) {
42 if( list.constructor != Array ) list = [list];
43 for(var i = 0; i < list.length; i++) {
48 iterate(this.dest.options,
49 function(o){if(o.getAttribute('value') == item.value) {exists = true; return;}});
52 _debug('Inserting SetWidget values ' + js2JSON(item));
53 insertSelectorVal(this.dest, -1, item.label, this.objToStr(item.value));
57 oilsRptSetWidget.prototype.removeSelected = function() {
58 oilsDelSelectedItems(this.dest);
61 oilsRptSetWidget.prototype.getValue = function() {
64 iterate(this.dest, function(i){vals.push(obj.strToObj(i.getAttribute('value')))});
68 oilsRptSetWidget.prototype.objToStr = function(obj) {
69 if( typeof obj == 'string' ) return obj;
70 //return ':'+obj.transform+':'+obj.params[0];
71 var str = ':'+obj.transform;
72 for( var i = 0; i < obj.params.length; i++ )
73 str += ':' + obj.params[i];
74 _debug("objToStr(): built string " + str);
79 oilsRptSetWidget.prototype.strToObj = function(str) {
80 if( str.match(/^:.*/) ) {
81 var parts = str.split(/:/);
82 _debug("strToObj(): " + str + ' : ' + parts);
84 var tform = parts.shift();
85 //var tform = str.replace(/^:(.*):.*/,'$1');
86 //var param = str.replace(/^:.*:(.*)/,'$1');
87 return { transform : tform, params : parts };
93 /* ---------------------------------------------------------------------
94 represents a widget that has start and end values. start and end
95 are gathered from start/end widgets
96 --------------------------------------------------------------------- */
97 function oilsRptBetweenWidget(args) {
98 this.node = args.node;
99 var seedValue = args.value;
100 if (seedValue) args.value = seedValue[0];
101 this.startWidget = new args.startWidget(args);
102 if (seedValue) args.value = seedValue[1];
103 this.endWidget = new args.endWidget(args);
105 oilsRptBetweenWidget.prototype.draw = function() {
106 removeChildren(this.node);
107 this.startWidget.draw();
108 this.node.appendChild(elem('hr'));
109 this.node.appendChild(elem('div',
110 {style:'text-align:center;width:100%;font-weight:bold'},' - And - '));
111 this.node.appendChild(elem('hr'));
112 this.endWidget.draw();
114 oilsRptBetweenWidget.prototype.getValue = function() {
116 this.startWidget.getValue(),
117 this.endWidget.getValue()
124 /* ---------------------------------------------------------------------
126 --------------------------------------------------------------------- */
129 /* ---------------------------------------------------------------------
130 Atomic text input widget
131 --------------------------------------------------------------------- */
132 function oilsRptTextWidget(args) {
133 this.node = args.node;
134 this.seedValue = args.value;
135 this.dest = elem('input',{type:'text',size:12});
136 this.dest.disabled = Boolean(args.readonly);
137 oilsRptMonitorWidget(this.dest);
139 oilsRptTextWidget.prototype.draw = function() {
140 this.node.appendChild(this.dest);
141 if (this.seedValue) {
142 this.dest.value = this.seedValue;
143 this.dest.onchange(); // validation
147 /* returns the "real" value for the widget */
148 oilsRptTextWidget.prototype.getValue = function() {
149 return this.dest.value;
152 /* returns the label and "real" value for the widget */
153 oilsRptTextWidget.prototype.getDisplayValue = function() {
154 return { label : this.getValue(), value : this.getValue() };
159 /* ---------------------------------------------------------------------
160 Atomic bool input widget
161 --------------------------------------------------------------------- */
162 function oilsRptBoolWidget(args) {
163 this.node = args.node;
164 this.seedValue = args.value;
165 this.selector = elem('select');
166 insertSelectorVal(this.selector, -1,'True','t');
167 insertSelectorVal(this.selector, -1,'False','f');
168 this.selector.disabled = Boolean(args.readonly);
171 oilsRptBoolWidget.prototype.draw = function() {
172 this.node.appendChild(this.selector);
174 setSelector(this.selector, this.seedValue);
177 /* returns the "real" value for the widget */
178 oilsRptBoolWidget.prototype.getValue = function() {
179 return getSelectorVal(this.selector);
182 /* returns the label and "real" value for the widget */
183 oilsRptBoolWidget.prototype.getDisplayValue = function() {
184 var val = getSelectorVal(this.selector);
186 if (val == 'f') labal = 'False';
187 return { label : label, value : val };
191 /* If you monitor a text widget with this function, it
192 will style the input differently to indicate the
193 field needs data. If a regex is provided, it will
194 style the field differently until the data matches
195 the regex. The style comes from OILS_RPT_INVALID_DATA. */
196 function oilsRptMonitorWidget(input, regex) {
197 addCSSClass(input, OILS_RPT_INVALID_DATA);
198 var func = function() {
199 var val = input.value;
201 addCSSClass(input, OILS_RPT_INVALID_DATA);
204 if( val && val.match(regex) )
205 removeCSSClass(input, OILS_RPT_INVALID_DATA);
207 addCSSClass(input, OILS_RPT_INVALID_DATA);
209 removeCSSClass(input, OILS_RPT_INVALID_DATA);
214 input.onkeyup = func;
215 input.onchange = func;
221 /* ---------------------------------------------------------------------
222 Atomic calendar widget
223 --------------------------------------------------------------------- */
224 function oilsRptCalWidget(args) {
225 this.node = args.node;
226 this.calFormat = args.calFormat;
227 this.input = elem('input',{type:'text',size:12});
228 this.seedValue = args.value;
229 this.input.disabled = Boolean(args.readonly);
231 oilsRptMonitorWidget(this.input, args.regex);
233 if( args.inputSize ) {
234 this.input.setAttribute('size',args.inputSize);
235 this.input.setAttribute('maxlength',args.inputSize);
239 oilsRptCalWidget.prototype.draw = function() {
240 this.button = DOM.generic_calendar_button.cloneNode(true);
241 this.button.id = oilsNextId();
242 this.input.id = oilsNextId();
244 this.node.appendChild(this.button);
245 this.node.appendChild(this.input);
246 unHideMe(this.button);
248 _debug('making calendar widget with format ' + this.calFormat);
251 inputField : this.input.id,
252 ifFormat : this.calFormat,
253 button : this.button.id,
258 if (this.seedValue) {
259 this.input.value = this.seedValue;
260 this.input.onchange(); // validation
264 oilsRptCalWidget.prototype.getValue = function() {
265 return this.input.value;
268 oilsRptCalWidget.prototype.getDisplayValue = function() {
269 return { label : this.getValue(), value : this.getValue() };
273 /* ---------------------------------------------------------------------
275 --------------------------------------------------------------------- */
276 function oilsRptOrgSelector(args) {
277 this.node = args.node;
278 this.seedValue = args.value;
279 this.selector = elem('select',
280 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
281 this.selector.disabled = Boolean(args.readonly);
284 oilsRptOrgSelector.prototype.draw = function(org) {
285 if(!org) org = globalOrgTree;
286 var opt = insertSelectorVal( this.selector, -1,
287 org.shortname(), org.id(), null, findOrgDepth(org) );
288 if( org.id() == oilsRptCurrentOrg && !this.seedValue)
291 /* sometimes we need these choices
292 if( !isTrue(findOrgType(org.ou_type()).can_have_vols()) )
296 if( org.children() ) {
297 for( var c = 0; c < org.children().length; c++ )
298 this.draw(org.children()[c]);
300 this.node.appendChild(this.selector);
302 if (this.seedValue) {
303 if (dojo.isArray(this.seedValue)) {
304 for (var i = 0; i < this.selector.options.length; i++) {
305 var opt = this.selector.options[i];
306 if (this.seedValue.indexOf(opt.value) > -1)
310 setSelector(this.selector, this.seedValue);
315 oilsRptOrgSelector.prototype.getValue = function() {
317 iterate(this.selector, /* XXX this.selector.options?? */
320 vals.push(o.getAttribute('value'))
326 oilsRptOrgSelector.prototype.getDisplayValue = function() {
328 iterate(this.selector,
331 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
338 /* ---------------------------------------------------------------------
340 --------------------------------------------------------------------- */
341 function oilsRptAgeWidget(args) {
342 this.node = args.node;
343 this.seedValue = args.value;
344 this.count = elem('select');
345 this.type = elem('select');
346 this.count.disabled = Boolean(args.readonly);
347 this.type.disabled = Boolean(args.readonly);
350 oilsRptAgeWidget.prototype.draw = function() {
352 //insertSelectorVal(this.count, -1, ' -- Select One -- ', '');
353 for( var i = 1; i < 25; i++ )
354 insertSelectorVal(this.count, -1, i, i);
356 //insertSelectorVal(this.type, -1, ' -- Select One -- ', '');
357 insertSelectorVal(this.type, -1, rpt_strings.WIDGET_DAYS, 'days');
358 insertSelectorVal(this.type, -1, rpt_strings.WIDGET_MONTHS, 'months');
359 insertSelectorVal(this.type, -1, rpt_strings.WIDGET_YEARS, 'years');
360 this.node.appendChild(this.count);
361 this.node.appendChild(this.type);
363 if (this.seedValue) {
365 var count = this.seedValue.match(/(\d+)([^\d]+)/)[1];
366 var type = this.seedValue.match(/(\d+)([^\d]+)/)[2];
367 setSelector(this.count, count);
368 setSelector(this.type, type);
372 oilsRptAgeWidget.prototype.getValue = function() {
373 var count = getSelectorVal(this.count);
374 var type = getSelectorVal(this.type);
375 return count+''+type;
378 oilsRptAgeWidget.prototype.getDisplayValue = function() {
379 var val = { value : this.getValue() };
380 var label = getSelectorVal(this.count) + ' ';
381 for( var i = 0; i < this.type.options.length; i++ ) {
382 var opt = this.type.options[i];
384 label += opt.innerHTML;
392 /* ---------------------------------------------------------------------
393 Atomic substring picker
394 --------------------------------------------------------------------- */
395 function oilsRptSubstrWidget(args) {
396 this.node = args.node
397 this.seedValue = args.value;
398 this.data = elem('input',{type:'text',size:12})
399 this.offset = elem('input',{type:'text',size:5})
400 this.length = elem('input',{type:'text',size:5})
401 this.offset.disabled = Boolean(args.readonly);
402 this.length.disabled = Boolean(args.readonly);
405 oilsRptSubstrWidget.prototype.draw = function() {
406 this.node.appendChild(text('string: '))
407 this.node.appendChild(this.data);
408 this.node.appendChild(elem('br'));
409 this.node.appendChild(text('offset: '))
410 this.node.appendChild(this.offset);
411 this.node.appendChild(elem('br'));
412 this.node.appendChild(text('length: '))
413 this.node.appendChild(this.length);
415 if (this.seedValue) {
416 // TODO: unested; substring currently not supported.
417 this.data.value = this.seedValue[0];
418 this.offset.value = this.seedValue[1];
419 this.length.value = this.seedValue[2];
423 oilsRptSubstrWidget.prototype.getValue = function() {
425 transform : 'substring',
426 params : [ this.data.value, this.offset.value, this.length.value ]
430 oilsRptSubstrWidget.prototype.getDisplayValue = function() {
432 label : this.data.value + ' : ' + this.offset.value + ' : ' + this.length.value,
433 value : this.getValue()
438 /* ---------------------------------------------------------------------
440 --------------------------------------------------------------------- */
441 function oilsRptNumberWidget(args) {
442 this.node = args.node;
443 this.seedValue = args.value;
444 this.size = args.size || 32;
445 this.start = args.start;
446 this.selector = elem('select');
447 this.selector.disabled = Boolean(args.readonly);
449 oilsRptNumberWidget.prototype.draw = function() {
450 //insertSelectorVal(this.selector, -1, ' -- Select One -- ', '');
451 for( var i = this.start; i < (this.size + this.start); i++ )
452 insertSelectorVal(this.selector, -1, i, i);
453 this.node.appendChild(this.selector);
457 setSelector(this.selector, this.seedValue);
460 oilsRptNumberWidget.prototype.getValue = function() {
461 return getSelectorVal(this.selector);
464 oilsRptNumberWidget.prototype.getDisplayValue = function() {
465 return { label : this.getValue(), value : this.getValue() };
468 function oilsRptNullWidget(args) {
469 this.node = args.node;
470 this.type = args.type;
472 oilsRptNullWidget.prototype.draw = function() {}
473 oilsRptNullWidget.prototype.getValue = function() {
477 function oilsRptTemplateWidget(args) {
478 this.node = args.node;
479 this.value = args.value;
481 oilsRptTemplateWidget.prototype.draw = function() {
482 this.node.appendChild(text(''+this.value));
485 /* ---------------------------------------------------------------------
486 Relative dates widget
487 -------------------------------------------------------------------- */
488 function oilsRptTruncPicker(args) {
489 this.node = args.node;
490 this.type = args.type;
491 this.seedValue = args.value;
492 this.realSpan = elem('span');
493 this.relSpan = elem('span');
494 hideMe(this.relSpan);
495 args.node = this.realSpan;
496 this.calWidget = new oilsRptCalWidget(args);
497 args.node = this.node;
499 this.selector = elem('select');
500 insertSelectorVal(this.selector,-1,rpt_strings.WIDGET_REAL_DATE,1);
501 insertSelectorVal(this.selector,-1,rpt_strings.WIDGET_RELATIVE_DATE,2);
502 this.selector.disabled = Boolean(args.readonly);
505 new oilsRptNumberWidget(
506 {node:this.relSpan,size:90,start:1,readonly:args.readonly});
508 this.label = 'Day(s)';
509 if(this.type == 'month') this.label = rpt_strings.WIDGET_MONTHS;
510 if(this.type == 'quarter') this.label = rpt_strings.WIDGET_QUARTERS;
511 if(this.type == 'year') this.label = rpt_strings.WIDGET_YEARS;
512 if(this.type == 'date') this.label = rpt_strings.WIDGET_DAYS;
515 oilsRptTruncPicker.prototype.draw = function() {
516 this.node.appendChild(this.selector);
517 this.node.appendChild(this.realSpan);
518 this.node.appendChild(this.relSpan);
519 this.calWidget.draw();
520 this.numberPicker.draw();
521 this.relSpan.appendChild(text(this.label+' ago'));
524 this.selector.onchange = function() {
525 if( getSelectorVal(obj.selector) == 1 ) {
526 unHideMe(obj.realSpan);
529 unHideMe(obj.relSpan);
530 hideMe(obj.realSpan);
534 if (seed = this.seedValue) {
535 if (typeof seed == 'string') {
536 this.calWidget.value = seed;
538 // relative date transform
539 if (seed.transform.match(/relative/)) {
540 setSelector(this.selector, 2)
541 setSelector(this.numberPicker.selector,
542 Math.abs(seed.params[0]));
543 unHideMe(this.relSpan);
544 hideMe(this.realSpan);
550 oilsRptTruncPicker.prototype.getValue = function() {
551 if( getSelectorVal(this.selector) == 2) {
552 var val = this.numberPicker.getValue();
553 var tform = 'relative_' + this.type;
554 return { transform : tform, params : ['-'+val] };
556 return this.calWidget.getValue();
559 oilsRptTruncPicker.prototype.getDisplayValue = function() {
560 if( getSelectorVal(this.selector) == 2) {
561 var num = this.numberPicker.getValue();
562 return { label : num +' '+this.label+' ago', value : this.getValue() };
564 return this.calWidget.getDisplayValue();
568 /* ---------------------------------------------------------------------
569 Atomic remote object picker
570 --------------------------------------------------------------------- */
572 function oilsRptRemoteWidget(args) {
573 this.node = args.node;
574 this.class = args.class;
575 this.field = args.field;
576 this.column = args.column;
577 this.source = elem('select',
578 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
579 this.source.disabled = Boolean(args.readonly);
582 oilsRptRemoteWidget.prototype.draw = function() {
584 iterate(oilsIDL[this.class].fields,
586 if(i.type == 'link' && i.class == 'aou')
591 if(orgcol) _debug("found org column for remote widget: " + orgcol);
594 iterate(oilsRptMyOrgs,function(i){orgs.push(i.id());});
595 var req = new Request(OILS_RPT_MAGIC_FETCH, SESSION, {
602 this.node.appendChild(this.source);
603 req.callback(function(r){obj.render(r.getResultObject())});
607 oilsRptRemoteWidget.prototype.render = function(objs) {
608 var selector = this.field.selector;
611 if (a[selector]() > b[selector]())
616 for( var i = 0; i < objs.length; i++ ) {
618 var label = obj[this.field.selector]();
619 var value = obj[this.column]();
620 _debug("inserted remote object "+label + ' : ' + value);
621 insertSelectorVal(this.source, -1, label, value);
625 oilsRptRemoteWidget.prototype.getDisplayValue = function() {
630 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
636 oilsRptRemoteWidget.prototype.getValue = function() {
641 vals.push(o.getAttribute('value'))
650 /* ---------------------------------------------------------------------
652 --------------------------------------------------------------------- */
654 /* ---------------------------------------------------------------------
655 custom my-orgs picker
656 --------------------------------------------------------------------- */
657 function oilsRptMyOrgsWidget(node, orgid, maxorg) {
658 _debug('fetching my orgs with max org of ' + maxorg);
661 this.maxorg = maxorg || 1;
664 this.node.disabled = true;
669 oilsRptMyOrgsWidget.prototype.draw = function() {
671 var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
674 function(r) { obj.drawWidget(r.getResultObject()); }
678 this.drawWidget(oilsRptMyOrgs);
682 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
685 oilsRptMyOrgs = orglist;
686 for( var i = 0; i < orglist.length; i++ ) {
687 var org = orglist[i];
688 var opt = insertSelectorVal( this.node, -1,
689 org.name(), org.id(), null, findOrgDepth(org) );
690 if( org.id() == this.orgid )
693 if( org.id() == this.maxorg )
695 else opt.disabled = true;
700 oilsRptMyOrgsWidget.prototype.getValue = function() {
701 return getSelectorVal(this.node);