function vmFromHostCB()

in web/js/vm.js [311:405]


function vmFromHostCB(data, ioArgs) {
	if(data.items.failed) {
		if(data.items.failed == 'nohostaccess')
			alert('You do not have access to manage this VM host.');
		if(data.items.failed == 'invaliddata')
			alert('Invalid list of VMs submitted.');
		document.body.style.cursor = 'default';
		return;
	}
	/*
	for each vmid sent back we
		search through allvms until we find it keeping track of the previous item with inout == 1
		we set allvms[vmid].inout to 1
		we find the previous item in the select.options array
		we insert a new option right after that one
	*/
	var vms = data.items.vms;
	var addrem = data.items.addrem; // 1 for add, 0 for rem
	var checks = data.items.checks;
	var fails = data.items.fails;
	var obj = dojo.byId('currvms');
	for(var i = obj.options.length - 1; i >= 0; i--) {
		if(obj.options[i].selected) {
			var remove = 1;
			for(var j = 0; j < checks.length; j++) {
				if(obj.options[i].value == checks[j].id) {
					obj.options[i].selected = false;
					remove = 0;
					break;
				}
			}
			for(var j = 0; j < fails.length; j++) {
				if(obj.options[i].value == fails[j].id) {
					obj.options[i].selected = false;
					remove = 0;
					break;
				}
			}
			if(remove) {
				obj.remove(i);
				dojo.byId('vmstate').innerHTML = '';
				currvms.splice(i, 1);
			}
		}
	}
	for(var i = 0; i < vms.length; i++) {
		for(var j = 0; j < allvms.length; j++) {
			if(allvms[j].id == vms[i].id) {
				allvms.splice(j, 1);
				break;
			}
		}
	}

	if(data.items.vms.length) {
		dojo.byId('movevms').className = 'shown';
		obj = dojo.byId('movevmssel');
		var vms = data.items.vms;
		for(var i = 0; i < vms.length; i++) {
			var label = vms[i]['hostname'] + ' (' + vms[i]['time'] + ')';
			obj.options[obj.options.length] = new Option(label, data.items.vms[i].reqid);
		}
	}

	if(fails.length) {
		var msg1 = '';
		var msg2 = '';
		for(var i = 0; i < fails.length; i++) {
			if(fails[i].reason == 'noaccess')
				msg1 += fails[i].name + '\n';
			else if(fails[i].reason == 'nomgtnode')
				msg2 += fails[i].name + '\n';
		}
		if(msg1.length)
			alert('You do not have access to remove the following vm(s):\n\n' + msg1);
		if(msg2.length)
			alert('The following vms could not be removed because no management node was available for them:\n\n' + msg2);
	}

	var checks = data.items.checks;
	if(checks.length) {
		var content = 'The following computer(s) have reservations on them that cannot be<br>'
		            + 'moved.  Click <strong>Move Later</strong> to move the computer(s) off of the host<br>'
		            + 'at the listed time(s) or click <strong>Cancel</strong> to leave the computer(s) on<br>'
		            + 'the host:<br><br>';
		for(var i = 0; i < checks.length; i++) {
			content += 'computer: ' + checks[i].hostname + '<br>';
			content += 'free at: ' + checks[i].end + '<br><br>';
		}
		var func = function() {vmFromHostDelayed(data.items.cont);};
		setMessageWindow('Delayed Move', 'Move Later', content, func);
	}
	dojo.byId('assignedcnt').innerHTML = dojo.byId('currvms').options.length;
	document.body.style.cursor = 'default';
}