1 function oilsInitReportBuilder() {
3 oilsRpt = new oilsReport();
4 oilsRptDisplaySelector = $('oils_rpt_display_selector');
5 oilsRptFilterSelector = $('oils_rpt_filter_selector');
8 hideMe($('oils_rpt_tree_loading'));
9 unHideMe($('oils_rpt_table'));
16 function oilsRptSplitPath(path) {
17 var parts = path.split(/-/);
18 var column = parts.pop();
19 return [ parts.join('-'), column ];
22 function oilsRptMakeLabel(path) {
23 var parts = path.split(/-/);
25 for( var i = 0; i < parts.length; i++ ) {
28 str += oilsIDL[parts[i]].label;
30 var column = parts[i];
31 var data = oilsIDL[parts[i-1]];
32 var f = grep(data.fields, function(j){return (j.name == column); })[0];
40 /* adds an item to the display window */
41 function oilsAddRptDisplayItem(val, name) {
42 if( ! oilsAddSelectorItem(oilsRptDisplaySelector, val, name) )
45 /* add the selected columns to the report output */
46 var splitp = oilsRptSplitPath(val);
47 name = (name) ? name : splitp[1];
48 var param = oilsRptNextParam();
49 oilsRpt.def.select.push( {relation:splitp[0], column:splitp[1], alias:param} );
50 oilsRpt.params[param] = name;
54 /* removes a specific item from the display window */
55 function oilsDelDisplayItem(val) {
56 oilsDelSelectorItem(oilsRptDisplaySelector, val);
59 /* removes selected items from the display window */
60 function oilsDelSelectedDisplayItems() {
61 var list = oilsDelSelectedItems(oilsRptDisplaySelector);
63 /* remove the de-selected columns from the report output */
64 oilsRpt.def.select = grep( oilsRpt.def.select,
66 for( var j = 0; j < list.length; j++ ) {
68 var arr = oilsRptSplitPath(d);
69 if( arr[0] == i.relation && arr[1] == i.column ) {
70 var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
71 if( param ) delete oilsRpt.params[param];
78 if(!oilsRpt.def.select) oilsRpt.def.select = [];
83 /* adds an item to the display window */
84 function oilsAddRptFilterItem(val) {
85 oilsAddSelectorItem(oilsRptFilterSelector, val);
88 /* removes a specific item from the display window */
89 function oilsDelFilterItem(val) {
90 oilsDelSelectorItem(oilsRptFilterSelector, val);
93 /* removes selected items from the display window */
94 function oilsDelSelectedFilterItems() {
95 oilsDelSelectedItems(oilsRptFilterSelector);
99 /* adds an item to the display window */
100 function oilsAddSelectorItem(sel, val, name) {
101 name = (name) ? name : oilsRptMakeLabel(val);
102 _debug("adding selector item "+name+' = ' +val);
103 for( var i = 0; i < sel.options.length; i++ ) {
104 var opt = sel.options[i];
105 if( opt.value == val ) return false;
107 insertSelectorVal( sel, -1, name, val );
111 /* removes a specific item from the display window */
112 function oilsDelSelectorItem(sel, val) {
113 _debug("deleting selector item "+val);
114 var opts = sel.options;
115 for( var i = 0; i < opts.length; i++ ) {
117 if( opt.value == val ) {
118 if( i == opts.length - 1 )
120 else opts[i] = opts[i+1];
126 /* removes selected items from the display window */
127 function oilsDelSelectedItems(sel) {
128 var list = getSelectedList(sel);
129 for( var i = 0; i < list.length; i++ )
130 oilsDelSelectorItem(sel, list[i]);
134 function oilsRptHideEditorDivs() {
135 hideMe($('oils_rpt_tform_div'));
136 hideMe($('oils_rpt_filter_div'));
137 hideMe($('oils_rpt_agg_filter_div'));
142 This draws the 3-tabbed window containing the transform,
143 filter, and aggregate filter picker window
145 function oilsRptDrawDataWindow(path) {
147 var parts = path.split(/-/);
148 var col = parts.pop();
149 var cls = parts.pop();
150 var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
151 _debug("setting update data window for column "+col+' on class '+cls);
153 var div = $('oils_rpt_column_editor');
155 /* don't let them see the floating div until the position is fully determined */
156 div.style.visibility='hidden';
158 oilsRptDrawTransformWindow(path, col, cls, field);
160 $('oils_rpt_column_editor_close_button').onclick = function(){hideMe(div);};
161 buildFloatingDiv(div, 600);
162 div.style.visibility='visible';
164 /* focus after all the shifting to make sure the div is at least visible */
165 $('oils_rpt_tform_label_input').focus();
167 /* give the tab links behavior */
168 $('oils_rpt_tform_tab').onclick =
169 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_tform_div'))};
170 $('oils_rpt_filter_tab').onclick =
171 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_filter_div'))};
172 $('oils_rpt_agg_filter_tab').onclick =
173 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_agg_filter_div'))};
177 /* draws the transform window */
178 function oilsRptDrawTransformWindow(path, col, cls, field) {
179 appendClear($('oils_rpt_tform_label'), text(oilsRptMakeLabel(path)));
180 $('oils_rpt_tform_label_input').value = oilsRptMakeLabel(path);
182 $('oils_rpt_tform_submit').onclick =
183 function(){ oilsAddRptDisplayItem(path, $('oils_rpt_tform_label_input').value) };
185 $('oils_rpt_tform_label_input').focus();
186 $('oils_rpt_tform_label_input').select();