[Cluster-devel] conga/luci/cluster form-macros validate_qdisk.js

rmccabe at sourceware.org rmccabe at sourceware.org
Wed Aug 16 21:33:50 UTC 2006


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
--- conga/luci/cluster/validate_qdisk.js
+++ -	2006-08-16 21:33:49.905718000 +0000
@@ -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;
+}
--- conga/luci/cluster/form-macros	2006/08/16 19:08:35	1.45
+++ conga/luci/cluster/form-macros	2006/08/16 21:33:49	1.46
@@ -474,121 +474,12 @@
 	</div>
 
 	<div id="configTabContent" tal:condition="python: configTabNum == 4">
-		<form name="quorum_partition" action="" method="get" tal:attributes="action clusterinfo/quorumd_url">
-		<script type="text/javascript">
-			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;
-			}
-		</script>
+	<script type="text/javascript" src="/luci/homebase/homebase_common.js"></script>
+	<script type="text/javascript" src="/luci/cluster/validate_qdisk.js"></script>
+		<form name="quorum_partition" action="" method="post">
+			<input type="hidden" name="pagetype"
+				tal:attributes="value request/pagetype | request/form/pagetype"
+			/>
 		<div class="configTabContent">
 		<table id="systemsTable" class="systemsTable" border="0" cellspacing="0">
 			<thead class="systemsTable"> 
@@ -704,16 +595,16 @@
 				<input type="hidden" name="num_heuristics" id="num_heuristics" value="0">
 				<tr class="systemsTable">
 					<td class="systemsTable">
-						<input class="qdname qdisk" type="text" name="heuristic0:hname" value="">
+						<input class="qdname qdisk" type="text" name="heuristic0:hname" id="heuristic0:hname" value="">
 					</td>
 					<td class="systemsTable">
-						<input class="qdpath qdisk" type="text" name="heuristic0:hprog" value="">
+						<input class="qdpath qdisk" type="text" name="heuristic0:hprog" id="heuristic0:hprog" value="">
 					</td>
 					<td class="systemsTable">
-						<input class="qdint qdisk" type="text" name="heuristic0:hinterval" value="">
+						<input class="qdint qdisk" type="text" name="heuristic0:hinterval" id="heuristic0:hinterval" value="">
 					</td>
 					<td class="systemsTable">
-						<input class="qdscore qdisk" type="text" name="heuristic0:hscore" value="">
+						<input class="qdscore qdisk" type="text" name="heuristic0:hscore" id="heuristic0:hscore" value="">
 					</td>
 				</tr>
 				</tal:block>
@@ -733,24 +624,28 @@
 						<input class="qdname qdisk" type="text"
 							tal:attributes="
 								value heuristic/hname;
+								id python: 'heuristic' + str(curHeur) + ':hname';
 								name python: 'heuristic' + str(curHeur) + ':hname';"/>
 					</td>
 					<td class="systemsTable">
 						<input class="qdpath qdisk" type="text"
 							tal:attributes="
 								value heuristic/hprog;
+								id python: 'heuristic' + str(curHeur) + ':hprog';
 								name python: 'heuristic' + str(curHeur) + ':hprog';"/>
 					</td>
 					<td class="systemsTable">
 						<input class="qdint qdisk" type="text"
 							tal:attributes="
 								value heuristic/hinterval;
+								id python: 'heuristic' + str(curHeur) + ':hinterval';
 								name python: 'heuristic' + str(curHeur) + ':hinterval';"/>
 					</td>
 					<td class="systemsTable">
 						<input class="qdscore qdisk" type="text"
 							tal:attributes="
 								value heuristic/hscore;
+								id python: 'heuristic' + str(curHeur) + ':hscore';
 								name python: 'heuristic' + str(curHeur) + ':hscore';"/>
 					</td>
 				</tr>
@@ -767,7 +662,9 @@
 
 		<div class="spacing configTabContent"></div>
 		<div class="hbSubmit spacing configTabContent">
-			<input class="hbSubmit" type="submit" value="Apply">
+			<input class="hbSubmit" type="button" value="Apply"
+				onClick="validate_form(this.form);"
+			>
 		</div>
 			<script tal:condition="python:clusterinfo['is_quorumd'] != 'True'">
 				disableChildrenInput('quorumdisk');




More information about the Cluster-devel mailing list