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 )
250 if( org.children() ) {
251 for( var c = 0; c < org.children().length; c++ )
252 this.draw(org.children()[c]);
254 this.node.appendChild(this.selector);
257 oilsRptOrgSelector.prototype.getValue = function() {
259 iterate(this.selector, /* XXX this.selector.options?? */
262 vals.push(o.getAttribute('value'))
268 oilsRptOrgSelector.prototype.getDisplayValue = function() {
270 iterate(this.selector,
273 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
280 /* ---------------------------------------------------------------------
282 --------------------------------------------------------------------- */
283 function oilsRptAgeWidget(args) {
284 this.node = args.node;
285 this.count = elem('select');
286 this.type = elem('select');
289 oilsRptAgeWidget.prototype.draw = function() {
291 //insertSelectorVal(this.count, -1, ' -- Select One -- ', '');
292 for( var i = 1; i < 25; i++ )
293 insertSelectorVal(this.count, -1, i, i);
295 //insertSelectorVal(this.type, -1, ' -- Select One -- ', '');
296 insertSelectorVal(this.type, -1, 'Day(s)', 'days');
297 insertSelectorVal(this.type, -1, 'Month(s)', 'months');
298 insertSelectorVal(this.type, -1, 'Year(s)', 'years');
299 this.node.appendChild(this.count);
300 this.node.appendChild(this.type);
303 oilsRptAgeWidget.prototype.getValue = function() {
304 var count = getSelectorVal(this.count);
305 var type = getSelectorVal(this.type);
306 return count+''+type;
309 oilsRptAgeWidget.prototype.getDisplayValue = function() {
310 var val = { value : this.getValue() };
311 var label = getSelectorVal(this.count) + ' ';
312 for( var i = 0; i < this.type.options.length; i++ ) {
313 var opt = this.type.options[i];
315 label += opt.innerHTML;
323 /* ---------------------------------------------------------------------
325 --------------------------------------------------------------------- */
326 function oilsRptNumberWidget(args) {
327 this.node = args.node;
328 this.size = args.size || 32;
329 this.start = args.start;
330 this.selector = elem('select');
332 oilsRptNumberWidget.prototype.draw = function() {
333 //insertSelectorVal(this.selector, -1, ' -- Select One -- ', '');
334 for( var i = this.start; i < (this.size + this.start); i++ )
335 insertSelectorVal(this.selector, -1, i, i);
336 this.node.appendChild(this.selector);
340 oilsRptNumberWidget.prototype.getValue = function() {
341 return getSelectorVal(this.selector);
344 oilsRptNumberWidget.prototype.getDisplayValue = function() {
345 return { label : this.getValue(), value : this.getValue() };
349 /* ---------------------------------------------------------------------
350 Relative dates widget
351 --------------------------------------------------------------------- */
352 function oilsRptTruncPicker(args) {
353 this.node = args.node;
354 this.type = args.type;
355 this.realSpan = elem('span');
356 this.relSpan = elem('span');
357 hideMe(this.relSpan);
358 args.node = this.realSpan;
359 this.calWidget = new oilsRptCalWidget(args);
360 args.node = this.node;
362 this.selector = elem('select');
363 insertSelectorVal(this.selector,-1,'Real Date',1);
364 insertSelectorVal(this.selector,-1,'Relative Date',2);
367 new oilsRptNumberWidget({node:this.relSpan,size:24,start:1});
369 this.label = 'Day(s)';
370 if(this.type == 'month') this.label = 'Month(s)';
371 if(this.type == 'quarter') this.label = 'Quarter(s)';
372 if(this.type == 'year') this.label = 'Year(s)';
373 if(this.type == 'date') this.label = 'Day(s)';
376 oilsRptTruncPicker.prototype.draw = function() {
377 this.node.appendChild(this.selector);
378 this.node.appendChild(this.realSpan);
379 this.node.appendChild(this.relSpan);
380 this.calWidget.draw();
381 this.numberPicker.draw();
382 this.relSpan.appendChild(text(this.label+' ago'));
385 this.selector.onchange = function() {
386 if( getSelectorVal(obj.selector) == 1 ) {
387 unHideMe(obj.realSpan);
390 unHideMe(obj.relSpan);
391 hideMe(obj.realSpan);
396 oilsRptTruncPicker.prototype.getValue = function() {
397 if( getSelectorVal(this.selector) == 2) {
398 var val = this.numberPicker.getValue();
399 var tform = 'relative_' + this.type;
400 return { transform : tform, params : ['-'+val] };
402 return this.calWidget.getValue();
405 oilsRptTruncPicker.prototype.getDisplayValue = function() {
406 if( getSelectorVal(this.selector) == 2) {
407 var num = this.numberPicker.getValue();
408 return { label : num +' '+this.label+' ago', value : this.getValue() };
410 return this.calWidget.getDisplayValue();
414 /* ---------------------------------------------------------------------
415 Atomic remote object picker
416 --------------------------------------------------------------------- */
418 function oilsRptRemoteWidget(args) {
419 this.node = args.node;
420 this.class = args.class;
421 this.field = args.field;
422 this.column = args.column;
423 this.source = elem('select',
424 {multiple:'multiple','class':'oils_rpt_small_info_selector'});
427 oilsRptRemoteWidget.prototype.draw = function() {
429 iterate(oilsIDL[this.class].fields,
431 if(i.type == 'link' && i.class == 'aou')
436 if(orgcol) _debug("found org column for remote widget: " + orgcol);
439 iterate(oilsRptMyOrgs,function(i){orgs.push(i.id());});
440 var req = new Request(OILS_RPT_MAGIC_FETCH, SESSION, {
447 this.node.appendChild(this.source);
448 req.callback(function(r){obj.render(r.getResultObject())});
452 oilsRptRemoteWidget.prototype.render = function(objs) {
453 for( var i = 0; i < objs.length; i++ ) {
455 var label = obj[this.field.selector]();
456 var value = obj[this.column]();
457 _debug("inserted remote object "+label + ' : ' + value);
458 insertSelectorVal(this.source, -1, label, value);
462 oilsRptRemoteWidget.prototype.getDisplayValue = function() {
467 vals.push({ label : o.innerHTML, value : o.getAttribute('value')});
473 oilsRptRemoteWidget.prototype.getValue = function() {
478 vals.push(o.getAttribute('value'))
487 /* ---------------------------------------------------------------------
489 --------------------------------------------------------------------- */
491 /* ---------------------------------------------------------------------
492 custom my-orgs picker
493 --------------------------------------------------------------------- */
494 function oilsRptMyOrgsWidget(node, orgid, maxorg) {
495 _debug('fetching my orgs with max org of ' + maxorg);
498 this.maxorg = maxorg || 1;
501 this.node.disabled = true;
506 oilsRptMyOrgsWidget.prototype.draw = function() {
508 var req = new Request(OILS_RPT_FETCH_ORG_FULL_PATH, this.orgid);
511 function(r) { obj.drawWidget(r.getResultObject()); }
515 this.drawWidget(oilsRptMyOrgs);
519 oilsRptMyOrgsWidget.prototype.drawWidget = function(orglist) {
522 oilsRptMyOrgs = orglist;
523 for( var i = 0; i < orglist.length; i++ ) {
524 var org = orglist[i];
525 var opt = insertSelectorVal( this.node, -1,
526 org.name(), org.id(), null, findOrgDepth(org) );
527 if( org.id() == this.orgid )
530 if( org.id() == this.maxorg )
532 else opt.disabled = true;
537 oilsRptMyOrgsWidget.prototype.getValue = function() {
538 return getSelectorVal(this.node);