From 6548106d0a0609aa90483ed23eeb0d5a47a89578 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 28 Sep 2006 04:22:17 +0000 Subject: [PATCH] ever more toil 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 | 9 ++ Open-ILS/web/reports/oils_rpt.js | 62 +++++++- Open-ILS/web/reports/oils_rpt_builder.js | 22 +-- Open-ILS/web/reports/oils_rpt_common.xhtml | 1 + .../web/reports/oils_rpt_folder_window.js | 80 +++++++++- .../oils_rpt_report_folder_window.xhtml | 36 +++++ .../oils_rpt_template_folder_window.xhtml | 2 +- Open-ILS/web/reports/oils_rpt_utils.js | 29 ++++ Open-ILS/web/reports/oils_rpt_widget.js | 142 ++++++++++++++++++ 9 files changed, 355 insertions(+), 28 deletions(-) create mode 100644 Open-ILS/web/reports/oils_rpt_widget.js diff --git a/Open-ILS/web/reports/oils_rpt.css b/Open-ILS/web/reports/oils_rpt.css index ecceb50a83..faa54e263d 100644 --- a/Open-ILS/web/reports/oils_rpt.css +++ b/Open-ILS/web/reports/oils_rpt.css @@ -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; +} diff --git a/Open-ILS/web/reports/oils_rpt.js b/Open-ILS/web/reports/oils_rpt.js index 2e8160ecd1..44e8f9c0ca 100644 --- a/Open-ILS/web/reports/oils_rpt.js +++ b/Open-ILS/web/reports/oils_rpt.js @@ -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 + }); + } +} + + + diff --git a/Open-ILS/web/reports/oils_rpt_builder.js b/Open-ILS/web/reports/oils_rpt_builder.js index 401e2a60ca..75e17fa9d6 100644 --- a/Open-ILS/web/reports/oils_rpt_builder.js +++ b/Open-ILS/web/reports/oils_rpt_builder.js @@ -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(/-/); diff --git a/Open-ILS/web/reports/oils_rpt_common.xhtml b/Open-ILS/web/reports/oils_rpt_common.xhtml index abb5f554aa..c93b671e3c 100644 --- a/Open-ILS/web/reports/oils_rpt_common.xhtml +++ b/Open-ILS/web/reports/oils_rpt_common.xhtml @@ -36,6 +36,7 @@ + diff --git a/Open-ILS/web/reports/oils_rpt_folder_window.js b/Open-ILS/web/reports/oils_rpt_folder_window.js index d2b9aeda0c..1c2abe93a8 100644 --- a/Open-ILS/web/reports/oils_rpt_folder_window.js +++ b/Open-ILS/web/reports/oils_rpt_folder_window.js @@ -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); } diff --git a/Open-ILS/web/reports/oils_rpt_report_folder_window.xhtml b/Open-ILS/web/reports/oils_rpt_report_folder_window.xhtml index 82f57233cb..251958f138 100644 --- a/Open-ILS/web/reports/oils_rpt_report_folder_window.xhtml +++ b/Open-ILS/web/reports/oils_rpt_report_folder_window.xhtml @@ -4,6 +4,9 @@ Select a report: + + +
+ Offset: + + Length: + +
+ + + + + + diff --git a/Open-ILS/web/reports/oils_rpt_template_folder_window.xhtml b/Open-ILS/web/reports/oils_rpt_template_folder_window.xhtml index 518daa1454..9d9533d721 100644 --- a/Open-ILS/web/reports/oils_rpt_template_folder_window.xhtml +++ b/Open-ILS/web/reports/oils_rpt_template_folder_window.xhtml @@ -20,7 +20,7 @@ - + diff --git a/Open-ILS/web/reports/oils_rpt_utils.js b/Open-ILS/web/reports/oils_rpt_utils.js index e090050209..7b1227e7f1 100644 --- a/Open-ILS/web/reports/oils_rpt_utils.js +++ b/Open-ILS/web/reports/oils_rpt_utils.js @@ -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 index 0000000000..bfea75dd84 --- /dev/null +++ b/Open-ILS/web/reports/oils_rpt_widget.js @@ -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; +} + + + + + -- 2.43.2