Mercurial > kallithea
comparison rhodecode/templates/admin/users_groups/users_group_edit.html @ 1961:f48bce87475b beta
code cleanup
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 28 Jan 2012 00:51:13 +0200 |
parents | 4a7de41dc22a |
children | 6776f4e569d7 |
comparison
equal
deleted
inserted
replaced
1960:3daa7093fbbb | 1961:f48bce87475b |
---|---|
138 %endfor | 138 %endfor |
139 </ul> | 139 </ul> |
140 </div> | 140 </div> |
141 </div> | 141 </div> |
142 <script type="text/javascript"> | 142 <script type="text/javascript"> |
143 YAHOO.util.Event.onDOMReady(function(){ | 143 YAHOO.util.Event.onDOMReady(function(){ |
144 var D = YAHOO.util.Dom; | 144 var D = YAHOO.util.Dom; |
145 var E = YAHOO.util.Event; | 145 var E = YAHOO.util.Event; |
146 | 146 |
147 //definition of containers ID's | 147 //definition of containers ID's |
148 var available_container = 'available_members'; | 148 var available_container = 'available_members'; |
149 var selected_container = 'users_group_members'; | 149 var selected_container = 'users_group_members'; |
150 | 150 |
151 //form containing containers id | 151 //form containing containers id |
152 var form_id = 'edit_users_group'; | 152 var form_id = 'edit_users_group'; |
153 | 153 |
154 //temp container for selected storage. | 154 //temp container for selected storage. |
155 var cache = new Array(); | 155 var cache = new Array(); |
156 var av_cache = new Array(); | 156 var av_cache = new Array(); |
157 var c = D.get(selected_container); | 157 var c = D.get(selected_container); |
158 var ac = D.get(available_container); | 158 var ac = D.get(available_container); |
159 | 159 |
160 //get only selected options for further fullfilment | 160 //get only selected options for further fullfilment |
161 for(var i = 0;node =c.options[i];i++){ | 161 for(var i = 0;node =c.options[i];i++){ |
162 if(node.selected){ | 162 if(node.selected){ |
163 //push selected to my temp storage left overs :) | 163 //push selected to my temp storage left overs :) |
164 cache.push(node); | 164 cache.push(node); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 //clear 'selected' select | 168 //get all available options to cache |
169 //c.options.length = 0; | 169 for(var i = 0;node =ac.options[i];i++){ |
170 | 170 //push selected to my temp storage left overs :) |
171 //fill it with remembered options | 171 av_cache.push(node); |
172 //for(var i = 0;node = cache[i];i++){ | 172 } |
173 // c.options[i]=new Option(node.text, node.value, false, false); | 173 |
174 //} | 174 //fill available only with those not in choosen |
175 | 175 ac.options.length=0; |
176 | 176 tmp_cache = new Array(); |
177 //get all available options to cache | 177 |
178 for(var i = 0;node =ac.options[i];i++){ | 178 for(var i = 0;node = av_cache[i];i++){ |
179 //push selected to my temp storage left overs :) | 179 var add = true; |
180 av_cache.push(node); | 180 for(var i2 = 0;node_2 = cache[i2];i2++){ |
181 } | 181 if(node.value == node_2.value){ |
182 | 182 add=false; |
183 //fill available only with those not in choosen | 183 break; |
184 ac.options.length=0; | 184 } |
185 tmp_cache = new Array(); | 185 } |
186 | 186 if(add){ |
187 for(var i = 0;node = av_cache[i];i++){ | 187 tmp_cache.push(new Option(node.text, node.value, false, false)); |
188 var add = true; | 188 } |
189 for(var i2 = 0;node_2 = cache[i2];i2++){ | 189 } |
190 if(node.value == node_2.value){ | 190 |
191 add=false; | 191 for(var i = 0;node = tmp_cache[i];i++){ |
192 break; | 192 ac.options[i] = node; |
193 } | 193 } |
194 } | 194 |
195 if(add){ | 195 function prompts_action_callback(e){ |
196 tmp_cache.push(new Option(node.text, node.value, false, false)); | 196 |
197 } | 197 var choosen = D.get(selected_container); |
198 } | 198 var available = D.get(available_container); |
199 | 199 |
200 for(var i = 0;node = tmp_cache[i];i++){ | 200 //get checked and unchecked options from field |
201 ac.options[i] = node; | 201 function get_checked(from_field){ |
202 } | 202 //temp container for storage. |
203 | 203 var sel_cache = new Array(); |
204 function prompts_action_callback(e){ | 204 var oth_cache = new Array(); |
205 | 205 |
206 var choosen = D.get(selected_container); | 206 for(var i = 0;node = from_field.options[i];i++){ |
207 var available = D.get(available_container); | 207 if(node.selected){ |
208 | 208 //push selected fields :) |
209 //get checked and unchecked options from field | 209 sel_cache.push(node); |
210 function get_checked(from_field){ | 210 } |
211 //temp container for storage. | 211 else{ |
212 var sel_cache = new Array(); | 212 oth_cache.push(node) |
213 var oth_cache = new Array(); | 213 } |
214 | 214 } |
215 for(var i = 0;node = from_field.options[i];i++){ | 215 |
216 if(node.selected){ | 216 return [sel_cache,oth_cache] |
217 //push selected fields :) | 217 } |
218 sel_cache.push(node); | 218 |
219 } | 219 //fill the field with given options |
220 else{ | 220 function fill_with(field,options){ |
221 oth_cache.push(node) | 221 //clear firtst |
222 } | 222 field.options.length=0; |
223 } | 223 for(var i = 0;node = options[i];i++){ |
224 | 224 field.options[i]=new Option(node.text, node.value, |
225 return [sel_cache,oth_cache] | 225 false, false); |
226 } | 226 } |
227 | 227 |
228 //fill the field with given options | 228 } |
229 function fill_with(field,options){ | 229 //adds to current field |
230 //clear firtst | 230 function add_to(field,options){ |
231 field.options.length=0; | 231 for(var i = 0;node = options[i];i++){ |
232 for(var i = 0;node = options[i];i++){ | 232 field.appendChild(new Option(node.text, node.value, |
233 field.options[i]=new Option(node.text, node.value, | 233 false, false)); |
234 false, false); | 234 } |
235 } | 235 } |
236 | 236 |
237 } | 237 // add action |
238 //adds to current field | 238 if (this.id=='add_element'){ |
239 function add_to(field,options){ | 239 var c = get_checked(available); |
240 for(var i = 0;node = options[i];i++){ | 240 add_to(choosen,c[0]); |
241 field.appendChild(new Option(node.text, node.value, | 241 fill_with(available,c[1]); |
242 false, false)); | 242 } |
243 } | 243 // remove action |
244 } | 244 if (this.id=='remove_element'){ |
245 | 245 var c = get_checked(choosen); |
246 // add action | 246 add_to(available,c[0]); |
247 if (this.id=='add_element'){ | 247 fill_with(choosen,c[1]); |
248 var c = get_checked(available); | 248 } |
249 add_to(choosen,c[0]); | 249 // add all elements |
250 fill_with(available,c[1]); | 250 if(this.id=='add_all_elements'){ |
251 } | 251 for(var i=0; node = available.options[i];i++){ |
252 // remove action | 252 choosen.appendChild(new Option(node.text, |
253 if (this.id=='remove_element'){ | 253 node.value, false, false)); |
254 var c = get_checked(choosen); | 254 } |
255 add_to(available,c[0]); | 255 available.options.length = 0; |
256 fill_with(choosen,c[1]); | 256 } |
257 } | 257 //remove all elements |
258 // add all elements | 258 if(this.id=='remove_all_elements'){ |
259 if(this.id=='add_all_elements'){ | 259 for(var i=0; node = choosen.options[i];i++){ |
260 for(var i=0; node = available.options[i];i++){ | 260 available.appendChild(new Option(node.text, |
261 choosen.appendChild(new Option(node.text, | 261 node.value, false, false)); |
262 node.value, false, false)); | 262 } |
263 } | 263 choosen.options.length = 0; |
264 available.options.length = 0; | 264 } |
265 } | 265 |
266 //remove all elements | 266 } |
267 if(this.id=='remove_all_elements'){ | 267 |
268 for(var i=0; node = choosen.options[i];i++){ | 268 E.addListener(['add_element','remove_element', |
269 available.appendChild(new Option(node.text, | 269 'add_all_elements','remove_all_elements'],'click', |
270 node.value, false, false)); | 270 prompts_action_callback) |
271 } | 271 |
272 choosen.options.length = 0; | 272 E.addListener(form_id,'submit',function(){ |
273 } | 273 var choosen = D.get(selected_container); |
274 | 274 for (var i = 0; i < choosen.options.length; i++) { |
275 } | 275 choosen.options[i].selected = 'selected'; |
276 | 276 } |
277 | 277 }); |
278 E.addListener(['add_element','remove_element', | 278 }); |
279 'add_all_elements','remove_all_elements'],'click', | |
280 prompts_action_callback) | |
281 | |
282 E.addListener(form_id,'submit',function(){ | |
283 var choosen = D.get(selected_container); | |
284 for (var i = 0; i < choosen.options.length; i++) { | |
285 choosen.options[i].selected = 'selected'; | |
286 } | |
287 }) | |
288 }); | |
289 </script> | 279 </script> |
290 </%def> | 280 </%def> |