2 oilsRptSetSubClass('oilsRptWidget', 'oilsRptObject');
3 oilsRptWidget.OILS_RPT_TRANSFORM_WIDGET = 0;
4 oilsRptWidget.OILS_RPT_OPERATION_WIDGET = 1;
6 function oilsRptWidget(args) {
8 this.dest = elem('input',{type:'text'});
11 oilsRptWidget.prototype.initWidget = function(args) {
14 this.node = args.node;
15 this.type = args.type;
16 this.action = args.action;
17 this.column = args.column;
20 oilsRptWidget.prototype.getValue = function() {
21 return this.dest.value ;
24 oilsRptWidget.prototype.draw = function() {
25 appendClear(this.node, this.dest);
28 oilsRptSetSubClass('oilsRptMultiInputWidget', 'oilsRptWidget');
29 function oilsRptMultiInputWidget(args) {
30 this.initInputWidget(args);
33 oilsRptMultiInputWidget.prototype.initInputWidget = function(args) {
35 this.initWidget(args);
36 this.count = (args.count) ? args.count : 2;
38 for( var i = 0; i < this.count; i++ )
39 this.dest.push(elem('input',{type:'text',size:10}));
42 oilsRptMultiInputWidget.prototype.getValue = function() {
44 for( var i = 0; i < this.dest.length; i++ )
45 vals.push(this.dest[i].value);
49 oilsRptMultiInputWidget.prototype.draw = function() {
50 removeChildren(this.node);
51 for( var i = 0; i < this.dest.length; i++ ) {
53 this.node.appendChild(this.label[i]);
54 this.node.appendChild(this.dest[i]);
58 oilsRptMultiInputWidget.prototype.setLabels = function(labels) {
65 oilsRptSetSubClass('oilsRptMultiWidget', 'oilsRptWidget');
66 function oilsRptMultiWidget(args) {
67 this.initMultiWidget(args);
70 oilsRptMultiWidget.prototype.initMultiWidget = function(args) {
72 this.initWidget(args);
73 this.dest = elem('select',
74 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
78 this.addButton = elem('input',{type:'submit',value:"Add"})
79 this.addButton.onclick = this.getSourceCollector();
80 this.delButton = elem('input',{type:'submit',value:"Del"})
81 this.delButton.onclick = function(){obj.removeSelected()};
84 oilsRptMultiWidget.prototype.getValue = function() {
86 for( var i = 0; i < this.dest.options.length; i++ )
87 vals.push(this.dest.options[i].value);
91 oilsRptMultiWidget.prototype.removeSelected = function() {
92 oilsDelSelectedItems(this.dest);
95 oilsRptMultiWidget.prototype.addItem = function(name, val) {
96 for( var i = 0; i < this.dest.options.length; i++ ) {
97 if( this.dest.options[i].value == val )
100 insertSelectorVal(this.dest, -1, name, val);
103 oilsRptMultiWidget.prototype.setSource = function(src) {
107 oilsRptMultiWidget.prototype.drawMultiWidget = function() {
108 appendClear(this.node, this.source);
109 this.node.appendChild(elem('br'))
110 this.node.appendChild(this.addButton);
111 this.node.appendChild(this.delButton);
112 this.node.appendChild(elem('br'))
113 this.node.appendChild(this.dest);
116 oilsRptSetSubClass('oilsRptInputMultiWidget', 'oilsRptMultiWidget');
117 function oilsRptInputMultiWidget(args) {
118 this.initInputMultiWidget(args);
120 oilsRptInputMultiWidget.prototype.initInputMultiWidget = function(args) {
122 this.initMultiWidget(args);
123 this.setSource(elem('input',{type:'text'}));
126 oilsRptInputMultiWidget.prototype.draw = function() {
127 this.drawMultiWidget();
130 oilsRptInputMultiWidget.prototype.getSourceCollector = function() {
133 obj.addItem(obj.source.value, obj.source.value);
139 oilsRptSetSubClass('oilsRptSelectorMultiWidget', 'oilsRptMultiWidget');
140 function oilsRptSelectorMultiWidget(args) {
141 this.initSelectorMultiWidget(args);
143 oilsRptSelectorMultiWidget.prototype.initSelectorMultiWidget = function(args) {
145 this.initMultiWidget(args);
147 elem('select',{multiple:'multiple', 'class':'oils_rpt_small_info_selector'}));
150 oilsRptSelectorMultiWidget.prototype.getSourceCollector = function() {
153 for( var i = 0; i < obj.source.options.length; i++ ) {
154 if( obj.source.options[i].selected )
155 obj.addItem(obj.source.options[i].innerHTML,
156 obj.source.options[i].value);
162 /* ----------------------------------------------------------- */
165 oilsRptSetSubClass('oilsRptRemoteWidget', 'oilsRptSelectorMultiWidget');
166 function oilsRptRemoteWidget(args) {
167 this.initRemoteWidget(args);
169 oilsRptRemoteWidget.prototype.initRemoteWidget = function(args) {
171 this.initSelectorMultiWidget(args);
172 this.selector = args.selector;
175 oilsRptRemoteWidget.prototype.draw = function() {
180 oilsRptRemoteWidget.prototype.setFetch = function(func) {
188 /* --------------------------------------------------------------------- */
190 oilsRptSetSubClass('oilsRptOrgMultiSelect','oilsRptSelectorMultiWidget');
191 function oilsRptOrgMultiSelect(args) {
192 this.initSelectorMultiWidget(args);
194 oilsRptOrgMultiSelect.prototype.draw = function(org) {
195 if(!org) org = globalOrgTree;
196 var opt = insertSelectorVal( this.source, -1,
197 org.shortname(), org.id(), null, findOrgDepth(org) );
198 if( org.id() == oilsRptCurrentOrg )
200 if( org.children() ) {
201 for( var c = 0; c < org.children().length; c++ )
202 this.draw(org.children()[c]);
204 this.drawMultiWidget();
210 /* --------------------------------------------------------------------- */
212 function oilsRptRelDatePicker(args) {
213 this.node = args.node;
214 this.relative = args.relative;
215 this.div = DOM.oils_rpt_relative_date_picker.cloneNode(true);
218 oilsRptRelDatePicker.prototype.draw = function() {
219 this.node.appendChild(this.div);
223 oilsRptRelDatePicker.prototype.getValue = function() {
225 getSelectorVal($n(this.div, 'count')) +
226 getSelectorVal($n(this.div,'type'));
227 if( this.relative ) str = '-'+str;
231 /* --------------------------------------------------------------------- */
240 /* --------------------------------------------------------------------- */
241 /* --------------------------------------------------------------------- */
246 /* ---------------------------------------------------------------------
247 Represents a set of value, an inputWidget collects data and a
248 multi-select displays the data and allows the user to remove items
249 --------------------------------------------------------------------- */
250 function oilsRptSetWidget(args) {
251 this.node = args.node;
252 this.inputWidget = new args.inputWidget(args);
253 this.dest = elem('select',
254 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
257 oilsRptSetWidget.prototype.draw = function() {
259 this.addButton = elem('input',{type:'submit',value:"Add"})
260 this.delButton = elem('input',{type:'submit',value:"Del"})
263 this.addButton.onclick = function() {
264 obj.addDisplayItems(obj.inputWidget.getDisplayValue());
267 this.delButton.onclick = function(){obj.removeSelected()};
269 removeChildren(this.node);
270 this.inputWidget.draw();
271 this.node.appendChild(elem('br'))
272 this.node.appendChild(this.addButton);
273 this.node.appendChild(this.delButton);
274 this.node.appendChild(elem('br'))
275 this.node.appendChild(this.dest);
278 oilsRptSetWidget.prototype.addDisplayItems = function(list) {
279 if( list.constructor != Array ) list = [list];
280 for(var i = 0; i < list.length; i++) {
285 iterate(this.dest.options,
286 function(o){if(o.getAttribute('value') == item.value) {exists = true; return;}});
289 _debug('Inserting SetWidget values ' + js2JSON(item));
290 insertSelectorVal(this.dest, -1, item.label, this.objToStr(item.value));
294 oilsRptSetWidget.prototype.removeSelected = function() {
295 oilsDelSelectedItems(this.dest);
298 oilsRptSetWidget.prototype.getValue = function() {
301 iterate(this.dest, function(i){vals.push(obj.strToObj(i.getAttribute('value')))});
305 oilsRptSetWidget.prototype.objToStr = function(obj) {
306 if( typeof obj == 'string' ) return obj;
307 return ':'+obj.transform+':'+obj.params[0];
310 oilsRptSetWidget.prototype.strToObj = function(str) {
311 if( str.match(/^:.*/) ) {
312 var tform = str.replace(/^:(.*):.*/,'$1');
313 var param = str.replace(/^:.*:(.*)/,'$1');
314 return { transform : tform, params : [param] };
320 /* ---------------------------------------------------------------------
321 represents a widget that has start and end values. start and end
322 are gather from start/end widgets
323 --------------------------------------------------------------------- */
324 function oilsRptBetweenWidget(args) {
325 this.node = args.node;
326 this.startWidget = new args.startWidget(args);
327 this.endWidget = new args.endWidget(args);
329 oilsRptBetweenWidget.prototype.draw = function() {
330 removeChildren(this.node);
331 this.startWidget.draw();
332 this.node.appendChild(elem('hr'));
333 this.node.appendChild(elem('div',
334 {style:'text-align:center;width:100%;font-weight:bold'},' - And - '));
335 this.node.appendChild(elem('hr'));
336 this.endWidget.draw();
338 oilsRptBetweenWidget.prototype.getValue = function() {
340 this.startWidget.getValue(),
341 this.endWidget.getValue()
348 /* ---------------------------------------------------------------------
350 --------------------------------------------------------------------- */
353 /* ---------------------------------------------------------------------
354 Atomic text input widget
355 --------------------------------------------------------------------- */
356 function oilsRptTextWidget(args) {
357 this.node = args.node;
358 this.dest = elem('input',{type:'text',size:12});
360 oilsRptTextWidget.prototype.draw = function() {
361 this.node.appendChild(this.dest);
364 /* returns the "real" value for the widget */
365 oilsRptTextWidget.prototype.getValue = function() {
366 return this.dest.value;
369 /* returns the label and "real" value for the widget */
370 oilsRptTextWidget.prototype.getDisplayValue = function() {
371 return { label : this.getValue(), value : this.getValue() };
376 /* ---------------------------------------------------------------------
377 Atomic bool input widget
378 --------------------------------------------------------------------- */
379 function oilsRptBoolWidget(args) {
380 this.node = args.node;
381 this.selector = elem('select');
382 insertSelectorVal(this.selector, -1,'True','t');
383 insertSelectorVal(this.selector, -1,'False','f');
386 oilsRptBoolWidget.prototype.draw = function() {
387 this.node.appendChild(this.selector);
390 /* returns the "real" value for the widget */
391 oilsRptBoolWidget.prototype.getValue = function() {
392 return getSelectorVal(this.selector);
395 /* returns the label and "real" value for the widget */
396 oilsRptBoolWidget.prototype.getDisplayValue = function() {
397 var val = getSelectorVal(this.selector);
399 if (val == 'f') labal = 'False';
400 return { label : label, value : val };
406 /* ---------------------------------------------------------------------
407 Atomic calendar widget
408 --------------------------------------------------------------------- */
409 function oilsRptCalWidget(args) {
410 this.node = args.node;
411 this.calFormat = args.calFormat;
412 this.input = elem('input',{type:'text',size:12});
414 if( args.inputSize ) {
415 this.input.setAttribute('size',args.inputSize);
416 this.input.setAttribute('maxlength',args.inputSize);
420 oilsRptCalWidget.prototype.draw = function() {
421 this.button = DOM.generic_calendar_button.cloneNode(true);
422 this.button.id = oilsNextId();
423 this.input.id = oilsNextId();
425 this.node.appendChild(this.button);
426 this.node.appendChild(this.input);
427 unHideMe(this.button);
429 _debug('making calendar widget with format ' + this.calFormat);
432 inputField : this.input.id,
433 ifFormat : this.calFormat,
434 button : this.button.id,
440 oilsRptCalWidget.prototype.getValue = function() {
441 return this.input.value;
444 oilsRptCalWidget.prototype.getDisplayValue = function() {
445 return { label : this.getValue(), value : this.getValue() };
449 /* ---------------------------------------------------------------------
451 --------------------------------------------------------------------- */
452 function oilsRptOrgSelector(args) {
453 this.node = args.node;
454 this.selector = elem('select',
455 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
458 oilsRptOrgSelector.prototype.draw = function(org) {
459 if(!org) org = globalOrgTree;
460 var opt = insertSelectorVal( this.selector, -1,
461 org.shortname(), org.id(), null, findOrgDepth(org) );
462 if( org.id() == oilsRptCurrentOrg )
464 if( org.children() ) {
465 for( var c = 0; c < org.children().length; c++ )
466 this.draw(org.children()[c]);
468 this.node.appendChild(this.selector);
471 oilsRptOrgSelector.prototype.getValue = function() {
473 iterate(this.selector,
476 vals.push(o.getAttribute('value'))
482 oilsRptOrgSelector.prototype.getDisplayValue = function() {
484 iterate(this.selector,
487 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
494 /* ---------------------------------------------------------------------
496 --------------------------------------------------------------------- */
497 function oilsRptAgeWidget(args) {
498 this.node = args.node;
499 this.count = elem('select');
500 this.type = elem('select');
503 oilsRptAgeWidget.prototype.draw = function() {
504 for( var i = 1; i < 25; i++ )
505 insertSelectorVal(this.count, -1, i, i);
506 insertSelectorVal(this.type, -1, 'Day(s)', 'days');
507 insertSelectorVal(this.type, -1, 'Month(s)', 'months');
508 insertSelectorVal(this.type, -1, 'Year(s)', 'years');
509 this.node.appendChild(this.count);
510 this.node.appendChild(this.type);
513 oilsRptAgeWidget.prototype.getValue = function() {
514 var count = getSelectorVal(this.count);
515 var type = getSelectorVal(this.type);
516 return count+''+type;
519 oilsRptAgeWidget.prototype.getDisplayValue = function() {
520 var val = { value : this.getValue() };
521 var label = getSelectorVal(this.count) + ' ';
522 for( var i = 0; i < this.type.options.length; i++ ) {
523 var opt = this.type.options[i];
525 label += opt.innerHTML;
533 /* ---------------------------------------------------------------------
535 --------------------------------------------------------------------- */
536 function oilsRptNumberWidget(args) {
537 this.node = args.node;
538 this.size = args.size || 32;
539 this.start = args.start;
541 var len = new String(this.size).length;
542 _debug('length = ' + len);
543 this.input = elem('input',{type:'text',size: len});
545 this.selector = elem('select');
547 oilsRptNumberWidget.prototype.draw = function() {
548 for( var i = this.start; i < (this.size + this.start); i++ )
549 insertSelectorVal(this.selector, -1, i, i);
550 this.node.appendChild(this.selector);
551 //this.node.appendChild(this.input);
554 this.selector.onchange = function() {
555 obj.input.value = getSelectorVal(obj.selector);
557 this.input.value = getSelectorVal(this.selector);
561 oilsRptNumberWidget.prototype.getValue = function() {
562 //return this.input.value;
563 return getSelectorVal(this.selector);
566 oilsRptNumberWidget.prototype.getDisplayValue = function() {
567 return { label : this.getValue(), value : this.getValue() };
571 /* ---------------------------------------------------------------------
572 Relative dates widget
573 --------------------------------------------------------------------- */
574 function oilsRptTruncPicker(args) {
575 this.node = args.node;
576 this.type = args.type;
577 this.realSpan = elem('span');
578 this.relSpan = elem('span');
579 hideMe(this.relSpan);
580 args.node = this.realSpan;
581 this.calWidget = new oilsRptCalWidget(args);
582 args.node = this.node;
584 this.selector = elem('select');
585 insertSelectorVal(this.selector,-1,'Real Date',1);
586 insertSelectorVal(this.selector,-1,'Relative Date',2);
589 new oilsRptNumberWidget({node:this.relSpan,size:24,start:1});
591 this.label = 'Day(s)';
592 if(this.type == 'month') this.label = 'Month(s)';
593 if(this.type == 'quarter') this.label = 'Quarter(s)';
594 if(this.type == 'year') this.label = 'Year(s)';
595 if(this.type == 'date') this.label = 'Day(s)';
598 oilsRptTruncPicker.prototype.draw = function() {
599 this.node.appendChild(this.selector);
600 this.node.appendChild(this.realSpan);
601 this.node.appendChild(this.relSpan);
602 this.calWidget.draw();
603 this.numberPicker.draw();
604 this.relSpan.appendChild(text(this.label+' ago'));
607 this.selector.onchange = function() {
608 if( getSelectorVal(obj.selector) == 1 ) {
609 unHideMe(obj.realSpan);
612 unHideMe(obj.relSpan);
613 hideMe(obj.realSpan);
618 oilsRptTruncPicker.prototype.getValue = function() {
619 if( getSelectorVal(this.selector) == 2) {
620 var val = this.numberPicker.getValue();
621 var tform = 'relative_' + this.type;
622 return { transform : tform, params : ['-'+val] };
624 return this.calWidget.getValue();
627 oilsRptTruncPicker.prototype.getDisplayValue = function() {
628 if( getSelectorVal(this.selector) == 2) {
629 var num = this.numberPicker.getValue();
630 return { label : num +' '+this.label+' ago', value : this.getValue() };
632 return this.calWidget.getDisplayValue();
636 /* ---------------------------------------------------------------------
637 Atomic remote object picker
638 --------------------------------------------------------------------- */
640 function oilsRptRemoteWidget(args) {
641 this.node = args.node;
642 this.class = args.class;
643 this.field = args.field;
644 this.column = args.column;
645 this.source = elem('select',
646 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
649 oilsRptRemoteWidget.prototype.draw = function() {
651 iterate(oilsIDL[this.class].fields,
653 if(i.type == 'link' && i.class == 'aou')
658 if(orgcol) _debug("found org column for remote widget: " + orgcol);
661 iterate(oilsRptMyOrgs,function(i){orgs.push(i.id());});
662 var req = new Request(OILS_RPT_MAGIC_FETCH, SESSION, {
669 this.node.appendChild(this.source);
670 req.callback(function(r){obj.render(r.getResultObject())});
674 oilsRptRemoteWidget.prototype.render = function(objs) {
675 for( var i = 0; i < objs.length; i++ ) {
677 var label = obj[this.field.selector]();
678 var value = obj[this.column]();
679 _debug("inserted remote object "+label + ' : ' + value);
680 insertSelectorVal(this.source, -1, label, value);
684 oilsRptRemoteWidget.prototype.getDisplayValue = function() {
689 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
695 oilsRptRemoteWidget.prototype.getValue = function() {
700 vals.push(o.getAttribute('value'))
709 /* ---------------------------------------------------------------------
711 --------------------------------------------------------------------- */
713 /* ---------------------------------------------------------------------
714 custom my-orgs picker
715 --------------------------------------------------------------------- */
716 function oilsRptMyOrgsWidget(node, orgid, maxorg) {
717 _debug('fetching my orgs with max org of ' + maxorg);
720 this.maxorg = maxorg || 1;
723 this.node.disabled = true;
728 oilsRptMyOrgsWidget.prototype.draw = function() {
730 var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
733 function(r) { obj.drawWidget(r.getResultObject()); }
737 this.drawWidget(oilsRptMyOrgs);
741 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
744 oilsRptMyOrgs = orglist;
745 for( var i = 0; i < orglist.length; i++ ) {
746 var org = orglist[i];
747 var opt = insertSelectorVal( this.node, -1,
748 org.name(), org.id(), null, findOrgDepth(org) );
749 if( org.id() == this.orgid )
752 if( org.id() == this.maxorg )
754 else opt.disabled = true;
759 oilsRptMyOrgsWidget.prototype.getValue = function() {
760 return getSelectorVal(this.node);