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