ever more toil
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 28 Sep 2006 04:22:17 +0000 (04:22 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 28 Sep 2006 04:22:17 +0000 (04:22 +0000)
added generic widget handling code for taking user input on report params

git-svn-id: svn://svn.open-ils.org/ILS/trunk@6239 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/reports/oils_rpt.css
Open-ILS/web/reports/oils_rpt.js
Open-ILS/web/reports/oils_rpt_builder.js
Open-ILS/web/reports/oils_rpt_common.xhtml
Open-ILS/web/reports/oils_rpt_folder_window.js
Open-ILS/web/reports/oils_rpt_report_folder_window.xhtml
Open-ILS/web/reports/oils_rpt_template_folder_window.xhtml
Open-ILS/web/reports/oils_rpt_utils.js
Open-ILS/web/reports/oils_rpt_widget.js [new file with mode: 0644]

index ecceb50..faa54e2 100644 (file)
@@ -186,3 +186,12 @@ button {
 oils_rpt_folder_window_div {
        width: 100%;
 }
+
+.oils_rpt_param_table thead td {
+       font-weight: bold;
+}
+
+.oils_rpt_param_table td {
+       border: 1px solid #808080;
+       padding: 5px;
+}
index 2e8160e..44e8f9c 100644 (file)
@@ -23,10 +23,12 @@ function oilsCleanupReports() {
 }
 
 
+
+
 /* ---------------------------------------------------------------------
        Define the report object
        --------------------------------------------------------------------- */
-function oilsReport() {
+function oilsReport(templateObj, reportObj) {
        this.def = {
                select  : [],
                from            : {},
@@ -34,8 +36,19 @@ function oilsReport() {
                having  : [],
                order_by : []
        };
+
        this.params     = {};
-       this.name       = ""
+       this.name       = "";
+       this.templateObject = templateObj;
+       this.reportObject = reportObj;
+
+       if( templateObj ) {
+               this.def = JSON2js(templateObj.data());
+               this.name = templateObj.name();
+       }
+
+       if( reportObj ) 
+               this.params = JSON2js(reportObj.data());
 }
 
 oilsReport.prototype.toString = function() {
@@ -46,4 +59,49 @@ oilsReport.prototype.toHTMLString = function() {
        return formatJSONHTML(js2JSON(this));
 }
 
+oilsReport.prototype.gatherParams = function() {
+       if(oilsRptObjectKeys(this.params).length == 0) return;
+
+       _debug("we have params: " + js2JSON(this.params));
+
+       var params      = [];
+       this._gatherParams(params, this.def.select, 'select', 'alias');
+       this._gatherParams(params, this.def.where, 'where', 'condition');
+       this._gatherParams(params, this.def.having, 'having', 'condition');
+       return params;
+}
+
+oilsReport.prototype._gatherParams = function(params, arr, type, field) {
+       if(!arr) return;
+       for( var i = 0; i < arr.length; i++ ) {
+
+               var obj = arr[i];
+               node = obj[field];
+               var key; 
+               var op;
+
+               if( typeof node == 'string' ) {
+                       key = node.match(/::.*/);
+               } else {
+                       op = oilsRptObjectKeys(node)[0];
+                       key = (node[op] +'').match(/::.*/);
+               }
+
+               if(!key) continue;
+               key = key[0].replace(/::/,'');
+               _debug("key = "+key+", param = " + this.params[key]);
+
+               params.push( { 
+                       key             : key,
+                       op                      : op,
+                       value           : this.params[key],
+                       column  : obj.column,
+                       type            : type, 
+                       relation : obj.relation
+               });
+       }
+}
+
+
+
 
index 401e2a6..75e17fa 100644 (file)
@@ -27,6 +27,7 @@ function oilsReportBuilderReset() {
        oilsRptResetParams();
 }
 
+
 /*
 function oilsRptBuildCalendars() {
        Calendar.setup({
@@ -47,27 +48,6 @@ function oilsRptBuildCalendars() {
 */
 
 
-
-/* returns just the column name */
-function oilsRptPathCol(path) {
-       var parts = path.split(/-/);
-       return parts.pop();
-}
-
-/* returns the IDL class of the selected column */
-function oilsRptPathClass(path) {
-       var parts = path.split(/-/);
-       parts.pop();
-       return parts.pop();
-}
-
-/* returns everything prior to the column name */
-function oilsRptPathRel(path) {
-       var parts = path.split(/-/);
-       parts.pop();
-       return parts.join('-');
-}
-
 /* creates a label "path" based on the column path */
 function oilsRptMakeLabel(path) {
        var parts = path.split(/-/);
index abb5f55..c93b671 100644 (file)
@@ -36,6 +36,7 @@
 <script type="text/javascript" src="oils_rpt_builder_widgets.js"></script>
 <script type="text/javascript" src="oils_rpt_folders.js"></script>
 <script type="text/javascript" src="oils_rpt_folder_window.js"></script>
+<script type="text/javascript" src="oils_rpt_widget.js"></script>
 <script type="text/javascript" src="oils_rpt.js"></script>
 
 <link rel="stylesheet" type="text/css" href="oils_rpt.css"> </link>
index d2b9aed..1c2abe9 100644 (file)
@@ -20,7 +20,7 @@ function oilsRptFetchTemplate(id) {
                return oilsRptTemplateCache[id];
        var r = new Request(OILS_RPT_FETCH_TEMPLATE, SESSION, id);
        r.send(true);
-       return r.result();
+       return oilsRptTemplateCache[id] = r.result();
 }
 
 
@@ -34,7 +34,6 @@ oilsRptFolderWindow.prototype.init2 = function(node, type) {
        this.folderNode = node;
        this.type = type;
        this.init();
-       _debug('id = ' + this.id);
 }
 
 oilsRptFolderWindow.prototype.openWindow = function(node) {
@@ -44,7 +43,7 @@ oilsRptFolderWindow.prototype.openWindow = function(node) {
        unHideMe(node);
 }
 
-oilsRptFolderWindow.prototype.fetchFolderData = function(type, selector, cache) {
+oilsRptFolderWindow.prototype.fetchFolderData = function(type, selector, cache, callback) {
        removeChildren(selector);
        var req = new Request(OILS_RPT_FETCH_FOLDER_DATA, 
                SESSION, type, this.folderNode.folder.id());
@@ -60,6 +59,7 @@ oilsRptFolderWindow.prototype.fetchFolderData = function(type, selector, cache)
                                insertSelectorVal(selector, -1, name, ts[i].id());
                                cache[ts[i].id()] = ts[i];
                        }
+                       if(callback) callback();
                }
        );
        req.send();
@@ -99,7 +99,79 @@ function oilsRptReportFolderWindow(node) { this.init2(node, 'report'); }
 
 oilsRptReportFolderWindow.prototype.draw = function() {
        this.openWindow(DOM.oils_rpt_report_folder_window_contents_div);
-       this.fetchFolderData('report', DOM.oils_rpt_report_selector, oilsRptReportCache);
+       var obj = this;
+       this.fetchFolderData('report', 
+               DOM.oils_rpt_report_selector, oilsRptReportCache, 
+                       function() {
+                               appendClear(DOM.oils_rpt_report_description, 
+                                       text(obj.getSelectedReport().description()));
+                       }
+       );
+
+       DOM.oils_rpt_report_folder_window_go.onclick = function() {
+               var rpt = obj.getSelectedReport();
+               var tmpl = oilsRptFetchTemplate(rpt.template());
+               obj.oilsReport = new oilsReport( tmpl, rpt );
+               var params = obj.oilsReport.gatherParams();
+               obj.drawParamEditor(params);
+       };
+}
+
+oilsRptReportFolderWindow.prototype.drawParamEditor = function(params) {
+       _debug('drawing params: \n' + formatJSON(js2JSON(params)));
+       this.drawSelectParamEditor(grep(params,
+               function(p) { return (p.type == 'select')}));
+       this.drawWhereParamEditor(grep(params,
+               function(p) { return (p.type == 'where')}));
+       this.drawHavingParamEditor(grep(params,
+               function(p) { return (p.type == 'having')}));
+}
+
+
+var oilsRptReportFolderSelectParamRow;
+oilsRptReportFolderWindow.prototype.drawSelectParamEditor = function(params) {
+       if(params.length == 0) return;
+       unHideMe(DOM.oils_rpt_report_folder_window_display_params_table);
+
+       var tbody = $n(DOM.oils_rpt_report_folder_window_display_params_table,'tbody');
+       if(!oilsRptReportFolderSelectParamRow)
+               oilsRptReportFolderSelectParamRow = tbody.removeChild($n(tbody,'tr'));
+
+       for( var p = 0; p < params.length; p++ ) {
+
+               var row = oilsRptReportFolderSelectParamRow.cloneNode(true);
+               var par = params[p];
+               $n(row, 'column').appendChild(text(par.column.colname));
+               $n(row, 'transform').appendChild(text(par.column.transform));
+
+               if( typeof par.value == 'string' ) {
+                       unHideMe($n(row, 'param'));
+                       $n(row, 'param').value = par.value;
+               } else {
+                       switch(par.transform) {
+                               case 'substring':
+                                       unHideMe($n(row,'string_substring_widget'));
+                                       break;
+                       }
+               }
+               tbody.appendChild(row);
+       }
+}
+
+oilsRptReportFolderWindow.prototype.drawWhereParamEditor = function(params) {
+}
+
+oilsRptReportFolderWindow.prototype.drawHavingParamEditor = function(params) {
+}
+
+
+
+oilsRptReportFolderWindow.prototype.getSelectedReport = function() {
+       return oilsRptReportCache[getSelectorVal(DOM.oils_rpt_report_selector)];
+}
+
+oilsRptReportFolderWindow.prototype.getSelectedAction = function() {
+       return getSelectorVal(DOM.oils_rpt_report_selector, force);
 }
 
 
index 82f5723..251958f 100644 (file)
@@ -4,6 +4,9 @@
                        <tr>
                                <td>Select a report:</td>
                                <td><select id='oils_rpt_report_selector'/></td>
+                               <td>
+                                       <span>Report Description: </span><span id='oils_rpt_report_description'/>
+                               </td>
                        </tr>
                        <tr>
                                <td>Select an action:</td>
                                        </div>
                                </td>
                        </tr>
+                       <tr>
+                               <td colspan='2' align='center'>
+                                       <button id='oils_rpt_report_folder_window_go'>Go!</button>
+                               </td>
+                       </tr>
                </tbody>
        </table>
+
+       <table id='oils_rpt_report_folder_window_display_params_table' class='hide_me oils_rpt_param_table'>
+
+               <thead>
+                       <tr><td colspan='3' align='center'>Display Transforms</td></tr>
+                       <tr><td>Column</td><td>Transform</td><td>Parameters</td></tr>
+               </thead>
+
+               <tbody name='tbody'>
+                       <tr name='tr'>
+                               <td name='column'/>
+                               <td name='transform'/>
+                               <td>
+                                       <input name='param' type='text' class='hide_me'/>
+
+                                       <!-- pull in from an external file? -->
+                                       <div widget='1' name='string_substring_widget' class='hide_me'>
+                                               <span style='padding-left: 5px;'>Offset: </span>
+                                               <input name='string_substring_offset' size='3' value='1'/>
+                                               <span style='padding-left: 5px;'>Length: </span>
+                                       <input name='string_substring_length' size='3' value='1'/>
+                                       </div>
+
+                               </td>
+                       </tr>
+               </tbody>
+       </table>
+
 </div>
 
index 518daa1..9d9533d 100644 (file)
@@ -20,7 +20,7 @@
                                </td>
                        </tr>
                        <tr>
-                               <td colspan='2'>
+                               <td colspan='3' align='center'>
                                        <button id='oils_rpt_template_folder_window_go'>Go!</button>
                                </td>
                        </tr>
index e090050..7b1227e 100644 (file)
@@ -42,6 +42,25 @@ oilsRptObject.cache = function(obj) {
 /* -------------------------------------------- */
 
 
+/* returns just the column name */
+function oilsRptPathCol(path) {
+       var parts = path.split(/-/);
+       return parts.pop();
+}
+
+/* returns the IDL class of the selected column */
+function oilsRptPathClass(path) {
+       var parts = path.split(/-/);
+       parts.pop();
+       return parts.pop();
+}
+
+/* returns everything prior to the column name */
+function oilsRptPathRel(path) {
+       var parts = path.split(/-/);
+       parts.pop();
+       return parts.join('-');
+}
 
 
 
@@ -164,3 +183,13 @@ function oilsRptObjectKeys(obj) {
        return k;
 }
 
+
+/* makes cls a subclass of parent */
+function oilsRptSetSubClass(cls, parent) {
+       var str = cls+'.prototype = new '+parent+'();\n';
+       str += cls+'.prototype.constructor = '+cls+';\n';
+       str += cls+'.baseClass = '+parent+'.prototype.constructor;\n';
+       str += cls+'.prototype.super = '+parent+'.prototype;\n';
+       eval(str);
+}
+
diff --git a/Open-ILS/web/reports/oils_rpt_widget.js b/Open-ILS/web/reports/oils_rpt_widget.js
new file mode 100644 (file)
index 0000000..bfea75d
--- /dev/null
@@ -0,0 +1,142 @@
+oilsRptSetSubClass('oilsRptWidget', 'oilsRptObject');
+oilsRptWidget.OILS_RPT_TRANSFORM_WIDGET = 0;
+oilsRptWidget.OILS_RPT_OPERATION_WIDGET = 1;
+
+function oilsRptWidget(args) {
+       this.init(args);
+       this.dest = elem('input',{type:'text'});
+}
+
+oilsRptWidget.prototype.init = function(args) {
+       if(!args) return;
+       this.super.init();
+       this.node       = args.node;
+       this.type       = args.type;
+       this.action = args.action;
+       this.column     = args.column;
+}
+
+oilsRptWidget.prototype.getValue = function() {
+       return this.dest.value;
+}
+
+oilsRptWidget.prototype.draw = function() {
+       appendClear(this.node, this.dest);
+}
+
+
+/* ----------------------------------------------------------- */
+
+oilsRptSetSubClass('oilsRptMultiWidget', 'oilsRptWidget');
+function oilsRptMultiWidget(args) {
+       this.init(args);
+}
+
+oilsRptMultiWidget.prototype.init = function(args) {
+       if(!args) return;
+       this.super.init(args);
+       this.dest = elem('select',
+               {multiple:'multiple','class':'oils_rpt_info_selector'});
+       this.addButton = elem('button',null, 'Add');
+       this.addButton = this.getSourceCollector();
+}
+
+oilsRptMultiWidget.prototype.getValue = function() {
+       var vals = [];
+       for( var i = 0; i < this.dest.options.length; i++ )
+               vals.push(this.dest.options[i].value);
+       return vals;
+}
+
+oilsRptMultiWidget.prototype.removeSelected = function() {
+       oilsDeleteSelectedItems(this.dest);
+}
+
+oilsRptMultiWidget.prototype.addItem = function(name, val) {
+       for( var i = 0; i < this.dest.options.length; i++ )
+               if( this.dest.options[i].value == val ) 
+                       return;
+       insertSelectorVal(this.dest, -1, name, val);
+}
+
+oilsRptMultiWidget.prototype.setSource = function(src) {
+       this.source = src;
+}
+
+oilsRptMultiWidget.prototype.draw = function() {
+       appendClear(this.node, this.source);
+       appendClear(this.node, this.dest);
+}
+
+
+/* ----------------------------------------------------------- */
+
+oilsRptSetSubClass('oilsRptInputMultiWidget', 'oilsRptMultiWidget');
+function oilsRptInputMultiWidget(args) {
+       this.init(args);
+}
+oilsRptInputMultiWidget.prototype.init = function(args) {
+       if(!args) return;
+       this.super.init(args);
+       this.setSource(elem('input',{type:'text'}));
+}
+
+oilsRptInputMultiWidget.prototype.addItem = function(name, val) {
+       this.super.addItem(name, val);
+       this.source.value = "";
+       this.source.focus();
+}
+
+oilsRptInputMultiWidget.prototype.getSourceCollector = function() {
+       var obj = this;
+       return function() {
+               obj.addItem(obj.source.value, obj.source.value);
+       }
+}
+
+/* ----------------------------------------------------------- */
+
+oilsRptSetSubClass('oilsRptSelectorMultiWidget', 'oilsRptMultiWidget');
+function oilsRptSelectorMultiWidget(args) {
+       this.init(args);
+}
+oilsRptSelectorMultiWidget.prototype.init = function(args) {
+       if(!args) return;
+       this.super.init(args);
+       this.setSource(
+               elem('select',{multiple:multiple, 'class':'oils_rpt_info_selector'}));
+}
+
+oilsRptSelectorMultiWidget.prototype.getSourceCollector = function() {
+       var obj = this;
+       return function() {
+               for( var i = 0; i < obj.source.options.length; i++ )
+                       obj.addItem(obj.source.options.name, obj.source.options.value);
+       }
+}
+
+/* ----------------------------------------------------------- */
+
+oilsRptSetSubClass('oilsRptRemoteWidget', 'oilsRptSelectorMultiWidget');
+function oilsRptRemoteWidget(args) {
+       this.init(args);
+}
+oilsRptRemoteWidget.prototype.init = function(args) {
+       if(!args) return;
+       this.super.init(args);
+       this.selector = args.selector;
+}
+
+oilsRptRemoteWidget.prototype.draw = function() {
+       this.fetch();
+       this.super.draw();
+}
+
+oilsRptRemoteWidget.prototype.setFetch = function(func) {
+       this.fetch = func;
+}
+
+
+
+
+