Rev 7479 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2788 | guerimand | 1 | <script type="text/javascript"> |
7479 | bpr | 2 | /*<![CDATA[*/ |
12784 | obado | 3 | |
4 | /** |
||
5 | * chooselist, inspired by qfamsHAndler HTML_QuickForm_advmultiselect |
||
6 | |||
7 | * JavaScript functions to handle a multiselect element (Move elements between 2 select boxes) |
||
8 | * @author Laurent Laville <pear@laurent-laville.org> |
||
9 | * @copyright 2007-2009 Laurent Laville |
||
10 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
||
11 | * @website https://github.com/pear/HTML_QuickForm_advmultiselect |
||
12 | */ |
||
13 | |||
14 | |||
15 | /** |
||
16 | * QFAMS.moveSelection |
||
17 | * in double select box mode, to move current selection and update live counter |
||
18 | * |
||
19 | * @param dom element selectLeft Data source list |
||
20 | * @param dom element selectRight Target data list |
||
21 | * @param dom element selectHidden Full data source (selected, unselected) |
||
22 | * private usage |
||
23 | * @param string action Action name (add, remove, all, none, toggle) |
||
24 | */ |
||
2788 | guerimand | 25 | function moveSelections(selectLeft, selectRight, selectHidden, action) { |
12784 | obado | 26 | var isIE = /*@cc_on!@*/false; //IE detector |
27 | var source = null; |
||
28 | var target = null; |
||
29 | var option; |
||
30 | var c = null; |
||
31 | var s = null; |
||
32 | var i; |
||
33 | var maxFrom, maxTo; |
||
34 | |||
35 | if (action === 'add' || action === 'all' || action === 'toggle') { |
||
36 | source = selectLeft; |
||
37 | target = selectRight; |
||
38 | } else { |
||
39 | source = selectRight; |
||
40 | target = selectLeft; |
||
2788 | guerimand | 41 | } |
42 | // Don't do anything if nothing selected. Otherwise we throw javascript errors. |
||
12784 | obado | 43 | if (source.selectedIndex === -1 && (action === 'add' || action === 'remove')) { |
2788 | guerimand | 44 | return; |
45 | } |
||
12784 | obado | 46 | maxFrom = source.options.length; |
47 | maxTo = target.options.length; |
||
2788 | guerimand | 48 | |
12784 | obado | 49 | // check if target list is empty and remove fake empty option (tip to be XHTML compliant) |
50 | if (maxTo > 0 && target.options[0].value === "") { |
||
51 | target.removeAttribute("disabled"); |
||
52 | target.options[0] = null; |
||
53 | } |
||
54 | |||
2788 | guerimand | 55 | // Add items to the 'TO' list. |
12784 | obado | 56 | for (i = (maxFrom - 1); i >= 0; i--) { |
57 | if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) { |
||
58 | if (source.options[i].disabled === false) { |
||
59 | if (isIE) { |
||
60 | option = source.options[i].removeNode(true); |
||
61 | //option.selected = env.persistantSelection; |
||
62 | target.appendChild(option); |
||
63 | } else { |
||
64 | option = source.options[i].cloneNode(true); |
||
65 | //option.selected = env.persistantSelection; |
||
66 | target.options[target.options.length] = option; |
||
67 | } |
||
68 | } |
||
2788 | guerimand | 69 | } |
70 | } |
||
71 | |||
72 | // Remove items from the 'FROM' list. |
||
12784 | obado | 73 | if (!isIE) { |
74 | for (i = (maxFrom - 1); i >= 0; i--) { |
||
75 | if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) { |
||
76 | if (source.options[i].disabled === false) { |
||
77 | source.options[i] = null; |
||
78 | } |
||
79 | } |
||
2788 | guerimand | 80 | } |
81 | } |
||
82 | |||
12784 | obado | 83 | // Add items to the 'FROM' list for toggle function |
84 | if (action === 'toggle') { |
||
85 | for (i = (maxTo - 1); i >= 0; i--) { |
||
86 | if (target.options[i].disabled === false) { |
||
87 | if (isIE) { |
||
88 | option = target.options[i].removeNode(true); |
||
89 | //option.selected = env.persistantSelection; |
||
90 | source.appendChild(option); |
||
91 | } else { |
||
92 | option = target.options[i].cloneNode(true); |
||
93 | //option.selected = env.persistantSelection; |
||
94 | source.options[source.options.length] = option; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | if (!isIE) { |
||
99 | for (i = (maxTo - 1); i >= 0; i--) { |
||
100 | if (target.options[i].disabled === false) { |
||
101 | target.options[i] = null; |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
2788 | guerimand | 107 | // Set the appropriate items as 'selected in the hidden select. |
108 | // These are the values that will actually be posted with the form. |
||
109 | updateHidden(selectHidden, selectRight); |
||
110 | } |
||
111 | |||
12784 | obado | 112 | /* |
113 | * QFAMS.updateHidden |
||
114 | * updates the private list that handle selection of all elements (selected and unselected) |
||
115 | * @param dom element h hidden list (contains all elements) |
||
116 | * @param dom element r selection list (contains only elements selected) |
||
117 | */ |
||
118 | function updateHidden(h, r) { |
||
119 | var i; |
||
120 | |||
121 | for(i = h.options.length - 1 ; i >= 0 ; i--) |
||
122 | { |
||
123 | //h.options[i].selected = false; |
||
124 | h.remove(i); |
||
2788 | guerimand | 125 | } |
126 | |||
12784 | obado | 127 | for (i = 0; i < r.length; i++) { |
2788 | guerimand | 128 | h.options[h.length] = new Option(r.options[i].text, r.options[i].value); |
12784 | obado | 129 | h.options[h.length - 1].selected = true; |
2788 | guerimand | 130 | } |
131 | } |
||
132 | |||
12784 | obado | 133 | /** |
134 | * QFAMS.moveUp |
||
135 | * end-user may arrange and element up to the selection list |
||
136 | * |
||
137 | * @param dom element l selection list (contains only elements selected) |
||
138 | * @param dom element h hidden list (contains all elements) |
||
139 | * |
||
140 | */ |
||
141 | function moveUp(l, h) { |
||
2788 | guerimand | 142 | var indice = l.selectedIndex; |
143 | if (indice < 0) { |
||
144 | return; |
||
145 | } |
||
146 | if (indice > 0) { |
||
12784 | obado | 147 | moveSwap(l, indice, indice - 1); |
2788 | guerimand | 148 | updateHidden(h, l); |
149 | } |
||
150 | } |
||
151 | |||
12784 | obado | 152 | /** |
153 | * QFAMS.moveDown |
||
154 | * end-user may arrange and element down to the selection list |
||
155 | * |
||
156 | * @param dom element l selection list (contains only elements selected) |
||
157 | * @param dom element h hidden list (contains all elements) |
||
158 | * |
||
159 | */ |
||
160 | function moveDown(l, h) { |
||
2788 | guerimand | 161 | var indice = l.selectedIndex; |
162 | if (indice < 0) { |
||
163 | return; |
||
164 | } |
||
12784 | obado | 165 | if (indice < l.options.length - 1) { |
166 | moveSwap(l, indice, indice + 1); |
||
2788 | guerimand | 167 | updateHidden(h, l); |
168 | } |
||
169 | } |
||
170 | |||
12784 | obado | 171 | /** |
172 | * QFAMS.moveSwap |
||
173 | * end-user may invert two elements position in the selection list |
||
174 | * |
||
175 | * @param dom element l selection list (contains only elements selected) |
||
176 | * @param integer i element source indice |
||
177 | * @param integer j element target indice |
||
178 | * |
||
179 | */ |
||
2788 | guerimand | 180 | function moveSwap(l,i,j) { |
181 | var valeur = l.options[i].value; |
||
182 | var texte = l.options[i].text; |
||
183 | l.options[i].value = l.options[j].value; |
||
184 | l.options[i].text = l.options[j].text; |
||
185 | l.options[j].value = valeur; |
||
186 | l.options[j].text = texte; |
||
187 | l.selectedIndex = j |
||
188 | } |
||
189 | |||
12784 | obado | 190 | |
191 | /** |
||
192 | * filterSelectExoSheet |
||
193 | * Display only exo corresponding to specific sheet Id in a select box |
||
194 | * The Sheet Id is the value selected by selectFilter (it can be a list like 1,2,3) |
||
195 | * |
||
196 | * @param dom element selectbox selection list |
||
197 | * @param dom element selectFilter WIMS Sheet Id |
||
198 | * |
||
199 | */ |
||
200 | function filterSelectExoSheet(selectTarget, selectFilter) { |
||
201 | var i,current; |
||
202 | // Converts selectFilter to an array |
||
203 | var sheetIds = selectFilter.value.split(','); |
||
204 | |||
205 | for(i = selectTarget.options.length - 1 ; i >= 0 ; i--){ |
||
206 | current = selectTarget.options[i] |
||
207 | if (sheetIds.indexOf(current.dataset.sheetid) >= 0){ |
||
208 | selectTarget.options[i].style.display = "block"; |
||
209 | } |
||
210 | else{ |
||
211 | selectTarget.options[i].style.display = "none"; |
||
212 | selectTarget.options[i].selected = false; |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | |||
2788 | guerimand | 217 | /* end javascript for HTML_QuickForm_advmultiselect */ |
7479 | bpr | 218 | /*]]>*/ |
2788 | guerimand | 219 | </script> |