function saveResource()

in web/js/resources/image.js [212:357]


function saveResource() {
	var submitbtn = dijit.byId('addeditbtn');
	var errobj = dojo.byId('addeditdlgerrmsg');
	if(! checkValidatedObj('name', errobj))
		return;
	/*if(! dijit.byId('owner')._hasBeenBlurred && dijit.byId('owner').get('value') == '') {
		dijit.byId('owner')._hasBeenBlurred = true;
		dijit.byId('owner').validate();
		submitbtn.set('disabled', true);
		setTimeout(function() {
			saveResource();
			submitbtn.set('disabled', false);
		}, 1000);
		return;
	}*/
	if(ownerchecking) {
		submitbtn.set('disabled', true);
		setTimeout(function() {
			saveResource();
			submitbtn.set('disabled', false);
		}, 1000);
		return;
	}
	if(! checkValidatedObj('owner', errobj))
		return;
	if(! checkValidatedObj('ram', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('ram').focus();}, 300);
		return;
	}
	if(! checkValidatedObj('cores', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('cores').focus();}, 300);
		return;
	}
	if(! checkValidatedObj('cpuspeed', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('cpuspeed').focus();}, 300);
		return;
	}
	if(! checkValidatedObj('concurrent', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('concurrent').focus();}, 300);
		return;
	}
	if(! checkValidatedObj('reload', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('reload').focus();}, 300);
		return;
	}
	if(dijit.byId('adauthenable').checked && ! checkValidatedObj('baseou', errobj)) {
		if(! dijit.byId('advancedoptions').open)
			dijit.byId('advancedoptions').toggle();
		setTimeout(function() {dijit.byId('baseou').focus();}, 300);
		return;
	}

	if(dojo.byId('editresid').value == 0)
		var data = {continuation: dojo.byId('addresourcecont').value};
	else
		var data = {continuation: dojo.byId('saveresourcecont').value};

	data['name'] = dijit.byId('name').get('value');
	data['owner'] = dijit.byId('owner').get('value');

	data['networkspeed'] = parseInt(dijit.byId('networkspeed').get('value'));
	if((+log10(data['networkspeed']).toFixed(2) % 1) != 0) { // log10(1000) -> 2.9999999999999996
		errobj.innerHTML = _('Invalid network speed specified');
		return;
	}
	data['concurrent'] = dijit.byId('concurrent').get('value');
	if(data['concurrent'] < 0 || data['concurrent'] > 255) {
		errobj.innerHTML = _('Max Concurrent Usage must be between 0 and 255');
		return;
	}
	data['checkout'] = parseInt(dijit.byId('checkout').get('value'));
	if(data['checkout'] != 0 && data['checkout'] != 1) {
		errobj.innerHTML = _('Invalid value specified for \'Available for checkout\'');
		return;
	}
	data['checkuser'] = parseInt(dijit.byId('checkuser').get('value'));
	if(data['checkuser'] != 0 && data['checkuser'] != 1) {
		errobj.innerHTML = _('Invalid value specified for \'Check for logged in user\'');
		return;
	}
	data['rootaccess'] = parseInt(dijit.byId('rootaccess').get('value'));
	if(data['rootaccess'] != 0 && data['rootaccess'] != 1) {
		errobj.innerHTML = _('Invalid value specified for \'Users have administrative access\'');
		return;
	}
	data['sethostname'] = parseInt(dijit.byId('sethostname').get('value'));
	if(data['sethostname'] != 0 && data['sethostname'] != 1) {
		if(dojo.hasClass('sethoatnamediv', 'hidden')) {
			data['sethostname'] = 0;
		}
		else {
			errobj.innerHTML = _('Invalid value specified for \'Set computer hostname\'');
			return;
		}
	}
	data['maxinitialtime'] = parseInt(dijit.byId('maxinitialtime').get('value'));
	if(data['maxinitialtime'] < 0 || data['maxinitialtime'] > 201600) {
		errobj.innerHTML = _('Invalid Max Reservation Duration selected');
		return;
	}
	if(dijit.byId('sysprep')) {
		data['sysprep'] = parseInt(dijit.byId('sysprep').get('value'));
		if(data['sysprep'] != 0 && data['sysprep'] != 1) {
			errobj.innerHTML = _('Invalid value specified for \'Use sysprep\'');
			return;
		}
		if(! /[0-9,]+/.test(dojo.byId('connectmethodids').value)) {
			errobj.innerHTML = _('Invalid Connect Methods specified');
			return;
		}
		data['connectmethodids'] = dojo.byId('connectmethodids').value;
	}

	data['desc'] = dijit.byId('description').get('value');
	data['usage'] = dijit.byId('usage').get('value');
	if(dijit.byId('imgcomments'))
		data['imgcomments'] = dijit.byId('imgcomments').get('value');
	data['ram'] = dijit.byId('ram').get('value');
	data['cores'] = dijit.byId('cores').get('value');
	data['cpuspeed'] = dijit.byId('cpuspeed').get('value');
	if(dijit.byId('reload'))
		data['reload'] = dijit.byId('reload').get('value');
	if(dijit.byId('adauthenable').checked) {
		data['adauthenabled'] = 1;
		data['addomainid'] = dijit.byId('addomainid').get('value');
		data['baseou'] = dijit.byId('baseou').get('value');
	}
	else {
		data['adauthenabled'] = 0;
		data['addomainid'] = 0;
		data['baseou'] = '';
	}

	submitbtn.set('disabled', true);
	RPCwrapper(data, saveResourceCB, 1);
}