annotate public/javascripts/select_list_move.js @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents 433d4f72a19b
children 261b3d9a4903
rev   line source
Chris@1115 1 var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
Chris@1115 2
Chris@1115 3 function addOption(theSel, theText, theValue)
Chris@1115 4 {
Chris@1115 5 var newOpt = new Option(theText, theValue);
Chris@1115 6 var selLength = theSel.length;
Chris@1115 7 theSel.options[selLength] = newOpt;
Chris@1115 8 }
Chris@1115 9
Chris@1115 10 function swapOptions(theSel, index1, index2)
Chris@1115 11 {
Chris@1115 12 var text, value;
Chris@1115 13 text = theSel.options[index1].text;
Chris@1115 14 value = theSel.options[index1].value;
Chris@1115 15 theSel.options[index1].text = theSel.options[index2].text;
Chris@1115 16 theSel.options[index1].value = theSel.options[index2].value;
Chris@1115 17 theSel.options[index2].text = text;
Chris@1115 18 theSel.options[index2].value = value;
Chris@1115 19 }
Chris@1115 20
Chris@1115 21 function deleteOption(theSel, theIndex)
Chris@1115 22 {
Chris@1115 23 var selLength = theSel.length;
Chris@1115 24 if(selLength>0)
Chris@1115 25 {
Chris@1115 26 theSel.options[theIndex] = null;
Chris@1115 27 }
Chris@1115 28 }
Chris@1115 29
Chris@1115 30 function moveOptions(theSelFrom, theSelTo)
Chris@1115 31 {
Chris@1115 32
Chris@1115 33 var selLength = theSelFrom.length;
Chris@1115 34 var selectedText = new Array();
Chris@1115 35 var selectedValues = new Array();
Chris@1115 36 var selectedCount = 0;
Chris@1115 37
Chris@1115 38 var i;
Chris@1115 39
Chris@1115 40 for(i=selLength-1; i>=0; i--)
Chris@1115 41 {
Chris@1115 42 if(theSelFrom.options[i].selected)
Chris@1115 43 {
Chris@1115 44 selectedText[selectedCount] = theSelFrom.options[i].text;
Chris@1115 45 selectedValues[selectedCount] = theSelFrom.options[i].value;
Chris@1115 46 deleteOption(theSelFrom, i);
Chris@1115 47 selectedCount++;
Chris@1115 48 }
Chris@1115 49 }
Chris@1115 50
Chris@1115 51 for(i=selectedCount-1; i>=0; i--)
Chris@1115 52 {
Chris@1115 53 addOption(theSelTo, selectedText[i], selectedValues[i]);
Chris@1115 54 }
Chris@1115 55
Chris@1115 56 if(NS4) history.go(0);
Chris@1115 57 }
Chris@1115 58
Chris@1115 59 function moveOptionUp(theSel) {
Chris@1115 60 var index = theSel.selectedIndex;
Chris@1115 61 if (index > 0) {
Chris@1115 62 swapOptions(theSel, index-1, index);
Chris@1115 63 theSel.selectedIndex = index-1;
Chris@1115 64 }
Chris@1115 65 }
Chris@1115 66
Chris@1115 67 function moveOptionDown(theSel) {
Chris@1115 68 var index = theSel.selectedIndex;
Chris@1115 69 if (index < theSel.length - 1) {
Chris@1115 70 swapOptions(theSel, index, index+1);
Chris@1115 71 theSel.selectedIndex = index+1;
Chris@1115 72 }
Chris@1115 73 }
Chris@1115 74
Chris@1115 75 // OK
Chris@1115 76 function selectAllOptions(id)
Chris@1115 77 {
Chris@1115 78 var select = $('#'+id);/*
Chris@1115 79 for (var i=0; i<select.options.length; i++) {
Chris@1115 80 select.options[i].selected = true;
Chris@1115 81 }*/
Chris@1115 82 select.children('option').attr('selected', true);
Chris@1115 83 }