multi-set reporting based on pivot of 1 grouping column
[Evergreen.git] / Open-ILS / src / reporter / templates / select_sorter.js
1 <script language="javascript">
2
3 function field_add_remove (x) {
4         var field = x.name;
5         if (x.checked) {
6                 Widget.Select.addOption('output_order',field, outputs[field]);
7                 Widget.Select.addOption('pivot_col',field, outputs[field]);
8         } else {
9                 Widget.Select.removeOption('output_order',field);
10                 Widget.Select.removeOption('pivot_col',field);
11         }
12         return true;
13 }
14
15
16 if ( typeof Widget == "undefined" ) Widget = {};
17
18 if ( typeof Widget.Select == "undefined" ) Widget.Select = {};
19
20 Widget.Select.VERSION = '0.01';
21
22
23 Widget.Select.selectAll = function (source){
24         if (typeof(source) != 'object') source = document.getElementById(source);
25         var l = source.options.length;
26     for (var j=0; j<l; j++){
27         source.options[j].selected = true;
28     }
29 }
30
31
32 Widget.Select.selectNone = function(source){
33         if (typeof(source) != 'object') source = document.getElementById(source);
34         var l = source.options.length;
35     for (var j=0; j<l; j++){
36         source.options[j].selected = false;
37     }
38 }
39
40
41 Widget.Select.invertSelection = function(source){
42         if (typeof(source) != 'object') source = document.getElementById(source);
43         var l = source.options.length;
44     for (var j=0; j<l; j++){
45         source.options[j].selected = ! source.options[j].selected;
46     }
47 }
48
49 Widget.Select._moveOption = function(e, source, s_idx, target){
50                         var opt = new Option(
51                                 e.text, e.value);
52                         opt.selected = e.selected;
53                         target.options[target.options.length] = opt;
54                         source.options[s_idx] = null;
55 }
56
57
58 Widget.Select.moveSelectedOptionsUp = function(source){
59         if (typeof(source) != 'object') source = document.getElementById(source);
60         var l = source.options.length;
61     for (var j=0; j<l; j++){
62         
63                 var e = source.options[0];
64                 if (e.selected){
65                         Widget.Select._moveOption(e, source, 0, source, l);
66                         continue;
67                 }
68                 
69         
70                 while (j<l-1){
71                         var f= source.options[1];
72                         if (!f.selected) break;
73                         Widget.Select._moveOption(f, source, 1, source, l);
74                         j++;
75                 }
76         
77                 Widget.Select._moveOption(e, source, 0, source, l);
78         }
79                         
80 }
81
82
83 Widget.Select.moveSelectedOptionsDown = function(source){
84         if (typeof(source) != 'object') source = document.getElementById(source);
85         var l = source.options.length;
86     var skip=0;
87     for (var j=0; j<l; j++){
88                 var e = source.options[0];
89                 if (skip == 0){
90                         if (e.selected){
91                                 for (var i=1;i<l-j; i++){
92                                         var f = source.options[i];
93                                         if (! f.selected){
94                                                 Widget.Select._moveOption(f, source, i, source, l);
95                                                 j++;
96                                                 break;
97                                         }
98                                         skip++;
99                                         
100                                 }
101                                 
102                         }
103                 }else{
104                         skip--;
105                 }       
106                 
107                 Widget.Select._moveOption(e, source, 0, source, l);
108                 
109         }
110                         
111 }
112
113
114
115 Widget.Select.moveSelectedOptionsTo = function(source, target){
116         if (typeof(source) != 'object') source = document.getElementById(source);
117         if (typeof(target) != 'object') target = document.getElementById(target);
118         for (var i=0; i<source.options.length; i++){
119                 var e = source.options[i];
120                 if(e.selected){
121                         Widget.Select._moveOption(e,source, i, target, target.options.length);
122                         i--;
123                 }
124         }
125 }
126
127
128
129
130
131
132 Widget.Select.addOption = function (target,val,l) {
133         if (typeof(target) != 'object') target = document.getElementById(target);
134         target.options[target.options.length] = new Option( l, val );
135 }
136
137 Widget.Select.removeOption = function (target, val) {
138         if (typeof(target) != 'object') target = document.getElementById(target);
139         var l = target.options.length;
140         for ( var i = 0; i<l; i++) {
141                 if (target.options[i].value == val) {
142                         target.options[i] = null;
143                         break;
144                 }
145         }
146 }
147
148
149
150 </script>