1 /** initializes reports, some basid display settings,
2 * grabs and builds the IDL tree
4 function oilsInitReportBuilder() {
6 oilsReportBuilderReset();
9 hideMe(DOM.oils_rpt_tree_loading);
10 unHideMe(DOM.oils_rpt_table);
15 function oilsReportBuilderReset() {
16 oilsRpt = new oilsReport();
17 oilsRptDisplaySelector = DOM.oils_rpt_display_selector;
18 oilsRptFilterSelector = DOM.oils_rpt_filter_selector;
19 removeChildren(oilsRptDisplaySelector);
20 removeChildren(oilsRptFilterSelector);
24 /* returns just the column name */
25 function oilsRptPathCol(path) {
26 var parts = path.split(/-/);
30 /* returns the IDL class of the selected column */
31 function oilsRptPathClass(path) {
32 var parts = path.split(/-/);
37 /* returns everything prior to the column name */
38 function oilsRptPathRel(path) {
39 var parts = path.split(/-/);
41 return parts.join('-');
44 /* creates a label "path" based on the column path */
45 function oilsRptMakeLabel(path) {
46 var parts = path.split(/-/);
48 for( var i = 0; i < parts.length; i++ ) {
51 str += oilsIDL[parts[i]].label;
53 var column = parts[i];
54 var data = oilsIDL[parts[i-1]];
55 var f = grep(data.fields,
56 function(j){return (j.name == column); })[0];
64 /* adds an item to the display window */
65 function oilsAddRptDisplayItem(path, name) {
66 if( ! oilsAddSelectorItem(oilsRptDisplaySelector, path, name) )
69 /* add the selected columns to the report output */
70 name = (name) ? name : oilsRptPathCol(path);
71 var param = oilsRptNextParam();
73 /* add this item to the select blob */
74 oilsRpt.def.select.push( {
75 relation:oilsRptPathRel(path),
76 column:oilsRptPathCol(path),
80 mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path));
81 oilsRpt.params[param] = name;
85 /* takes a column path and builds a from-clause object for the path */
86 function oilsRptBuildFromClause(path) {
87 var parts = path.split(/-/);
88 //var obj = {from : {}};
92 for( var i = 0; i < parts.length; i += 2 ) {
95 var node = oilsIDL[parts[i]];
96 var field = oilsRptFindField(node, col);
97 newpath = (newpath) ? newpath + '-'+ cls : cls;
99 tobj.table = node.table;
100 tobj.alias = newpath;
101 _debug('field type is ' + field.type);
102 if( i == (parts.length - 2) ) break;
108 if( field.type == 'link' )
109 tobj.key = field.key;
111 newpath = newpath + '-'+ col;
114 _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj)));
119 /* removes a specific item from the display window */
120 function oilsDelDisplayItem(val) {
121 oilsDelSelectorItem(oilsRptDisplaySelector, val);
124 /* removes selected items from the display window */
125 function oilsDelSelectedDisplayItems() {
126 var list = oilsDelSelectedItems(oilsRptDisplaySelector);
128 /* remove the de-selected columns from the report output */
129 oilsRpt.def.select = grep( oilsRpt.def.select,
131 for( var j = 0; j < list.length; j++ ) {
133 if( oilsRptPathRel(d) == i.relation
134 && oilsRptPathCol(d) == i.column ) {
135 var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
136 if( param ) delete oilsRpt.params[param];
143 if(!oilsRpt.def.select) oilsRpt.def.select = [];
145 for( var j = 0; j < list.length; j++ )
146 oilsRptPruneFromClause(list[j]);
151 /* for each item in the path list, remove the associated data
152 from the "from" clause */
153 function oilsRptPruneFromClause(pathlist) {
156 /* adds an item to the display window */
157 function oilsAddRptFilterItem(val) {
158 oilsAddSelectorItem(oilsRptFilterSelector, val);
161 /* removes a specific item from the display window */
162 function oilsDelFilterItem(val) {
163 oilsDelSelectorItem(oilsRptFilterSelector, val);
166 /* removes selected items from the display window */
167 function oilsDelSelectedFilterItems() {
168 oilsDelSelectedItems(oilsRptFilterSelector);
172 /* adds an item to the display window */
173 function oilsAddSelectorItem(sel, val, name) {
174 name = (name) ? name : oilsRptMakeLabel(val);
175 _debug("adding selector item "+name+' = ' +val);
176 for( var i = 0; i < sel.options.length; i++ ) {
177 var opt = sel.options[i];
178 if( opt.value == val ) return false;
180 insertSelectorVal( sel, -1, name, val );
185 /* removes a specific item from the display window */
186 function oilsDelSelectorItem(sel, val) {
187 _debug("deleting selector item "+val);
188 var opts = sel.options;
189 for( var i = 0; i < opts.length; i++ ) {
191 if( opt.value == val ) {
192 if( i == opts.length - 1 )
194 else opts[i] = opts[i+1];
200 /* removes selected items from the display window */
201 function oilsDelSelectedItems(sel) {
202 var list = getSelectedList(sel);
203 for( var i = 0; i < list.length; i++ )
204 oilsDelSelectorItem(sel, list[i]);
209 /* hides the different field editor tabs */
210 function oilsRptHideEditorDivs() {
211 hideMe(DOM.oils_rpt_tform_div);
212 hideMe(DOM.oils_rpt_filter_div);
213 hideMe(DOM.oils_rpt_agg_filter_div);
218 This draws the 3-tabbed window containing the transform,
219 filter, and aggregate filter picker window
221 function oilsRptDrawDataWindow(path) {
222 var col = oilsRptPathCol(path);
223 var cls = oilsRptPathClass(path);
224 var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
225 _debug("setting update data window for column "+col+' on class '+cls);
227 var div = DOM.oils_rpt_column_editor;
228 /* set a preliminary top position so the page won't bounce around */
229 div.setAttribute('style','top:'+oilsMouseX+'px');
231 /* unhide the div so we can determine the dimensions */
234 /* don't let them see the floating div until the position is fully determined */
235 div.style.visibility='hidden';
237 oilsRptDrawTransformWindow(path, col, cls, field);
239 DOM.oils_rpt_column_editor_close_button.onclick = function(){hideMe(div);};
240 buildFloatingDiv(div, 600);
242 /* now let them see it */
243 div.style.visibility='visible';
245 /* give the tab links behavior */
246 DOM.oils_rpt_tform_tab.onclick =
247 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_tform_div)};
248 DOM.oils_rpt_filter_tab.onclick =
249 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_filter_div)};
250 DOM.oils_rpt_agg_filter_tab.onclick =
251 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_agg_filter_div)};
255 /* draws the transform window */
256 function oilsRptDrawTransformWindow(path, col, cls, field) {
257 appendClear(DOM.oils_rpt_tform_label, text(oilsRptMakeLabel(path)));
258 DOM.oils_rpt_tform_label_input.value = oilsRptMakeLabel(path);
260 DOM.oils_rpt_tform_submit.onclick =
261 function(){ oilsAddRptDisplayItem(path, DOM.oils_rpt_tform_label_input.value) };
263 DOM.oils_rpt_tform_label_input.focus();
264 DOM.oils_rpt_tform_label_input.select();
266 if( field.datatype == 'timestamp' )
267 unHideMe(DOM.oils_rpt_tform_date_div);