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