initial commit
[gitredmine.git] / public / javascripts / select_list_move.js
blob1ced88232217fb85dd8e3b5f03ec1427480985f5
1 var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);\r
2 \r
3 function addOption(theSel, theText, theValue)\r
4 {\r
5   var newOpt = new Option(theText, theValue);\r
6   var selLength = theSel.length;\r
7   theSel.options[selLength] = newOpt;\r
8 }\r
9 \r
10 function deleteOption(theSel, theIndex)\r
11 \r
12   var selLength = theSel.length;\r
13   if(selLength>0)\r
14   {\r
15     theSel.options[theIndex] = null;\r
16   }\r
17 }\r
19 function moveOptions(theSelFrom, theSelTo)\r
20 {\r
21   \r
22   var selLength = theSelFrom.length;\r
23   var selectedText = new Array();\r
24   var selectedValues = new Array();\r
25   var selectedCount = 0;\r
26   \r
27   var i;\r
28   \r
29   for(i=selLength-1; i>=0; i--)\r
30   {\r
31     if(theSelFrom.options[i].selected)\r
32     {\r
33       selectedText[selectedCount] = theSelFrom.options[i].text;\r
34       selectedValues[selectedCount] = theSelFrom.options[i].value;\r
35       deleteOption(theSelFrom, i);\r
36       selectedCount++;\r
37     }\r
38   }\r
39   \r
40   for(i=selectedCount-1; i>=0; i--)\r
41   {\r
42     addOption(theSelTo, selectedText[i], selectedValues[i]);\r
43   }\r
44   \r
45   if(NS4) history.go(0);\r
46 }\r
48 function selectAllOptions(id)\r
49 {\r
50   var select = $(id);\r
51   for (var i=0; i<select.options.length; i++) {\r
52     select.options[i].selected = true;\r
53   }\r
54 }\r