annotate public/javascripts/select_list_move.js @ 1516:b450a9d58aed redmine-2.4

Update to Redmine SVN revision 13356 on 2.4-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:28:31 +0100
parents 261b3d9a4903
children dffacf8a6908
rev   line source
Chris@1115 1 var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
Chris@1115 2
Chris@1464 3 function addOption(theSel, theText, theValue) {
Chris@1115 4 var newOpt = new Option(theText, theValue);
Chris@1115 5 var selLength = theSel.length;
Chris@1115 6 theSel.options[selLength] = newOpt;
Chris@1115 7 }
Chris@1115 8
Chris@1464 9 function swapOptions(theSel, index1, index2) {
Chris@1115 10 var text, value;
Chris@1115 11 text = theSel.options[index1].text;
Chris@1115 12 value = theSel.options[index1].value;
Chris@1115 13 theSel.options[index1].text = theSel.options[index2].text;
Chris@1115 14 theSel.options[index1].value = theSel.options[index2].value;
Chris@1115 15 theSel.options[index2].text = text;
Chris@1115 16 theSel.options[index2].value = value;
Chris@1115 17 }
Chris@1115 18
Chris@1464 19 function deleteOption(theSel, theIndex) {
Chris@1115 20 var selLength = theSel.length;
Chris@1464 21 if (selLength > 0) {
Chris@1115 22 theSel.options[theIndex] = null;
Chris@1115 23 }
Chris@1115 24 }
Chris@1115 25
Chris@1464 26 function moveOptions(theSelFrom, theSelTo) {
Chris@1115 27 var selLength = theSelFrom.length;
Chris@1115 28 var selectedText = new Array();
Chris@1115 29 var selectedValues = new Array();
Chris@1115 30 var selectedCount = 0;
Chris@1115 31 var i;
Chris@1464 32 for (i = selLength - 1; i >= 0; i--) {
Chris@1464 33 if (theSelFrom.options[i].selected) {
Chris@1115 34 selectedText[selectedCount] = theSelFrom.options[i].text;
Chris@1115 35 selectedValues[selectedCount] = theSelFrom.options[i].value;
Chris@1115 36 deleteOption(theSelFrom, i);
Chris@1115 37 selectedCount++;
Chris@1115 38 }
Chris@1115 39 }
Chris@1464 40 for (i = selectedCount - 1; i >= 0; i--) {
Chris@1115 41 addOption(theSelTo, selectedText[i], selectedValues[i]);
Chris@1115 42 }
Chris@1464 43 if (NS4) history.go(0);
Chris@1115 44 }
Chris@1115 45
Chris@1115 46 function moveOptionUp(theSel) {
Chris@1115 47 var index = theSel.selectedIndex;
Chris@1115 48 if (index > 0) {
Chris@1115 49 swapOptions(theSel, index-1, index);
Chris@1115 50 theSel.selectedIndex = index-1;
Chris@1115 51 }
Chris@1115 52 }
Chris@1115 53
Chris@1115 54 function moveOptionDown(theSel) {
Chris@1115 55 var index = theSel.selectedIndex;
Chris@1115 56 if (index < theSel.length - 1) {
Chris@1115 57 swapOptions(theSel, index, index+1);
Chris@1115 58 theSel.selectedIndex = index+1;
Chris@1115 59 }
Chris@1115 60 }
Chris@1115 61
Chris@1115 62 // OK
Chris@1464 63 function selectAllOptions(id) {
Chris@1464 64 var select = $('#'+id);
Chris@1115 65 select.children('option').attr('selected', true);
Chris@1115 66 }