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;
+}
}
+
+
/* ---------------------------------------------------------------------
Define the report object
--------------------------------------------------------------------- */
-function oilsReport() {
+function oilsReport(templateObj, reportObj) {
this.def = {
select : [],
from : {},
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() {
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
+ });
+ }
+}
+
+
+
oilsRptResetParams();
}
+
/*
function oilsRptBuildCalendars() {
Calendar.setup({
*/
-
-/* 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(/-/);
<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>
return oilsRptTemplateCache[id];
var r = new Request(OILS_RPT_FETCH_TEMPLATE, SESSION, id);
r.send(true);
- return r.result();
+ return oilsRptTemplateCache[id] = r.result();
}
this.folderNode = node;
this.type = type;
this.init();
- _debug('id = ' + this.id);
}
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());
insertSelectorVal(selector, -1, name, ts[i].id());
cache[ts[i].id()] = ts[i];
}
+ if(callback) callback();
}
);
req.send();
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);
}
<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>
</td>
</tr>
<tr>
- <td colspan='2'>
+ <td colspan='3' align='center'>
<button id='oils_rpt_template_folder_window_go'>Go!</button>
</td>
</tr>
/* -------------------------------------------- */
+/* 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('-');
+}
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);
+}
+
--- /dev/null
+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;
+}
+
+
+
+
+