]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_builder.js
more grunt work
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_builder.js
1 function oilsInitReportBuilder() {
2         oilsInitReports();
3         oilsRpt = new oilsReport();
4         oilsRptDisplaySelector  = $('oils_rpt_display_selector');
5         oilsRptFilterSelector   = $('oils_rpt_filter_selector');
6         oilsDrawRptTree(
7                 function() { 
8                         hideMe($('oils_rpt_tree_loading')); 
9                         unHideMe($('oils_rpt_table')); 
10                 }
11         );
12 }
13
14
15
16 function oilsRptSplitPath(path) {
17         var parts = path.split(/-/);
18         var column = parts.pop();
19         return [ parts.join('-'), column ];
20 }
21
22 function oilsRptMakeLabel(path) {
23         var parts = path.split(/-/);
24         var str = '';
25         for( var i = 0; i < parts.length; i++ ) {
26                 if(i%2 == 0) {
27                         if( i == 0 )
28                                 str += oilsIDL[parts[i]].label;
29                 } else {
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];
33                         str += ":"+f.label;
34                 }
35         }
36         return str;
37 }
38
39
40 /* adds an item to the display window */
41 function oilsAddRptDisplayItem(val, name) {
42         if( ! oilsAddSelectorItem(oilsRptDisplaySelector, val, name) ) 
43                 return;
44
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;
51         oilsRptDebug();
52 }
53
54 /* removes a specific item from the display window */
55 function oilsDelDisplayItem(val) {
56         oilsDelSelectorItem(oilsRptDisplaySelector, val);
57 }
58
59 /* removes selected items from the display window */
60 function oilsDelSelectedDisplayItems() {
61         var list = oilsDelSelectedItems(oilsRptDisplaySelector);
62
63         /* remove the de-selected columns from the report output */
64         oilsRpt.def.select = grep( oilsRpt.def.select, 
65                 function(i) {
66                         for( var j = 0; j < list.length; j++ ) {
67                                 var d = list[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];
72                                         return false;
73                                 }
74                         }
75                         return true;
76                 }
77         );
78         if(!oilsRpt.def.select) oilsRpt.def.select = [];
79         oilsRptDebug();
80 }
81
82
83 /* adds an item to the display window */
84 function oilsAddRptFilterItem(val) {
85         oilsAddSelectorItem(oilsRptFilterSelector, val);
86 }
87
88 /* removes a specific item from the display window */
89 function oilsDelFilterItem(val) {
90         oilsDelSelectorItem(oilsRptFilterSelector, val);
91 }
92
93 /* removes selected items from the display window */
94 function oilsDelSelectedFilterItems() {
95         oilsDelSelectedItems(oilsRptFilterSelector);
96 }
97
98
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;
106         }
107         insertSelectorVal( sel, -1, name, val );
108         return true;
109 }
110
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++ ) {
116                 var opt = opts[i];
117                 if( opt.value == val )  {
118                         if( i == opts.length - 1 ) 
119                                 opts[i] = null;
120                         else opts[i] = opts[i+1];
121                         return;
122                 }
123         }
124 }
125
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]);
131         return list;
132 }
133
134 function oilsRptHideEditorDivs() {
135         hideMe($('oils_rpt_tform_div'));
136         hideMe($('oils_rpt_filter_div'));
137         hideMe($('oils_rpt_agg_filter_div'));
138 }
139
140
141 /**
142   This draws the 3-tabbed window containing the transform,
143   filter, and aggregate filter picker window
144   */
145 function oilsRptDrawDataWindow(path) {
146
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);
152
153         var div = $('oils_rpt_column_editor');
154         unHideMe(div);
155         /* don't let them see the floating div until the position is fully determined */
156         div.style.visibility='hidden'; 
157
158         oilsRptDrawTransformWindow(path, col, cls, field);
159
160         $('oils_rpt_column_editor_close_button').onclick = function(){hideMe(div);};
161         buildFloatingDiv(div, 600);
162         div.style.visibility='visible';
163
164         /* focus after all the shifting to make sure the div is at least visible */
165         $('oils_rpt_tform_label_input').focus();
166
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'))};
174 }
175
176
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);
181
182         $('oils_rpt_tform_submit').onclick = 
183                 function(){ oilsAddRptDisplayItem(path, $('oils_rpt_tform_label_input').value) };
184
185         $('oils_rpt_tform_label_input').focus();
186         $('oils_rpt_tform_label_input').select();
187 }
188
189
190