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