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 var n = (oilsRpt) ? oilsRpt.name : "";
17 oilsRpt = new oilsReport();
19 oilsRptDisplaySelector = DOM.oils_rpt_display_selector;
20 oilsRptFilterSelector = DOM.oils_rpt_filter_selector;
21 removeChildren(oilsRptDisplaySelector);
22 removeChildren(oilsRptFilterSelector);
27 /* returns just the column name */
28 function oilsRptPathCol(path) {
29 var parts = path.split(/-/);
33 /* returns the IDL class of the selected column */
34 function oilsRptPathClass(path) {
35 var parts = path.split(/-/);
40 /* returns everything prior to the column name */
41 function oilsRptPathRel(path) {
42 var parts = path.split(/-/);
44 return parts.join('-');
47 /* creates a label "path" based on the column path */
48 function oilsRptMakeLabel(path) {
49 var parts = path.split(/-/);
51 for( var i = 0; i < parts.length; i++ ) {
54 str += oilsIDL[parts[i]].label;
56 var column = parts[i];
57 var data = oilsIDL[parts[i-1]];
58 var f = grep(data.fields,
59 function(j){return (j.name == column); })[0];
67 /* adds an item to the display window */
68 function oilsAddRptDisplayItem(path, name, tform) {
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),
84 sel.column[tform] = oilsRptPathCol(path);
85 } else { sel.column = oilsRptPathCol(path); }
87 oilsRpt.def.select.push(sel);
89 mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path));
90 oilsRpt.params[param] = name;
94 /* takes a column path and builds a from-clause object for the path */
95 function oilsRptBuildFromClause(path) {
96 var parts = path.split(/-/);
101 for( var i = 0; i < parts.length; i += 2 ) {
103 var col = parts[i+1];
104 var node = oilsIDL[parts[i]];
105 var field = oilsRptFindField(node, col);
106 newpath = (newpath) ? newpath + '-'+ cls : cls;
108 tobj.table = node.table;
109 tobj.alias = newpath;
110 _debug('field type is ' + field.type);
111 if( i == (parts.length - 2) ) break;
117 if( field.type == 'link' )
118 tobj.key = field.key;
120 newpath = newpath + '-'+ col;
123 _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj)));
128 /* removes a specific item from the display window */
129 function oilsDelDisplayItem(val) {
130 oilsDelSelectorItem(oilsRptDisplaySelector, val);
133 /* removes selected items from the display window */
134 function oilsDelSelectedDisplayItems() {
135 var list = oilsDelSelectedItems(oilsRptDisplaySelector);
137 /* remove the de-selected columns from the report output */
138 oilsRpt.def.select = grep( oilsRpt.def.select,
140 for( var j = 0; j < list.length; j++ ) {
144 /* if this columsn has a transform, it will be an object { tform => column } */
145 if( typeof col != 'string' )
146 for( var c in col ) col = col[c];
148 if( oilsRptPathRel(d) == i.relation && oilsRptPathCol(d) == col ) {
149 var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
150 if( param ) delete oilsRpt.params[param];
158 if(!oilsRpt.def.select) {
159 oilsRpt.def.select = [];
160 oilsReportBuilderReset();
163 for( var j = 0; j < list.length; j++ )
164 oilsRptPruneFromClause(list[j]);
170 /* for each item in the path list, remove the associated data
171 from the "from" clause */
172 function oilsRptPruneFromClause(pathlist) {
175 /* adds an item to the display window */
176 function oilsAddRptFilterItem(val) {
177 oilsAddSelectorItem(oilsRptFilterSelector, val);
180 /* removes a specific item from the display window */
181 function oilsDelFilterItem(val) {
182 oilsDelSelectorItem(oilsRptFilterSelector, val);
185 /* removes selected items from the display window */
186 function oilsDelSelectedFilterItems() {
187 oilsDelSelectedItems(oilsRptFilterSelector);
191 /* adds an item to the display window */
192 function oilsAddSelectorItem(sel, val, name) {
193 name = (name) ? name : oilsRptMakeLabel(val);
194 _debug("adding selector item "+name+' = ' +val);
195 for( var i = 0; i < sel.options.length; i++ ) {
196 var opt = sel.options[i];
197 if( opt.value == val ) return false;
199 insertSelectorVal( sel, -1, name, val );
204 /* removes a specific item from the display window */
205 function oilsDelSelectorItem(sel, val) {
206 _debug("deleting selector item "+val);
207 var opts = sel.options;
208 for( var i = 0; i < opts.length; i++ ) {
210 if( opt.value == val ) {
211 if( i == opts.length - 1 )
213 else opts[i] = opts[i+1];
219 /* removes selected items from the display window */
220 function oilsDelSelectedItems(sel) {
221 var list = getSelectedList(sel);
222 for( var i = 0; i < list.length; i++ )
223 oilsDelSelectorItem(sel, list[i]);
228 /* hides the different field editor tabs */
229 function oilsRptHideEditorDivs() {
230 hideMe(DOM.oils_rpt_tform_div);
231 hideMe(DOM.oils_rpt_filter_div);
232 hideMe(DOM.oils_rpt_agg_filter_div);
237 This draws the 3-tabbed window containing the transform,
238 filter, and aggregate filter picker window
240 function oilsRptDrawDataWindow(path) {
241 var col = oilsRptPathCol(path);
242 var cls = oilsRptPathClass(path);
243 var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
244 _debug("setting update data window for column "+col+' on class '+cls);
246 var div = DOM.oils_rpt_column_editor;
247 /* set a preliminary top position so the page won't bounce around */
248 div.setAttribute('style','top:'+oilsMouseX+'px');
250 /* unhide the div so we can determine the dimensions */
253 /* don't let them see the floating div until the position is fully determined */
254 div.style.visibility='hidden';
256 oilsRptDrawTransformWindow(path, col, cls, field);
258 DOM.oils_rpt_column_editor_close_button.onclick = function(){hideMe(div);};
259 buildFloatingDiv(div, 600);
261 /* now let them see it */
262 div.style.visibility='visible';
264 /* give the tab links behavior */
265 DOM.oils_rpt_tform_tab.onclick =
266 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_tform_div)};
267 DOM.oils_rpt_filter_tab.onclick =
268 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_filter_div)};
269 DOM.oils_rpt_agg_filter_tab.onclick =
270 function(){oilsRptHideEditorDivs();unHideMe(DOM.oils_rpt_agg_filter_div)};
272 DOM.oils_rpt_tform_tab.onclick();
276 /* draws the transform window */
277 function oilsRptDrawTransformWindow(path, col, cls, field) {
278 appendClear(DOM.oils_rpt_tform_label, text(oilsRptMakeLabel(path)));
279 DOM.oils_rpt_tform_label_input.value = oilsRptMakeLabel(path);
281 DOM.oils_rpt_tform_submit.onclick =
283 var tform = oilsRptGetTform();
284 tform = (tform == 'raw') ? null : tform;
285 oilsAddRptDisplayItem(path, DOM.oils_rpt_tform_label_input.value, tform)
288 DOM.oils_rpt_tform_label_input.focus();
289 DOM.oils_rpt_tform_label_input.select();
290 oilsRptHideTformFields();
292 _debug("Transforming item with datatype "+field.datatype);
293 unHideMe($('oils_rpt_tform_'+field.datatype+'_div'));
294 unHideMe($('oils_rpt_tform_'+field.datatype+'_raw'));
295 $('oils_rpt_tform_'+field.datatype+'_raw').checked = true;
298 function oilsRptHideTformFields() {
299 for( var t in oilsRptTransforms ) {
300 hideMe($('oils_rpt_tform_'+t+'_div'));
301 for( var i in oilsRptTransforms[t] ) {
302 _debug('oils_rpt_tform_'+t+'_'+oilsRptTransforms[t][i]);
303 $('oils_rpt_tform_'+t+'_'+oilsRptTransforms[t][i]).checked = false;
308 function oilsRptGetTform() {
309 for( var t in oilsRptTransforms )
310 for( var i in oilsRptTransforms[t] )
311 if( $('oils_rpt_tform_'+t+'_'+oilsRptTransforms[t][i]).checked )
312 return oilsRptTransforms[t][i];