]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_builder.js
more ui work
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_builder.js
1 function oilsRptSplitPath(path) {
2         var parts = path.split(/-/);
3         var column = parts.pop();
4         return [ parts.join('-'), column ];
5 }
6
7 function oilsRptMakeLabel(path) {
8         var parts = path.split(/-/);
9         var str = '';
10         for( var i = 0; i < parts.length; i++ ) {
11                 if(i%2 == 0) {
12                         if( i == 0 )
13                                 str += oilsIDL[parts[i]].label;
14                 } else {
15                         var column = parts[i];
16                         var data = oilsIDL[parts[i-1]];
17                         var f = grep(data.fields, function(j){return (j.name == column); })[0];
18                         str += ":"+f.label;
19                 }
20         }
21         return str;
22 }
23
24
25 /* adds an item to the display window */
26 function oilsAddRptDisplayItem(val, name) {
27         if( ! oilsAddSelectorItem(oilsRptDisplaySelector, val, name) ) 
28                 return;
29
30         /* add the selected columns to the report output */
31         var splitp = oilsRptSplitPath(val);
32         name = (name) ? name : splitp[1];
33         oilsRpt.select.push( {relation:splitp[0], column:splitp[1], alias:name} );
34         oilsRptDebug();
35 }
36
37 /* removes a specific item from the display window */
38 function oilsDelDisplayItem(val) {
39         oilsDelSelectorItem(oilsRptDisplaySelector, val);
40 }
41
42 /* removes selected items from the display window */
43 function oilsDelSelectedDisplayItems() {
44         var list = oilsDelSelectedItems(oilsRptDisplaySelector);
45
46         /* remove the de-selected columns from the report output */
47         oilsRpt.select = grep( oilsRpt.select, 
48                 function(i) {
49                         for( var j = 0; j < list.length; j++ ) {
50                                 var d = list[j];
51                                 var arr = oilsRptSplitPath(d);
52                                 _debug(arr);
53                                 if( arr[0] == i.relation && arr[1] == i.column ) return false;
54                         }
55                         return true;
56                 }
57         );
58         if(!oilsRpt.select) oilsRpt.select = [];
59         oilsRptDebug();
60 }
61
62
63 /* adds an item to the display window */
64 function oilsAddRptFilterItem(val) {
65         oilsAddSelectorItem(oilsRptFilterSelector, val);
66 }
67
68 /* removes a specific item from the display window */
69 function oilsDelFilterItem(val) {
70         oilsDelSelectorItem(oilsRptFilterSelector, val);
71 }
72
73 /* removes selected items from the display window */
74 function oilsDelSelectedFilterItems() {
75         oilsDelSelectedItems(oilsRptFilterSelector);
76 }
77
78
79 /* adds an item to the display window */
80 function oilsAddSelectorItem(sel, val, name) {
81         name = (name) ? name : oilsRptMakeLabel(val);
82         _debug("adding selector item "+name+' = ' +val);
83         for( var i = 0; i < sel.options.length; i++ ) {
84                 var opt = sel.options[i];
85                 if( opt.value == val ) return false;
86         }
87         insertSelectorVal( sel, -1, name, val );
88         return true;
89 }
90
91 /* removes a specific item from the display window */
92 function oilsDelSelectorItem(sel, val) {
93         _debug("deleting selector item "+val);
94         var opts = sel.options;
95         for( var i = 0; i < opts.length; i++ ) {
96                 var opt = opts[i];
97                 if( opt.value == val )  {
98                         if( i == opts.length - 1 ) 
99                                 opts[i] = null;
100                         else opts[i] = opts[i+1];
101                         return;
102                 }
103         }
104 }
105
106 /* removes selected items from the display window */
107 function oilsDelSelectedItems(sel) {
108         var list = getSelectedList(sel);
109         for( var i = 0; i < list.length; i++ ) 
110                 oilsDelSelectorItem(sel, list[i]);
111         return list;
112 }
113
114 function oilsRptHideEditorDivs() {
115         hideMe($('oils_rpt_tform_div'));
116         hideMe($('oils_rpt_filter_div'));
117         hideMe($('oils_rpt_agg_filter_div'));
118 }
119
120
121 function oilsRptDrawDataWindow(path) {
122
123         var parts = path.split(/-/);
124         var col = parts.pop();
125         var cls = parts.pop();
126         var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
127         _debug("setting update data window for column "+col+' on class '+cls);
128
129         var div = $('oils_rpt_column_editor');
130         unHideMe(div);
131         /* don't let them see the floating div until the position is fully determined */
132         div.style.visibility='hidden'; 
133
134         oilsRptDrawTransformWindow(path, col, cls, field);
135
136         $('oils_rpt_column_editor_close_button').onclick = function(){hideMe(div);};
137         buildFloatingDiv(div, 600);
138         div.style.visibility='visible';
139
140         /* focus after all the shifting to make sure the div is at least visible */
141         $('oils_rpt_tform_label_input').focus();
142
143
144         /* give the tab links behavior */
145         $('oils_rpt_tform_tab').onclick = 
146                 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_tform_div'))};
147         $('oils_rpt_filter_tab').onclick = 
148                 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_filter_div'))};
149         $('oils_rpt_agg_filter_tab').onclick = 
150                 function(){oilsRptHideEditorDivs();unHideMe($('oils_rpt_agg_filter_div'))};
151 }
152
153
154 function oilsRptDrawTransformWindow(path, col, cls, field) {
155         appendClear($('oils_rpt_tform_label'), text(oilsRptMakeLabel(path)));
156         $('oils_rpt_tform_label_input').value = oilsRptMakeLabel(path);
157
158         $('oils_rpt_tform_submit').onclick = 
159                 function(){ oilsAddRptDisplayItem(path, $('oils_rpt_tform_label_input').value) };
160
161         $('oils_rpt_tform_label_input').focus();
162         $('oils_rpt_tform_label_input').select();
163 }
164
165
166