refactoring widgets, round one
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Oct 2006 15:35:15 +0000 (15:35 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Oct 2006 15:35:15 +0000 (15:35 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6394 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/reports/oils_rpt_common.xhtml
Open-ILS/web/reports/oils_rpt_param_editor.js
Open-ILS/web/reports/oils_rpt_report_editor.js
Open-ILS/web/reports/oils_rpt_tforms.js
Open-ILS/web/reports/oils_rpt_widget.js

index 1c60da5..f3867fa 100644 (file)
        Action Failed
 </span>
 
+
+<button style='padding: 0px;' id='generic_calendar_button'>
+       <img src="/opac/common/js/jscalendar/img.gif"
+               style="cursor: pointer; border: 1px solid red; padding: 0px; margin: -3px;"
+               title="Date selector"
+               onmouseover="this.style.background='red';"
+               onmouseout="this.style.background=''" />
+</button>
+
index 48c42d6..72f5ab1 100644 (file)
@@ -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) {
index b937ca4..5309fff 100644 (file)
@@ -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 );
index 930192c..f92170d 100644 (file)
@@ -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 : {
index f56955e..f4d74ff 100644 (file)
@@ -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() };
 }