1 /** initializes reports, some basid display settings,
2 * grabs and builds the IDL tree
4 function oilsInitReportBuilder() {
6 oilsRpt = new oilsReport();
7 oilsRptDisplaySelector = $('oils_rpt_display_selector');
8 oilsRptFilterSelector = $('oils_rpt_filter_selector');
11 hideMe($('oils_rpt_tree_loading'));
12 unHideMe($('oils_rpt_table'));
17 /* returns just the column name */
18 function oilsRptPathCol(path) {
19 var parts = path.split(/-/);
23 /* returns the IDL class of the selected column */
24 function oilsRptPathClass(path) {
25 var parts = path.split(/-/);
30 /* returns everything prior to the column name */
31 function oilsRptPathRel(path) {
32 var parts = path.split(/-/);
34 return parts.join('-');
37 /* creates a label "path" based on the column path */
38 function oilsRptMakeLabel(path) {
39 var parts = path.split(/-/);
41 for( var i = 0; i < parts.length; i++ ) {
44 str += oilsIDL[parts[i]].label;
46 var column = parts[i];
47 var data = oilsIDL[parts[i-1]];
48 var f = grep(data.fields,
49 function(j){return (j.name == column); })[0];
57 /* adds an item to the display window */
58 function oilsAddRptDisplayItem(path, name) {
59 if( ! oilsAddSelectorItem(oilsRptDisplaySelector, path, name) )
62 /* add the selected columns to the report output */
63 name = (name) ? name : oilsRptPathCol(path);
64 var param = oilsRptNextParam();
66 /* add this item to the select blob */
67 oilsRpt.def.select.push( {
68 relation:oilsRptPathRel(path),
69 column:oilsRptPathCol(path),
73 mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path));
74 oilsRpt.params[param] = name;
78 /* takes a column path and builds a from-clause object for the path */
79 function oilsRptBuildFromClause(path) {
80 var parts = path.split(/-/);
81 //var obj = {from : {}};
85 for( var i = 0; i < parts.length; i += 2 ) {
88 var node = oilsIDL[parts[i]];
89 var field = oilsRptFindField(node, col);
90 newpath = (newpath) ? newpath + '-'+ cls : cls;
92 tobj.table = node.table;
94 _debug('field type is ' + field.type);
95 if( i == (parts.length - 2) ) break;
101 if( field.type == 'link' )
102 tobj.key = field.key;
104 newpath = newpath + '-'+ col;
107 _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj)));
112 /* removes a specific item from the display window */
113 function oilsDelDisplayItem(val) {
114 oilsDelSelectorItem(oilsRptDisplaySelector, val);
117 /* removes selected items from the display window */
118 function oilsDelSelectedDisplayItems() {
119 var list = oilsDelSelectedItems(oilsRptDisplaySelector);
121 /* remove the de-selected columns from the report output */
122 oilsRpt.def.select = grep( oilsRpt.def.select,
124 for( var j = 0; j < list.length; j++ ) {
126 if( oilsRptPathRel(d) == i.relation
127 && oilsRptPathCol(d) == i.column ) {
128 var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
129 if( param ) delete oilsRpt.params[param];
136 if(!oilsRpt.def.select) oilsRpt.def.select = [];
138 for( var j = 0; j < list.length; j++ )
139 oilsRptPruneFromClause(list[j]);
144 /* for each item in the path list, remove the associated data
145 from the "from" clause */
146 function oilsRptPruneFromClause(pathlist) {
149 /* adds an item to the display window */
150 function oilsAddRptFilterItem(val) {
151 oilsAddSelectorItem(oilsRptFilterSelector, val);
154 /* removes a specific item from the display window */
155 function oilsDelFilterItem(val) {
156 oilsDelSelectorItem(oilsRptFilterSelector, val);
159 /* removes selected items from the display window */
160 function oilsDelSelectedFilterItems() {
161 oilsDelSelectedItems(oilsRptFilterSelector);
165 /* adds an item to the display window */
166 function oilsAddSelectorItem(sel, val, name) {
167 name = (name) ? name : oilsRptMakeLabel(val);
168 _debug("adding selector item "+name+' = ' +val);
169 for( var i = 0; i < sel.options.length; i++ ) {
170 var opt = sel.options[i];
171 if( opt.value == val ) return false;
173 insertSelectorVal( sel, -1, name, val );
178 /* removes a specific item from the display window */
179 function oilsDelSelectorItem(sel, val) {
180 _debug("deleting selector item "+val);
181 var opts = sel.options;
182 for( var i = 0; i < opts.length; i++ ) {
184 if( opt.value == val ) {
185 if( i == opts.length - 1 )
187 else opts[i] = opts[i+1];
193 /* removes selected items from the display window */
194 function oilsDelSelectedItems(sel) {
195 var list = getSelectedList(sel);
196 for( var i = 0; i < list.length; i++ )
197 oilsDelSelectorItem(sel, list[i]);
202 /* hides the different field editor tabs */
203 function oilsRptHideEditorDivs() {
204 hideMe($('oils_rpt_tform_div'));
205 hideMe($('oils_rpt_filter_div'));
206 hideMe($('oils_rpt_agg_filter_div'));
211 This draws the 3-tabbed window containing the transform,
212 filter, and aggregate filter picker window
214 function oilsRptDrawDataWindow(path) {
215 var col = oilsRptPathCol(path);
216 var cls = oilsRptPathClass(path);
217 var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
218 _debug("setting update data window for column "+col+' on class '+cls);
220 var div = $('oils_rpt_column_editor');
222 /* don't let them see the floating div until the position is fully determined */
223 div.style.visibility='hidden';
225 oilsRptDrawTransformWindow(path, col, cls, field);
227 $('oils_rpt_column_editor_close_button').onclick = function(){hideMe(div);};
228 buildFloatingDiv(div, 600);
229 div.style.visibility='visible';
231 /* focus after all the shifting to make sure the div is at least visible */
232 $('oils_rpt_tform_label_input').focus();
234 /* give the tab links behavior */
235 $('oils_rpt_tform_tab').onclick =
236 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_tform_div'))};
237 $('oils_rpt_filter_tab').onclick =
238 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_filter_div'))};
239 $('oils_rpt_agg_filter_tab').onclick =
240 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_agg_filter_div'))};
244 /* draws the transform window */
245 function oilsRptDrawTransformWindow(path, col, cls, field) {
246 appendClear($('oils_rpt_tform_label'), text(oilsRptMakeLabel(path)));
247 $('oils_rpt_tform_label_input').value = oilsRptMakeLabel(path);
249 $('oils_rpt_tform_submit').onclick =
250 function(){ oilsAddRptDisplayItem(path, $('oils_rpt_tform_label_input').value) };
252 $('oils_rpt_tform_label_input').focus();
253 $('oils_rpt_tform_label_input').select();
255 if( field.datatype == 'timestamp' )
256 unHideMe($('oils_rpt_tform_date_div'));