diff --git a/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect.js b/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect.js new file mode 100644 index 000000000..1a8260602 --- /dev/null +++ b/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect.js @@ -0,0 +1,112 @@ +function moveSelectedOptions(objSourceElement, objTargetElement, toSort, notMove1, notMove2) { + var test1 = compile(notMove1); + var test2 = compile(notMove2); + moveOptions(objSourceElement, objTargetElement, toSort, + function(opt) { + return (opt.selected && !test1(opt.value) && !test2(opt.value)); + } + ); +} + +function moveAllOptions(objSourceElement, objTargetElement, toSort, notMove1, notMove2) { + var test1 = compile(notMove1); + var test2 = compile(notMove2); + moveOptions(objSourceElement, objTargetElement, toSort, + function(opt) { + return (!test1(opt.value) && !test2(opt.value)); + } + ); +} + +function compile(ptn) { + if (ptn != undefined) { + if (ptn == '' || !window.RegExp) { + return function(val) { return val == ptn; } + } else { + var reg = new RegExp(ptn); + return function (val) { return reg.test(val); } + } + } + return function(val) { return false; } +} + + +function moveOptions(objSourceElement, objTargetElement, toSort, chooseFunc) { + var aryTempSourceOptions = new Array(); + var aryTempTargetOptions = new Array(); + var x = 0; + + //looping through source element to find selected options + for (var i = 0; i < objSourceElement.length; i++) { + if (chooseFunc(objSourceElement.options[i])) { + //need to move this option to target element + var intTargetLen = objTargetElement.length++; + objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text; + objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value; + } + else { + //storing options that stay to recreate select element + var objTempValues = new Object(); + objTempValues.text = objSourceElement.options[i].text; + objTempValues.value = objSourceElement.options[i].value; + aryTempSourceOptions[x] = objTempValues; + x++; + } + } + + //sorting and refilling target list + for (var i = 0; i < objTargetElement.length; i++) { + var objTempValues = new Object(); + objTempValues.text = objTargetElement.options[i].text; + objTempValues.value = objTargetElement.options[i].value; + aryTempTargetOptions[i] = objTempValues; + } + + if (toSort) { + aryTempTargetOptions.sort(sortByText); + } + + for (var i = 0; i < objTargetElement.length; i++) { + objTargetElement.options[i].text = aryTempTargetOptions[i].text; + objTargetElement.options[i].value = aryTempTargetOptions[i].value; + objTargetElement.options[i].selected = false; + } + + //resetting length of source + objSourceElement.length = aryTempSourceOptions.length; + //looping through temp array to recreate source select element + for (var i = 0; i < aryTempSourceOptions.length; i++) { + objSourceElement.options[i].text = aryTempSourceOptions[i].text; + objSourceElement.options[i].value = aryTempSourceOptions[i].value; + objSourceElement.options[i].selected = false; + } +} + +function sortByText(a, b) { + if (a.text < b.text) {return -1} + if (a.text > b.text) {return 1} + return 0; +} + +function selectAllOptionsExceptSome(objTargetElement, type, ptn) { + var test = compile(ptn); + for (var i = 0; i < objTargetElement.length; i++) { + var opt = objTargetElement.options[i]; + if ((type == 'key' && !test(opt.value)) || + (type == 'text' && !test(opt.text))) { + opt.selected = true; + } else { + opt.selected = false; + } + } + return false; +} + +function selectAllOptions(objTargetElement) { + for (var i = 0; i < objTargetElement.length; i++) { + if (objTargetElement.options[i].value != '') { + objTargetElement.options[i].selected = true; + } + } + return false; +} diff --git a/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect/optiontransferselect.js b/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect/optiontransferselect.js deleted file mode 100644 index e786e6f3e..000000000 --- a/action/src/main/resources/org/apache/struts/action2/static/optiontransferselect/optiontransferselect.js +++ /dev/null @@ -1,463 +0,0 @@ -// =================================================================== -// Author: Matt Kruse -// WWW: http://www.mattkruse.com/ -// -// NOTICE: You may use this code for any purpose, commercial or -// private, without any further permission from the author. You may -// remove this notice from your final code if you wish, however it is -// appreciated by the author if at least my web site address is kept. -// -// You may *NOT* re-distribute this code in any way except through its -// use. That means, you can include it in your product, or your web -// site, or any other form where the code is actually being used. You -// may not put the plain javascript up on your site for download or -// include it in your javascript libraries for download. -// If you wish to share this code with others, please just point them -// to the URL instead. -// Please DO NOT link directly to my .js files from your site. Copy -// the files to your server and use them there. Thank you. -// =================================================================== - -// HISTORY -// ------------------------------------------------------------------ -// Jan 31, 2005: (tm_jee) alter selectAllOptions(obj) to ignore those option whose key -// is empty. -// Jan 31, 2005: (tm_jee) added moveOptionUp(obj, regexp) to move obj up except when -// obj's option's key is empty or if it matches the regexp -// Jan 31, 2005: (tm_jee) added moveOptionDown(obj, regexp) to move obj down except when -// obj's option's key is empty or if it matches the regexp -// Jan 31, 2005: (tm_jee) altered moveOptionUp(obj) to ignore moving obj's option -// up if its key is empty -// Jan 31, 2005: (tm_jee) altered moveOptionDown(obj) to ignore moving obj's option -// down if its key is empty -// Jan 1, 2005: (tm_jee) moveSelectedOptions(from, to) accept a 5th argument -// that function exactly like the fourth (regexp) -// Jan 1, 2005: (tm_jee) added unSelectMatchingOptionsBasedOnKey -// Jan 1, 2005: (tm_jee) alter selectUnselectMatchingOptions(obj,regexp,which,only) -// accept a 5th string agrument ('key' or 'text'). If key regexp -// is matched on -// Jan 1, 2005: (tm_jee) alter selectUnselectMatchingOptions(obj,regexp,which,only) -// when it is in 'key' mode to auto-unselect