1 /** initializes reports, some basid display settings,
2 * grabs and builds the IDL tree
4 function oilsInitReportBuilder() {
6 oilsReportBuilderReset();
7 DOM.oils_rpt_table.onclick =
8 function(){hideMe(DOM.oils_rpt_column_editor)};
11 hideMe(DOM.oils_rpt_tree_loading);
12 unHideMe(DOM.oils_rpt_table);
17 function oilsReportBuilderReset() {
18 var n = (oilsRpt) ? oilsRpt.name : "";
19 oilsRpt = new oilsReport();
21 oilsRptDisplaySelector = DOM.oils_rpt_display_selector;
22 oilsRptFilterSelector = DOM.oils_rpt_filter_selector;
23 removeChildren(oilsRptDisplaySelector);
24 removeChildren(oilsRptFilterSelector);
30 /* returns just the column name */
31 function oilsRptPathCol(path) {
32 var parts = path.split(/-/);
36 /* returns the IDL class of the selected column */
37 function oilsRptPathClass(path) {
38 var parts = path.split(/-/);
43 /* returns everything prior to the column name */
44 function oilsRptPathRel(path) {
45 var parts = path.split(/-/);
47 return parts.join('-');
50 /* creates a label "path" based on the column path */
51 function oilsRptMakeLabel(path) {
52 var parts = path.split(/-/);
54 for( var i = 0; i < parts.length; i++ ) {
57 str += oilsIDL[parts[i]].label;
59 var f = oilsRptFindField(oilsIDL[parts[i-1]], parts[i]);
67 /* adds an item to the display window */
68 function oilsAddRptDisplayItem(path, name, tform, params) {
69 if( ! oilsAddSelectorItem(oilsRptDisplaySelector, path, name) )
72 /* add the selected columns to the report output */
73 name = (name) ? name : oilsRptPathCol(path);
74 var param = oilsRptNextParam();
76 /* add this item to the select blob */
78 relation:oilsRptPathRel(path),
85 params.unshift(oilsRptPathCol(path));
86 sel.column[tform] = params;
88 sel.column[tform] = oilsRptPathCol(path);
90 } else { sel.column = oilsRptPathCol(path); }
92 oilsRpt.def.select.push(sel);
94 mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path));
95 oilsRpt.params[param] = name;
99 /* takes a column path and builds a from-clause object for the path */
100 function oilsRptBuildFromClause(path) {
101 var parts = path.split(/-/);
106 for( var i = 0; i < parts.length; i += 2 ) {
108 var col = parts[i+1];
109 var node = oilsIDL[parts[i]];
110 var field = oilsRptFindField(node, col);
111 newpath = (newpath) ? newpath + '-'+ cls : cls;
113 tobj.table = node.table;
114 tobj.alias = newpath;
115 _debug('field type is ' + field.type);
116 if( i == (parts.length - 2) ) break;
122 if( field.type == 'link' )
123 tobj.key = field.key;
125 newpath = newpath + '-'+ col;
128 _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj)));
133 /* removes a specific item from the display window */
134 function oilsDelDisplayItem(val) {
135 oilsDelSelectorItem(oilsRptDisplaySelector, val);
138 /* removes selected items from the display window */
139 function oilsDelSelectedDisplayItems() {
140 var list = oilsDelSelectedItems(oilsRptDisplaySelector);
142 /* remove the de-selected columns from the report output */
143 oilsRpt.def.select = grep( oilsRpt.def.select,
145 for( var j = 0; j < list.length; j++ ) {
149 /* if this columsn has a transform,
150 it will be an object { tform => column } */
151 if( typeof col != 'string' )
152 for( var c in col ) col = col[c];
154 /* if this transform requires params, the column
155 will be the first item in the param set array */
156 if( typeof col != 'string' ) col = col[0];
158 if( oilsRptPathRel(d) == i.relation && oilsRptPathCol(d) == col ) {
159 var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
160 if( param ) delete oilsRpt.params[param];
168 if(!oilsRpt.def.select) {
169 oilsRpt.def.select = [];
170 oilsReportBuilderReset();
173 for( var j = 0; j < list.length; j++ )
174 /* if there are no items left in the "select" clause for the given
175 relation, trim this relation from the "from" clause */
176 if(!grep(oilsRpt.def.select,
177 function(i){ return (i.relation == oilsRptPathRel(list[j])); }))
178 oilsRptPruneFromClause(oilsRptPathRel(list[j]));
184 /* for each item in the path list, remove the associated data
185 from the "from" clause */
187 function oilsRptPruneFromClause(relation, node) {
188 _debug("removing relation from 'from' clause " + relation);
189 if(!node) node = oilsRpt.def.from.join;
190 for( var i in node ) {
191 if( node[i].alias == relation ) {
193 /* if we have subtrees, don't delete our tree node */
201 if( oilsRptPruneFromClause(relation, node[i].join ) ) {
202 if(oilsRptObjectKeys(node[i].join).length == 0) {
204 /* if there are no items in the select clause with a relation matching
205 this nodes alias, we can safely remove this node from the tree */
206 if(!grep(oilsRpt.def.select,function(r){return (r.relation==node[i].alias)}))
217 /* adds an item to the display window */
218 function oilsAddRptFilterItem(val) {
219 oilsAddSelectorItem(oilsRptFilterSelector, val);
222 /* removes a specific item from the display window */
223 function oilsDelFilterItem(val) {
224 oilsDelSelectorItem(oilsRptFilterSelector, val);
227 /* removes selected items from the display window */
228 function oilsDelSelectedFilterItems() {
229 oilsDelSelectedItems(oilsRptFilterSelector);
233 /* adds an item to the display window */
234 function oilsAddSelectorItem(sel, val, name) {
235 name = (name) ? name : oilsRptMakeLabel(val);
236 _debug("adding selector item "+name+' = ' +val);
237 for( var i = 0; i < sel.options.length; i++ ) {
238 var opt = sel.options[i];
239 if( opt.value == val ) return false;
241 insertSelectorVal( sel, -1, name, val );
246 /* removes a specific item from the display window */
247 function oilsDelSelectorItem(sel, val) {
248 _debug("deleting selector item "+val);
249 var opts = sel.options;
250 for( var i = 0; i < opts.length; i++ ) {
252 if( opt.value == val ) {
253 if( i == opts.length - 1 )
255 else opts[i] = opts[i+1];
261 /* removes selected items from the display window */
262 function oilsDelSelectedItems(sel) {
263 var list = getSelectedList(sel);
264 for( var i = 0; i < list.length; i++ )
265 oilsDelSelectorItem(sel, list[i]);
270 /* hides the different field editor tabs */
271 function oilsRptHideEditorDivs() {
272 hideMe(DOM.oils_rpt_tform_div);
273 hideMe(DOM.oils_rpt_filter_div);
274 hideMe(DOM.oils_rpt_agg_filter_div);
279 This draws the 3-tabbed window containing the transform,
280 filter, and aggregate filter picker window
282 function oilsRptDrawDataWindow(path) {
283 var col = oilsRptPathCol(path);
284 var cls = oilsRptPathClass(path);
285 var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
287 _debug("setting update data window for column "+col+' on class '+cls);
289 var div = DOM.oils_rpt_column_editor;
290 /* set a preliminary top position so the page won't bounce around */
291 div.setAttribute('style','top:'+oilsMouseX+'px');
293 /* unhide the div so we can determine the dimensions */
296 /* don't let them see the floating div until the position is fully determined */
297 div.style.visibility='hidden';
299 oilsRptDrawTransformWindow(path, col, cls, field);
301 DOM.oils_rpt_column_editor_close_button.onclick = function(){hideMe(div);};
302 buildFloatingDiv(div, 600);
304 /* now let them see it */
305 div.style.visibility='visible';
307 /* give the tab links behavior */
308 DOM.oils_rpt_tform_tab.onclick =
309 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_tform_div)};
310 DOM.oils_rpt_filter_tab.onclick =
311 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_filter_div)};
312 DOM.oils_rpt_agg_filter_tab.onclick =
313 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_agg_filter_div)};
315 DOM.oils_rpt_tform_tab.onclick();
319 /* draws the transform window */
320 function oilsRptDrawTransformWindow(path, col, cls, field) {
321 appendClear(DOM.oils_rpt_tform_label, text(oilsRptMakeLabel(path)));
322 DOM.oils_rpt_tform_label_input.value = oilsRptMakeLabel(path);
323 var dtype = field.datatype;
325 DOM.oils_rpt_tform_submit.onclick =
327 var tform = oilsRptGetTform(dtype);
328 _debug('found tform: ' + js2JSON(tform));
329 var params = getRptTformParams(dtype, tform);
330 _debug('found tform params: ' + js2JSON(params));
331 tform = (tform == 'raw') ? null : tform;
332 oilsAddRptDisplayItem(path, DOM.oils_rpt_tform_label_input.value, tform, params )
335 DOM.oils_rpt_tform_label_input.focus();
336 DOM.oils_rpt_tform_label_input.select();
337 oilsRptHideTformFields();
338 oilsRptUnHideTformFields(dtype);
340 _debug("Transforming item with datatype "+dtype);
341 unHideMe($('oils_rpt_tform_'+dtype+'_div'));
342 $('oils_rpt_tform_all_raw').checked = true;
345 function oilsRptHideTformFields() {
346 var rows = DOM.oils_rpt_tform_tbody.childNodes;
347 for( var i = 0; i < rows.length; i++ )
348 if( rows[i] && rows[i].nodeType == 1 )
352 function oilsRptUnHideTformFields(dtype) {
353 var rows = DOM.oils_rpt_tform_tbody.childNodes;
354 for( var i = 0; i < rows.length; i++ ) {
356 if( row && row.nodeType == 1 &&
357 (row.getAttribute('datatype')=='all'
358 || row.getAttribute('datatype') == dtype)) {
364 function oilsRptGetTform(datatype) {
365 for( var i in oilsRptTransforms[datatype] )
366 if( $('oils_rpt_tform_'+datatype+'_'+oilsRptTransforms[datatype][i]).checked )
367 return oilsRptTransforms[datatype][i];
368 for( var i in oilsRptTransforms.all )
369 if( $('oils_rpt_tform_all_'+oilsRptTransforms.all[i]).checked )
370 return oilsRptTransforms.all[i];
374 function getRptTformParams(type, tform) {
379 return [DOM.oils_rpt_tform_timestamp_months_ago_input.value];
381 return [DOM.oils_rpt_tform_timestamp_quarters_ago_input.value];
387 DOM.oils_rpt_tform_string_substring_offset.value,
388 DOM.oils_rpt_tform_string_substring_length.value];