1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
function initButton(){
/*
* Role : disable button
*/
$('#add').attr('disabled','disabled');
}
function initList(){
/*
* Role : initialize the list
*/
//var $initValue='';
$('#leftList').val('');
}
function activateButton(){
/*
* Role : enable button
*/
$('#add').removeAttr('disabled');
}
function addPackage() {
//the selected item of leftList
var $leftItem = $('#leftList option:selected');
//id of the left item
var idLeftItem = $leftItem.val();
//toString of the object left item
var textLeftItem = $leftItem.text();
//generated code
var generateRight = '<div id="'+idLeftItem+'"><table><tr style="text-align:center;"><th colspan="5" style="text-align:left; background:#eee;"><b>'+textLeftItem+'</b></th><th colspan="2" style="text-align:right; background:#eee;"><input type="button" value="X" id="del'+idLeftItem+'"/></tr><tr height="10"><td></td></tr><tr><td><b>OS :</b></td><td>Win <input type="checkbox" id="checkWin" checked="checked"/></td><td>Lin <input type="checkbox" id="checkLin"/></td><td>Mac <input type="checkbox" id="checkMac"/></td><td>And <input type="checkbox" id="checkWin"/></td><td>iOS <input type="checkbox" id="checkIOS"/></td></tr><tr height="40"><td></td></tr></table></div>';
//if leftItem has an id
if(idLeftItem){
//add on the right list..
$('#rightList').append(generateRight);
}
//remove the left item from left list
$leftItem.remove();
initButton();
//Remove a right item
$('#del'+idLeftItem).bind("click", function(){
//add to the left list
var generateLeft = '<option value="'+idLeftItem+'">'+textLeftItem+'</option>' ;
$('#leftList').append(generateLeft);
//remove from the right list
$('div#'+idLeftItem).remove();
});
} //end addPackage
$(document).ready(function(){
initButton();
initList();
//when you click on the leftList
$('#leftList').click(function(){
activateButton();
//click on the add button which adds a package
$('#add').click(addPackage);
//Disable the add button for each value change
$('#leftList').change(function() {
initButton();
});
});//end #leftList.click
});//end ready function |