Skip to contentSkip to conversation

conga/luci/cluster form-macros validate_qdisk.js

Cluster-devel [email protected] 1 participant 1 message Aug 16, 2006

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-08-16 21:33:49

Modified files:
luci/cluster : form-macros
Added files:
luci/cluster : validate_qdisk.js

Log message:
form validate for qdisk config

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/validate_qdisk.js.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.45&r2=1.46

/cvs/cluster/conga/luci/cluster/validate_qdisk.js,v --> standard output revision 1.1

- renamed from luci/cluster/validate_qdisk.js +246 -0
@@ -0,0 +1,246 @@
+function check_heuristic(hnum, form) {
+	var errors = new Array();
+
+	if (hnum < 0)
+		errors.push('An invalid heuristic number was given: ' + hnum);
+	else if (hnum > 9)
+		errors.push('A maximum of 10 heuristics is allowed.');
+
+	if (errors.length > 0)
+		return (errors);
+
+	hstr = 'heuristic' + hnum + ':';
+
+	hname = document.getElementById(hstr + 'hname');
+	if (!hname || str_is_blank(hname.value))
+		errors.push('No name was given for heuristic ' + (hnum + 1));
+	else
+		hname = hname.value;
+
+	hpath = document.getElementById(hstr + 'hpath');
+	if (!hpath || str_is_blank(hpath.value))
+		errors.push('No path was given for heuristic ' + (hnum + 1));
+	else
+		hpath = hpath.value;
+
+	hint = document.getElementById(hstr + 'hinterval');
+	if (!hint || str_is_blank(hint.value))
+		errors.push('No interval was given for heuristic ' + (hnum + 1));
+	else
+		hint = hint.value;
+
+	hscore = document.getElementById(hstr + 'hscore');
+	if (!hscore || str_is_blank(hscore.value))
+		errors.push('No score was given for heuristic ' + (hnum + 1));
+	else
+		hscore = hscore.value;
+
+	if (errors.length == 4) {
+		/* The entry is blank -- ignore it. */
+		return (null);
+	}
+
+	/* TODO: hname, hpath */
+	if (hint && isNaN(parseInt(hint)))
+		errors.push('Heuristic interval values must be integers.');
+
+	if (hscore && isNaN(parseInt(hscore)))
+		errors.push('Heuristic score values must be integers.');
+
+	if (errors.length > 0)
+		return (errors);
+
+	return (null);
+}
+
+function validate_form(form) {
+	if (!form || !form.quorumd) {
+		alert('You did not specify whether or not to use a quorum partition.');
+		return (-1);
+	}
+
+	if (form.quorumd[0].checked)
+		qpart = 0
+	else if (form.quorumd[1].checked)
+		qpart = 1;
+	else {
+		alert('You submitted an invalid value while specifying whether or not to use a quorum partition: ' + qpart + '.');
+		return (-1);
+	}
+
+	if (qpart) {
+		var errors = new Array();
+		if (!form.interval || str_is_blank(form.interval.value))
+			errors.push('No interval setting was given.');
+		else {
+			if (isNaN(parseInt(form.interval.value)))
+				errors.push('Interval values must be integers.');
+		}
+
+		if (!form.votes || str_is_blank(form.votes.value))
+			errors.push('No votes setting was given.');
+		else {
+			if (isNaN(parseInt(form.votes.value)))
+				errors.push('Votes values must be integers.');
+		}
+
+		if (!form.tko || str_is_blank(form.tko.value))
+			errors.push('No TKO setting was given.');
+		else {
+			if (isNaN(parseInt(form.tko.value)))
+				errors.push('TKO values must be integers.');
+		}
+
+		if (!form.min_score || str_is_blank(form.min_score.value))
+			errors.push('No minimum score setting was given.');
+		else {
+			if (isNaN(parseInt(form.tko.value)))
+				errors.push('Minimum score values must be integers.');
+		}
+
+		if (!form.device || str_is_blank(form.device.value))
+			errors.push('No device setting was given.');
+		else {
+			/* TODO: check this */
+			device = form.device.value;
+		}
+
+		if (!form.label || str_is_blank(form.label.value))
+			errors.push('No label setting was given.');
+		else {
+			/* TODO: check this */
+			label = form.device.label;
+		}
+
+		hnum = document.getElementById('num_heuristics');
+		if (hnum) {
+			hnum = Number(hnum.value);
+			if (hnum == 0)
+				hnum++;
+			for (var i = 0 ; i < hnum ; i++) {
+				var err = check_heuristic(i, form);
+				if (err)
+					errors = errors.concat(err);
+			}
+		}
+
+		if (error_dialog(errors))
+			return (-1);
+	}
+
+	if (confirm('Update quorum partition properties?'))
+		form.submit()
+}
+
+var oldInput = null;
+
+function addHeuristic(parent_name) {
+	parent = document.getElementById(parent_name);
+	if (!parent)
+		return;
+	hnum = document.getElementById('num_heuristics');
+	if (!hnum)
+		return;
+
+	var cur_hnum = Number(hnum.value) + 1;
+	if (cur_hnum >= 10) {
+		alert('There is a maximum of 10 heuristics.');
+		return;
+	}
+	hstr = 'heuristic' + cur_hnum + ':';
+
+	name_td = document.createElement('td');
+	name_td.className = 'systemsTable';
+	name_input = document.createElement('input');
+	name_input.className = 'qdname qdisk';
+	name_input.setAttribute('name', hstr + 'hname');
+	name_input.setAttribute('id', hstr + 'hname');
+	name_input.setAttribute('type', 'text');
+	name_td.appendChild(name_input);
+
+	path_td = document.createElement('td');
+	path_td.className = 'systemsTable';
+	path_input = document.createElement('input');
+	path_input.className = 'qdpath qdisk';
+	path_input.setAttribute('name', hstr + 'hprog');
+	path_input.setAttribute('id', hstr + 'hprog');
+	path_input.setAttribute('type', 'text');
+	path_td.appendChild(path_input);
+
+	interval_td = document.createElement('td');
+	interval_td.className = 'systemsTable';
+	interval_input = document.createElement('input');
+	interval_input.className = 'qdint qdisk';
+	interval_input.setAttribute('name', hstr + 'hinterval');
+	interval_input.setAttribute('id', hstr + 'hinterval');
+	interval_input.setAttribute('type', 'text');
+	interval_td.appendChild(interval_input);
+
+	score_td = document.createElement('td');
+	score_td.className = 'systemsTable';
+	score_input = document.createElement('input');
+	score_input.className = 'qdscore qdisk';
+	score_input.setAttribute('name', hstr + 'hscore');
+	score_input.setAttribute('id', hstr + 'hscore');
+	score_input.setAttribute('type', 'input');
+	score_td.appendChild(score_input);
+
+	tr = document.createElement('tr');
+	tr.className = 'systemsTable';
+	tr.appendChild(name_td);
+	tr.appendChild(path_td);
+	tr.appendChild(interval_td);
+	tr.appendChild(score_td);
+	parent.appendChild(tr);
+	hnum.value++;
+}
+
+function disableChildrenInput(parent_name) {
+	parent = document.getElementById(parent_name);
+	if (!parent)
+		return;
+
+	inputElem = parent.getElementsByTagName('input');
+	if (!inputElem || inputElem.length < 1) {
+		oldInput = null;
+		return;
+	}
+	if (inputElem[0].disabled)
+		return;
+	oldInput = new Array(inputElem.length);
+	for (var i = 0 ; i < inputElem.length ; i++) {
+		e = inputElem[i];
+
+		e.disabled = true;
+		if (e.type == 'button')
+			continue;
+		oldInput[e.name] = e.value;
+		e.value = '';
+	}
+}
+
+function enableChildrenInput(parent_name) {
+	parent = document.getElementById(parent_name);
+	if (!parent)
+		return;
+
+	inputElem = parent.getElementsByTagName('input');
+	if (!inputElem || inputElem.length < 1) {
+		return;
+	}
+
+	if (!inputElem[0].disabled)
+		return;
+
+	for (var i = 0 ; i < inputElem.length ; i++) {
+		e = inputElem[i];
+		e.disabled = false;
+		if (e.type == 'button')
+			continue;
+		if (oldInput && oldInput[e.name])
+			e.value = oldInput[e.name];
+		else
+			e.value = '';
+	}
+	oldInput = null;
+}
luci/cluster/form-macros +17 -120

185 lines not on this page · raw message