| 1 |
// $Id $
|
| 2 |
|
| 3 |
//@file
|
| 4 |
//Code that operates multiselect boxes
|
| 5 |
|
| 6 |
$(document).ready(function()
|
| 7 |
{
|
| 8 |
//note: Doesn't matter what sort of submit button it is really (preview or submit)
|
| 9 |
//selects all the items in the selected box (so they are actually selected) when submitted
|
| 10 |
$('input.form-submit').click(function()
|
| 11 |
{
|
| 12 |
$('fieldset.multiselect select[@name$="[selected][]"]').selectAll();
|
| 13 |
});
|
| 14 |
|
| 15 |
});
|
| 16 |
|
| 17 |
//selects all the items in the select box it is called from.
|
| 18 |
//usage $('nameofselectbox').selectAll();
|
| 19 |
//
|
| 20 |
jQuery.fn.selectAll = function()
|
| 21 |
{
|
| 22 |
this.each(function()
|
| 23 |
{
|
| 24 |
for (var i=0;i<this.options.length;i++)
|
| 25 |
{
|
| 26 |
option = this.options[i];
|
| 27 |
option.selected = true;
|
| 28 |
}
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
| 32 |
|
| 33 |
// -------------------------------------------------------------------
|
| 34 |
// hasOptions(obj)
|
| 35 |
// Utility function to determine if an object has an options array
|
| 36 |
// -------------------------------------------------------------------
|
| 37 |
function hasOptions(obj) {
|
| 38 |
if (obj!=null && obj.options!=null) {
|
| 39 |
return true;
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
return false;
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
function moveSelectedOptions(from_name,to_name) {
|
| 47 |
|
| 48 |
from = document.getElementsByName(from_name)[0];
|
| 49 |
to = document.getElementsByName(to_name)[0];
|
| 50 |
|
| 51 |
// Move them over
|
| 52 |
if (!hasOptions(from)) {
|
| 53 |
return false;
|
| 54 |
}
|
| 55 |
|
| 56 |
for (var i=0; i<from.options.length; i++) {
|
| 57 |
var o = from.options[i];
|
| 58 |
if (o.selected) {
|
| 59 |
if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
|
| 60 |
to.options[index] = new Option( o.text, o.value, false, false);
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
// Delete them from original
|
| 65 |
for (var i=(from.options.length-1); i>=0; i--) {
|
| 66 |
var o = from.options[i];
|
| 67 |
if (o.selected) {
|
| 68 |
from.options[i] = null;
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
from.selectedIndex = -1;
|
| 73 |
to.selectedIndex = -1;
|
| 74 |
}
|