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 calendar widget
378 --------------------------------------------------------------------- */
379 function oilsRptCalWidget(args) {
380 this.node = args.node;
381 this.calFormat = args.calFormat;
382 this.input = elem('input',{type:'text',size:12});
384 if( args.inputSize ) {
385 this.input.setAttribute('size',args.inputSize);
386 this.input.setAttribute('maxlength',args.inputSize);
390 oilsRptCalWidget.prototype.draw = function() {
391 this.button = DOM.generic_calendar_button.cloneNode(true);
392 this.button.id = oilsNextId();
393 this.input.id = oilsNextId();
395 this.node.appendChild(this.button);
396 this.node.appendChild(this.input);
397 unHideMe(this.button);
399 _debug('making calendar widget with format ' + this.calFormat);
402 inputField : this.input.id,
403 ifFormat : this.calFormat,
404 button : this.button.id,
410 oilsRptCalWidget.prototype.getValue = function() {
411 return this.input.value;
414 oilsRptCalWidget.prototype.getDisplayValue = function() {
415 return { label : this.getValue(), value : this.getValue() };
419 /* ---------------------------------------------------------------------
421 --------------------------------------------------------------------- */
422 function oilsRptOrgSelector(args) {
423 this.node = args.node;
424 this.selector = elem('select',
425 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
428 oilsRptOrgSelector.prototype.draw = function(org) {
429 if(!org) org = globalOrgTree;
430 var opt = insertSelectorVal( this.selector, -1,
431 org.shortname(), org.id(), null, findOrgDepth(org) );
432 if( org.id() == oilsRptCurrentOrg )
434 if( org.children() ) {
435 for( var c = 0; c < org.children().length; c++ )
436 this.draw(org.children()[c]);
438 this.node.appendChild(this.selector);
441 oilsRptOrgSelector.prototype.getValue = function() {
443 iterate(this.selector,
446 vals.push(o.getAttribute('value'))
452 oilsRptOrgSelector.prototype.getDisplayValue = function() {
454 iterate(this.selector,
457 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
464 /* ---------------------------------------------------------------------
466 --------------------------------------------------------------------- */
467 function oilsRptAgeWidget(args) {
468 this.node = args.node;
469 this.count = elem('select');
470 this.type = elem('select');
473 oilsRptAgeWidget.prototype.draw = function() {
474 for( var i = 1; i < 25; i++ )
475 insertSelectorVal(this.count, -1, i, i);
476 insertSelectorVal(this.type, -1, 'Day(s)', 'days');
477 insertSelectorVal(this.type, -1, 'Month(s)', 'months');
478 insertSelectorVal(this.type, -1, 'Year(s)', 'years');
479 this.node.appendChild(this.count);
480 this.node.appendChild(this.type);
483 oilsRptAgeWidget.prototype.getValue = function() {
484 var count = getSelectorVal(this.count);
485 var type = getSelectorVal(this.type);
486 return count+''+type;
489 oilsRptAgeWidget.prototype.getDisplayValue = function() {
490 var val = { value : this.getValue() };
491 var label = getSelectorVal(this.count) + ' ';
492 for( var i = 0; i < this.type.options.length; i++ ) {
493 var opt = this.type.options[i];
495 label += opt.innerHTML;
503 /* ---------------------------------------------------------------------
505 --------------------------------------------------------------------- */
506 function oilsRptNumberWidget(args) {
507 this.node = args.node;
508 this.size = args.size || 24;
509 this.start = args.start;
511 var len = new String(this.size).length;
512 _debug('length = ' + len);
513 this.input = elem('input',{type:'text',size: len});
515 this.selector = elem('select');
517 oilsRptNumberWidget.prototype.draw = function() {
518 for( var i = this.start; i < (this.size + this.start); i++ )
519 insertSelectorVal(this.selector, -1, i, i);
520 this.node.appendChild(this.selector);
521 //this.node.appendChild(this.input);
524 this.selector.onchange = function() {
525 obj.input.value = getSelectorVal(obj.selector);
527 this.input.value = getSelectorVal(this.selector);
531 oilsRptNumberWidget.prototype.getValue = function() {
532 //return this.input.value;
533 return getSelectorVal(this.selector);
536 oilsRptNumberWidget.prototype.getDisplayValue = function() {
537 return { label : this.getValue(), value : this.getValue() };
541 /* ---------------------------------------------------------------------
542 Relative dates widget
543 --------------------------------------------------------------------- */
544 function oilsRptTruncPicker(args) {
545 this.node = args.node;
546 this.type = args.type;
547 this.realSpan = elem('span');
548 this.relSpan = elem('span');
549 hideMe(this.relSpan);
550 args.node = this.realSpan;
551 this.calWidget = new oilsRptCalWidget(args);
552 args.node = this.node;
554 this.selector = elem('select');
555 insertSelectorVal(this.selector,-1,'Real Date',1);
556 insertSelectorVal(this.selector,-1,'Relative Date',2);
559 new oilsRptNumberWidget({node:this.relSpan,size:24,start:1});
561 this.label = 'Day(s)';
562 if(this.type == 'month') this.label = 'Month(s)';
563 if(this.type == 'quarter') this.label = 'Quarter(s)';
564 if(this.type == 'year') this.label = 'Year(s)';
567 oilsRptTruncPicker.prototype.draw = function() {
568 this.node.appendChild(this.selector);
569 this.node.appendChild(this.realSpan);
570 this.node.appendChild(this.relSpan);
571 this.calWidget.draw();
572 this.numberPicker.draw();
573 this.relSpan.appendChild(text(this.label+' ago'));
576 this.selector.onchange = function() {
577 if( getSelectorVal(obj.selector) == 1 ) {
578 unHideMe(obj.realSpan);
581 unHideMe(obj.relSpan);
582 hideMe(obj.realSpan);
587 oilsRptTruncPicker.prototype.getValue = function() {
588 if( getSelectorVal(this.selector) == 2) {
589 var val = this.numberPicker.getValue();
590 var tform = 'relative_' + this.type;
591 return { transform : tform, params : ['-'+val] };
593 return this.calWidget.getValue();
596 oilsRptTruncPicker.prototype.getDisplayValue = function() {
597 if( getSelectorVal(this.selector) == 2) {
598 var num = this.numberPicker.getValue();
599 return { label : num +' '+this.label+' ago', value : this.getValue() };
601 return this.calWidget.getDisplayValue();
605 /* ---------------------------------------------------------------------
606 Atomic remote object picker
607 --------------------------------------------------------------------- */
612 /* ---------------------------------------------------------------------
614 --------------------------------------------------------------------- */
616 /* ---------------------------------------------------------------------
617 custom my-orgs picker
618 --------------------------------------------------------------------- */
619 function oilsRptMyOrgsWidget(node, orgid, maxorg) {
620 _debug('fetching my orgs with max org of ' + maxorg);
623 this.maxorg = maxorg || 1;
626 this.node.disabled = true;
631 oilsRptMyOrgsWidget.prototype.draw = function() {
632 var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
635 function(r) { obj.drawWidget(r.getResultObject()); }
640 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
643 for( var i = 0; i < orglist.length; i++ ) {
644 var org = orglist[i];
645 var opt = insertSelectorVal( this.node, -1,
646 org.name(), org.id(), null, findOrgDepth(org) );
647 if( org.id() == this.orgid )
650 if( org.id() == this.maxorg )
652 else opt.disabled = true;
657 oilsRptMyOrgsWidget.prototype.getValue = function() {
658 return getSelectorVal(this.node);