more widget work, relative times working, needs more testing
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Oct 2006 20:55:55 +0000 (20:55 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Oct 2006 20:55:55 +0000 (20:55 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6397 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index f075669..6691099 100644 (file)
@@ -45,7 +45,6 @@ function oilsReportBuilderSave() {
        debugFMObject(tmpl);
        //return; /* XXX */
 
-
        var req = new Request(OILS_RPT_CREATE_TEMPLATE, SESSION, tmpl);
        req.callback(
                function(r) {
@@ -53,7 +52,7 @@ function oilsReportBuilderSave() {
                        if( res && res != '0' ) {
                                oilsRptAlertSuccess();
                                _l('oils_rpt.xhtml');
-                       }
+                       } 
                }
        );
        
index f3867fa..c8dab07 100644 (file)
@@ -63,7 +63,7 @@
 </span>
 
 
-<button style='padding: 0px;' id='generic_calendar_button'>
+<button style='padding: 0px;' id='generic_calendar_button' class='hide_me'>
        <img src="/opac/common/js/jscalendar/img.gif"
                style="cursor: pointer; border: 1px solid red; padding: 0px; margin: -3px;"
                title="Date selector"
index 8992bb8..9bf69d8 100644 (file)
@@ -32,10 +32,9 @@ oilsRptParamEditor.prototype.draw = function() {
                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));
-               $n(row, 'action').appendChild(text(par.op));
+               $n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path)));
+               $n(row, 'transform').appendChild(text(OILS_RPT_TRANSFORMS[par.column.transform].label));
+               $n(row, 'action').appendChild(text(OILS_RPT_FILTERS[par.op].label));
                par.widget = this.buildWidget(par, $n(row, 'widget'));
                par.widget.draw();
                //this.buildRelWidget(par, row);
@@ -84,8 +83,17 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) {
 
        switch(transform) {
                case 'hour_trunc':
+                       widgetArgs.type = 'hour';
+                       atomicWidget = oilsRptTruncPicker;
+                       break;
                case 'month_trunc':
+                       widgetArgs.type = 'month';
+                       atomicWidget = oilsRptTruncPicker;
+                       break;
                case 'year_trunc':
+                       widgetArgs.type = 'year';
+                       atomicWidget = oilsRptTruncPicker;
+                       break;
                case 'date':
                        atomicWidget = oilsRptCalWidget;
                        break;
@@ -114,7 +122,7 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) {
                        break;
                case 'dow':
                        widgetArgs.size = 7;
-                       widgetArgs.start = 1;
+                       widgetArgs.start = 0;
                        atomicWidget = oilsRptNumberWidget
                        break;
                case 'dom':
@@ -166,7 +174,7 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) {
                        widgetArgs.endWidget = atomicWidget;
                        return new oilsRptBetweenWidget(widgetArgs);
                default:
-                       return new oilsRptAtomicWidget(widgetArgs);
+                       return new atomicWidget(widgetArgs);
        }
 
        /*
index c29eee2..0dc5b0a 100644 (file)
@@ -54,7 +54,9 @@
        <table id='oils_rpt_param_editor_table'>
                <thead>
                        <tr>
+                               <!--
                                <td>Object</td>
+                               -->
                                <td>Column</td>
                                <td>Transform</td>
                                <td>Action</td>
@@ -63,7 +65,9 @@
                </thead>
                <tbody id='oils_rpt_param_editor_tbody'>
                        <tr name='tr'>
+                               <!--
                                <td name='object'/>
+                               -->
                                <td name='column'/>
                                <td name='transform'/>
                                <td name='action'/>
                                                <span name='hint'/>
                                                <span name='widget'/>
                                        </div>
-                                       <!--
                                        <div name='reldate_div'  style='margin-top: 5px;' class='hide_me'>
                                                <div><b> - OR - </b></div>
                                                <input type='checkbox' name='choose_rel'/> Use a relative date instead.
                                                <div name='reldate'/>
                                        </div>
-                                       -->
                                </td>
                        </tr>
                </tbody>
index 5309fff..e5653e7 100644 (file)
@@ -122,16 +122,18 @@ oilsRptReportEditor.prototype.save = function() {
        debugFMObject(report);
        debugFMObject(schedule);
 
-       return;
+       //return;
 
        var obj = this;
        var req = new Request(OILS_RPT_CREATE_REPORT, SESSION, report, schedule );
        req.callback(
                function(r) {
                        var res = r.getResultObject();
-                       oilsRptAlertSuccess();
-                       oilsRptCurrentFolderManager.draw();
-                       obj.folderWindow.draw();
+                       if( res && res != '0' ) {
+                               oilsRptAlertSuccess();
+                               oilsRptCurrentFolderManager.draw();
+                               obj.folderWindow.draw();
+                       }
                }
        );
        req.send();
index 76446fc..baf4372 100644 (file)
@@ -208,6 +208,7 @@ oilsRptOrgMultiSelect.prototype.draw = function(org) {
 
 
 /* --------------------------------------------------------------------- */
+/*
 function oilsRptRelDatePicker(args) {
        this.node = args.node;
        this.relative = args.relative;
@@ -226,6 +227,7 @@ oilsRptRelDatePicker.prototype.getValue = function() {
        if( this.relative ) str = '-'+str;
        return str;
 }
+*/
 /* --------------------------------------------------------------------- */
 
 
@@ -285,7 +287,7 @@ oilsRptSetWidget.prototype.addDisplayItems = function(list) {
                if(exists) continue;
 
                _debug('Inserting SetWidget values ' + js2JSON(item));
-               insertSelectorVal(this.dest, -1, item.label, item.value);
+               insertSelectorVal(this.dest, -1, item.label, this.objToStr(item.value));
        }
 }
 
@@ -295,10 +297,25 @@ oilsRptSetWidget.prototype.removeSelected = function() {
 
 oilsRptSetWidget.prototype.getValue = function() {
        var vals = [];
-       iterate(this.dest, function(i){vals.push(i.getAttribute('value'))});
+       var obj = this;
+       iterate(this.dest, function(i){vals.push(obj.strToObj(i.getAttribute('value')))});
        return vals;
 }
 
+oilsRptSetWidget.prototype.objToStr = function(obj) {
+       if( typeof obj == 'string' ) return obj;
+       return ':'+obj.transform+':'+obj.params[0];
+}
+
+oilsRptSetWidget.prototype.strToObj = function(str) {
+       if( str.match(/^:.*/) ) {
+               var tform = str.replace(/^:(.*):.*/,'$1');
+               var param = str.replace(/^:.*:(.*)/,'$1');
+               return { transform : tform, params : [param] };
+       }
+       return str;
+}
+
 
 /* --------------------------------------------------------------------- 
        represents a widget that has start and end values.  start and end
@@ -311,9 +328,11 @@ function oilsRptBetweenWidget(args) {
 }
 oilsRptBetweenWidget.prototype.draw = function() {
        removeChildren(this.node);
-       this.node.appendChild(text('Between '));
        this.startWidget.draw();
-       this.node.appendChild(text(' and '));
+       this.node.appendChild(elem('hr'));
+       this.node.appendChild(elem('div',
+               {style:'text-align:center;width:100%;font-weight:bold'},' - And - '));
+       this.node.appendChild(elem('hr'));
        this.endWidget.draw();
 }
 oilsRptBetweenWidget.prototype.getValue = function() {
@@ -488,25 +507,30 @@ function oilsRptNumberWidget(args) {
        this.node = args.node;
        this.size = args.size || 24;
        this.start = args.start;
+       /*
        var len = new String(this.size).length;
        _debug('length = ' + len);
        this.input = elem('input',{type:'text',size: len});
+       */
        this.selector = elem('select');
 }
 oilsRptNumberWidget.prototype.draw = function() {
        for( var i = this.start; i < (this.size + this.start); i++ )
                insertSelectorVal(this.selector, -1, i, i);
        this.node.appendChild(this.selector);
-       this.node.appendChild(this.input);
+       //this.node.appendChild(this.input);
        var obj = this;
+       /*
        this.selector.onchange = function() {
                obj.input.value = getSelectorVal(obj.selector);
        }
        this.input.value = getSelectorVal(this.selector);
+       */
 }
 
 oilsRptNumberWidget.prototype.getValue = function() {
-       return this.input.value;
+       //return this.input.value;
+       return getSelectorVal(this.selector);
 }
 
 oilsRptNumberWidget.prototype.getDisplayValue = function() {
@@ -515,6 +539,73 @@ oilsRptNumberWidget.prototype.getDisplayValue = function() {
 
 
 /* --------------------------------------------------------------------- 
+       Relative dates widget
+       --------------------------------------------------------------------- */
+function oilsRptTruncPicker(args) {
+       this.node = args.node;
+       this.type = args.type;
+       this.realSpan = elem('span');
+       this.relSpan = elem('span');
+       hideMe(this.relSpan);
+       args.node = this.realSpan;
+       this.calWidget = new oilsRptCalWidget(args);
+       args.node = this.node;
+
+       this.selector = elem('select');
+       insertSelectorVal(this.selector,-1,'Real Date',1);
+       insertSelectorVal(this.selector,-1,'Relative Date',2);
+
+       this.numberPicker = 
+               new oilsRptNumberWidget({node:this.relSpan,size:24,start:1});
+
+       this.label = 'Day(s)';
+       if(this.type == 'month') this.label = 'Month(s)';
+       if(this.type == 'quarter') this.label = 'Quarter(s)';
+       if(this.type == 'year') this.label = 'Year(s)';
+}
+
+oilsRptTruncPicker.prototype.draw = function() {
+       this.node.appendChild(this.selector);
+       this.node.appendChild(this.realSpan);
+       this.node.appendChild(this.relSpan);
+       this.calWidget.draw();
+       this.numberPicker.draw();
+       this.relSpan.appendChild(text(this.label+' ago'));
+
+       var obj = this;
+       this.selector.onchange = function() {
+               if( getSelectorVal(obj.selector) == 1 ) {
+                       unHideMe(obj.realSpan);
+                       hideMe(obj.relSpan);
+               } else {
+                       unHideMe(obj.relSpan);
+                       hideMe(obj.realSpan);
+               }
+       }
+}
+
+oilsRptTruncPicker.prototype.getValue = function() {
+       if( getSelectorVal(this.selector) == 2) {
+               var val = this.numberPicker.getValue();
+               var tform = 'relative_' + this.type;
+               return { transform : tform, params : ['-'+val] };
+       }
+       return this.calWidget.getValue();
+}
+
+oilsRptTruncPicker.prototype.getDisplayValue = function() {
+       if( getSelectorVal(this.selector) == 2) {
+               var num = this.numberPicker.getValue();
+               return { label : num +' '+this.label+' ago', value : this.getValue() };
+       }
+       return this.calWidget.getDisplayValue();
+}
+
+
+
+
+
+/* --------------------------------------------------------------------- 
        CUSTOM WIDGETS
        --------------------------------------------------------------------- */