From: erickson Date: Thu, 5 Oct 2006 15:35:15 +0000 (+0000) Subject: refactoring widgets, round one X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bfe602609f7e37e85d86f507a727f39d5bebc305;p=evergreen%2Fpines.git refactoring widgets, round one git-svn-id: svn://svn.open-ils.org/ILS/trunk@6394 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/reports/oils_rpt_common.xhtml b/Open-ILS/web/reports/oils_rpt_common.xhtml index 1c60da5d24..f3867fa771 100644 --- a/Open-ILS/web/reports/oils_rpt_common.xhtml +++ b/Open-ILS/web/reports/oils_rpt_common.xhtml @@ -62,3 +62,12 @@ Action Failed + + + diff --git a/Open-ILS/web/reports/oils_rpt_param_editor.js b/Open-ILS/web/reports/oils_rpt_param_editor.js index 48c42d6102..72f5ab10e0 100644 --- a/Open-ILS/web/reports/oils_rpt_param_editor.js +++ b/Open-ILS/web/reports/oils_rpt_param_editor.js @@ -31,6 +31,7 @@ oilsRptParamEditor.prototype.draw = function() { for( var p = 0; p < params.length; p++ ) { var par = params[p]; var row = oilsRptParamEditor.row.cloneNode(true); + this.tbody.appendChild(row); $n(row, 'object').appendChild(text(oilsRptMakeLabel(oilsRptPathRel(par.path)))); $n(row, 'column').appendChild(text(par.column.colname)); $n(row, 'transform').appendChild(text(par.column.transform)); @@ -38,7 +39,6 @@ oilsRptParamEditor.prototype.draw = function() { par.widget = this.buildWidget(par, $n(row, 'widget')); par.widget.draw(); //this.buildRelWidget(par, row); - this.tbody.appendChild(row); } } @@ -80,14 +80,38 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) { _debug("building widget with param class:" + cls + ' col: '+param.column.colname + ' op: '+ param.op); + /* get the atomic widget from the datatype */ + var atomicWidget = oilsRptTextWidget; + var widgetArgs = {node:node}; + widgetArgs.calFormat = OILS_RPT_TRANSFORMS[transform].cal_format; + widgetArgs.inputSize = OILS_RPT_TRANSFORMS[transform].input_size; + switch(transform) { + case 'month_trunc': + case 'year_trunc': + case 'date': + atomicWidget = oilsRptCalWidget; + break; + } + switch(param.op) { + case 'in': + case 'not in': + widgetArgs.inputWidget = atomicWidget; + return new oilsRptSetWidget(widgetArgs); + case 'between': + case 'not between': + widgetArgs.startWidget = atomicWidget; + widgetArgs.endWidget = atomicWidget; + return new oilsRptBetweenWidget(widgetArgs); + default: + return new oilsRptAtomicWidget(widgetArgs); } + /* switch(param.op) { case 'in': case 'not in': - /* special case the org tree selector */ if( cls == 'aou' ) { return new oilsRptOrgMultiSelect({node:node}); } else { @@ -104,6 +128,7 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) { return new oilsRptWidget({node:node}); } } + */ } //oilsRptParamEditor.prototype.get = function(param, node) { diff --git a/Open-ILS/web/reports/oils_rpt_report_editor.js b/Open-ILS/web/reports/oils_rpt_report_editor.js index b937ca454e..5309fff7a2 100644 --- a/Open-ILS/web/reports/oils_rpt_report_editor.js +++ b/Open-ILS/web/reports/oils_rpt_report_editor.js @@ -122,7 +122,7 @@ oilsRptReportEditor.prototype.save = function() { debugFMObject(report); debugFMObject(schedule); - //return; + return; var obj = this; var req = new Request(OILS_RPT_CREATE_REPORT, SESSION, report, schedule ); diff --git a/Open-ILS/web/reports/oils_rpt_tforms.js b/Open-ILS/web/reports/oils_rpt_tforms.js index 930192caff..f92170de16 100644 --- a/Open-ILS/web/reports/oils_rpt_tforms.js +++ b/Open-ILS/web/reports/oils_rpt_tforms.js @@ -90,7 +90,8 @@ var OILS_RPT_TRANSFORMS = { label : 'Date', regex : /^\d{4}-\d{2}-\d{2}$/, hint : 'YYYY-MM-DD', - cal_format : '%Y-%m-%d' + cal_format : '%Y-%m-%d', + input_size : 10 }, month_trunc : { @@ -98,7 +99,8 @@ var OILS_RPT_TRANSFORMS = { label : 'Year + Month', regex : /^\d{4}-\d{2}$/, hint : 'YYYY-MM', - cal_format : '%Y-%m' + cal_format : '%Y-%m', + input_size : 7 }, year_trunc : { @@ -106,7 +108,8 @@ var OILS_RPT_TRANSFORMS = { label : 'Year', regex : /^\d{4}$/, hint : 'YYYY', - cal_format : '%Y' + cal_format : '%Y', + input_size : 4 }, day_name : { diff --git a/Open-ILS/web/reports/oils_rpt_widget.js b/Open-ILS/web/reports/oils_rpt_widget.js index f56955ec7a..f4d74ff749 100644 --- a/Open-ILS/web/reports/oils_rpt_widget.js +++ b/Open-ILS/web/reports/oils_rpt_widget.js @@ -274,53 +274,152 @@ oilsRptRelDatePicker.prototype.getValue = function() { - - /* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */ -function oilsRptAtomicWidget(args) { - this.node = args.node; - this.source = args.source; - this.dest = elem('input',{type:'text',size:12}); -} -oilsRptAtomicWidget.prototype.draw = function() { - if( this.source ) - appendClear(this.node, this.source); - appendClear(this.node, this.dest); -} -oilsRptAtomicWidget.prototype.getValue = function() { - return this.dest.value; -} -/* --------------------------------------------------------------------- */ -function oilsRptListWidget(args) { + + + +/* --------------------------------------------------------------------- + Represents a set of value, an inputWidget collects data and a + multi-select displays the data and allows the user to remove items + --------------------------------------------------------------------- */ +function oilsRptSetWidget(args) { this.node = args.node; - this.source = args.source; + this.inputWidget = new args.inputWidget(args); this.dest = elem('select', {multiple:'multiple','class':'oils_rpt_small_info_selector'}); } -oilsRptListWidget.prototype.draw = function() { - appendClear(this.source); - appendClear(this.dest); + +oilsRptSetWidget.prototype.draw = function() { + + this.addButton = elem('input',{type:'submit',value:"Add"}) + this.delButton = elem('input',{type:'submit',value:"Del"}) + + var obj = this; + this.addButton.onclick = function() { + obj.addDisplayItems(obj.inputWidget.getDisplayValue()); + } + + this.delButton.onclick = function(){obj.removeSelected()}; + + removeChildren(this.node); + this.inputWidget.draw(); + this.node.appendChild(elem('br')) + this.node.appendChild(this.addButton); + this.node.appendChild(this.delButton); + this.node.appendChild(elem('br')) + this.node.appendChild(this.dest); } -oilsRptListWidget.prototype.getValue = function() { - return getSelectedList(this.dest); + +oilsRptSetWidget.prototype.addDisplayItems = function(list) { + if( list.constructor != Array ) list = [list]; + for(var i = 0; i < list.length; i++) { + var item = list[i]; + + /* no dupes */ + var exists = false; + iterate(this.dest.options, + function(o){if(o.getAttribute('value') == item.value) {exists = true; return;}}); + if(exists) continue; + + _debug('Inserting SetWidget values ' + js2JSON(item)); + insertSelectorVal(this.dest, -1, item.label, item.value); + } } -/* --------------------------------------------------------------------- */ + +oilsRptSetWidget.prototype.removeSelected = function() { + oilsDelSelectedItems(this.dest); +} + +oilsRptSetWidget.prototype.getValue = function() { + return getSelectedSet(this.dest); +} + + +/* --------------------------------------------------------------------- + represents a widget that has start and end values. start and end + are gather from start/end widgets + --------------------------------------------------------------------- */ function oilsRptBetweenWidget(args) { this.node = args.node; - this.startSource = args.startSource; - this.endSource = args.endSource; - this.dest = elem('select', - {multiple:'multiple','class':'oils_rpt_small_info_selector'}); + this.startWidget = new args.startWidget(args); + this.endWidget = new args.endWidget(args); } oilsRptBetweenWidget.prototype.draw = function() { - appendClear(this.startSource); - appendClear(this.endSource); - appendClear(this.dest); + removeChildren(this.node); + this.startWidget.draw(); + this.endWidget.draw(); } oilsRptBetweenWidget.prototype.getValue = function() { - return getSelectedList(this.dest); + return [ + this.startWidget.getValue(), + this.endWidget.getValue() + ]; +} + + +/* --------------------------------------------------------------------- + the most basic text input widget + --------------------------------------------------------------------- */ +function oilsRptTextWidget(args) { + this.node = args.node; + this.dest = elem('input',{type:'text',size:12}); +} +oilsRptTextWidget.prototype.draw = function() { + this.node.appendChild(this.dest); +} + +/* returns the "real" value for the widget */ +oilsRptTextWidget.prototype.getValue = function() { + return this.dest.value; +} + +/* returns the label and "real" value for the widget */ +oilsRptTextWidget.prototype.getDisplayValue = function() { + return { label : this.getValue(), value : this.getValue() }; +} + + +/* --------------------------------------------------------------------- */ + +function oilsRptCalWidget(args) { + this.node = args.node; + this.calFormat = args.calFormat; + this.input = elem('input',{type:'text',size:12}); + + if( args.inputSize ) { + this.input.setAttribute('size',args.inputSize); + this.input.setAttribute('maxlength',args.inputSize); + } +} + +oilsRptCalWidget.prototype.draw = function() { + this.button = DOM.generic_calendar_button.cloneNode(true); + this.button.id = oilsNextId(); + this.input.id = oilsNextId(); + + this.node.appendChild(this.button); + this.node.appendChild(this.input); + unHideMe(this.button); + + _debug('making calendar widget with format ' + this.calFormat); + + Calendar.setup({ + inputField : this.input.id, + ifFormat : this.calFormat, + button : this.button.id, + align : "Tl", + singleClick : true + }); +} + +oilsRptCalWidget.prototype.getValue = function() { + return this.input.value; +} + +oilsRptCalWidget.prototype.getDisplayValue = function() { + return { label : this.getValue(), value : this.getValue() }; }