view test_create/test_create.html @ 925:82baf45866fc

Stash create_test. Implementing submit. Need to test on OSX
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 02 Jun 2015 15:18:40 +0100
parents 2dc00907c6ab
children 4a0bfa7bef24
line wrap: on
line source
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">

		<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
		Remove this if you use the .htaccess -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

		<title>WAET Create Test</title>
		<meta name="description" content="">
		<meta name="author" content="">

		<meta name="viewport" content="width=device-width; initial-scale=1.0">
		
		<script type="text/javascript">
			// To aid 'one-page set-up' all scripts and CSS must be included directly in this file!
			var topLevel;
			window.onload = function() {
				// Initialise page
				topLevel = document.getElementById('topLevelBody');
				var setup = document.createElement('div');
				setup.id = 'setupTagDiv';
				
			};
			
			function attributePair(string, type, mandatory){
				var id = document.createElement("span");
				id.textContent = string;
				var input = document.createElement("input");
				input.type = type;
				if (type == 'text') {
					if (mandatory == true) {
						input.setAttribute('mandatory','true');
					}
					else {
						input.setAttribute('mandatory','false');
					}
				}
				return [id, input];
			}
			
			function removeNode(event) {
				event.srcElement.parentElement.parentElement.removeChild(event.srcElement.parentElement);
			}
			
			function buttonClickedValidate() {
				var ready = validate();
				if (ready == false) {
					var errMsg = document.getElementById('errorMessage');
					errMsg.textContent = "There were some errors with your XML. Any input boxes highlighted in red are invalid because they are empty or because its ID matches another elements ID. Please fill these in correctly. Any boxes which are yellow are not-invalid but will use the default value.";
					errMsg.style.visibility = 'visible';
					document.getElementById('createXML').disabled = true;
					
				} else {
					var errMsg = document.getElementById('errorMessage');
					errMsg.textContent = "";
					errMsg.style.visiblity = 'hidden';
					document.getElementById('createXML').disabled = false;
				}
			}
			
			function buttonClickedSubmit() {
				var ready = validate();
				if (ready == true) {
					var xmlDoc = document.createElement('BrowserEvalProjectDocument');
					var setup = document.createElement('setup');
					setup.setAttribute('interface',document.getElementById('interface').value);
					if (document.getElementById('projectReturn').value == "") {
						setup.setAttribute('projectReturn',"null");
					} else {
						setup.setAttribute('projectReturn',document.getElementById('projectReturn').value);
					}
					setup.setAttribute('randomiseOrder',document.getElementById('randomisePageOrder').checked);
					setup.setAttribute('collectMetrics',document.getElementById('collectMetrics').checked);
					
					var globalPreTest = document.createElement('preTest');
					var options = document.getElementById('globalPreTest').getElementsByClassName('head');
					constructPrePost(globalPreTest, options);
					
					var globalPostTest = document.createElement('postTest');
					options = document.getElementById('globalPostTest').getElementsByClassName('head');
					constructPrePost(globalPostTest, options);
					
					var globalMetrics = document.createElement('metric');
					options = document.getElementById('globalMetric').getElementsByClassName('attrib')[0].getElementsByTagName('input');
					for (var i=0; i<options.length; i++) {
						if (options[i].checked) {
							var metric = document.createElement('metricEnable');
							metric.textContent = options[i].id;
							globalMetrics.appendChild(metric);
						}
					}
					
				}
			}
			
			function constructPrePost(parent, options) {
				for (var i=0; i<options.length; i++) {
					var elem = options[i];
					var attributes = elem.getElementsByClassName('attrib')[0].getElementsByTagName('input');
					if (elem.getAttribute('name') == 'question-node') {
						var node = document.createElement('question');
						node.setAttribute('id',attributes[0].value);
						node.textContent = attributes[1].value;
					} else if (elem.getAttribute('name') == 'statement-node') {
						var node = document.createElement('statment');
						node.textContent = attributes[0].value;
					}
					parent.appendChild(node);
				}
			}
			
			function validate() {
				var canExport = true;
				// Checks if the XML can be created from the given entries
				var inputs = document.getElementsByTagName('input');
				for (var i=0; i<inputs.length; i++) {
					if (inputs[i].type == 'text') {
						if (inputs[i].value == "") {
							var mandatory = inputs[i].getAttribute('mandatory');
							if (mandatory == "true") {
								errorInput(inputs[i]);
								canExport = false;
							} else {
								warningInput(inputs[i]);
							}
						} else {
							goodInput(inputs[i]);
						}
					}
				}
				
				var audioHolders = document.getElementsByName('audio-holder');
				for (var i=0; i<audioHolders.length; i++) {
					var divs = audioHolders[i].getElementsByClassName('head');
					var IDs = [];
					for (var j=0; j<divs.length; j++) {
						if (divs[j].getAttribute('name') == 'audio-element') {
							var obj = divs[j].getElementsByClassName('attrib')[0].children[1];
							var aeID = obj.value;
							if (aeID != "") {
								var unique = true;
								for (var k=0; k<IDs.length; k++) {
									if (aeID == IDs[k]) {
										unique = false;
										break;
									}
								}
								if (unique == true) {
									IDs.push(aeID);
								} else {
									errorInput(obj);
									canExport = false;
								}
							}
						}
					}
				}
				return canExport;
			};
			
			function errorInput(node) {
				node.style.backgroundColor = "#FF0000";
			}
			
			function warningInput(node) {
				node.style.backgroundColor = "#FFFF00";
			}
			
			function goodInput(node) {
				node.style.backgroundColor = "#FFFFFF";
			}
			
			function questionNode() {
				var node = document.createElement("div");
				node.setAttribute('class','head');
				node.setAttribute('name','question-node');
				var nodeTitle = document.createElement("span");
				nodeTitle.textContent = "Question";
				var attributes = document.createElement("div");
				attributes.setAttribute('class','attrib');
				var id = attributePair("ID:","text", true);
				var question = attributePair("Question:","text", false);
				node.appendChild(nodeTitle);
				id.forEach(function(item){attributes.appendChild(item);},false);
				question.forEach(function(item){attributes.appendChild(item);},false);
				node.appendChild(attributes);
				
				var removeButton = document.createElement("button");
				removeButton.textContent = "Remove";
				removeButton.onclick = removeNode;
				node.appendChild(removeButton);
				return node;
			}
			
			function statementNode() {
				var node = document.createElement("div");
				node.setAttribute('class','head');
				node.setAttribute('name','statement-node');
				var nodeTitle = document.createElement("span");
				nodeTitle.textContent = "Statement";
				var attributes = document.createElement("div");
				attributes.setAttribute('class','attrib');
				var statement = attributePair("Statement:","text",false);
				node.appendChild(nodeTitle);
				statement.forEach(function(item){attributes.appendChild(item);},false);
				node.appendChild(attributes);
				
				var removeButton = document.createElement("button");
				removeButton.textContent = "Remove";
				removeButton.onclick = removeNode;
				node.appendChild(removeButton);
				return node;
			}
			
			function audioHolderNode() {
				var audioHolderCounts = document.getElementsByName("audio-holder").length;
				var node = document.createElement("div");
				node.setAttribute("class","head");
				node.setAttribute("name","audio-holder");
				node.setAttribute("id","audio-holder-"+audioHolderCounts);
				var nodeTitle = document.createElement("span");
				nodeTitle.textContent = "Audio Holder "+(audioHolderCounts+1);
				
				var attributes = document.createElement("div");
				attributes.setAttribute('class','attrib');
				var id = attributePair("ID:","text",true);
				id[1].value=audioHolderCounts;
				var hostURL = attributePair("Host URL:", "text",false);
				var sampleRate = attributePair("Sample Rate:","text",false);
				var randomiseOrder = attributePair("Randomise Element Order:","checkbox");
				var repeatCount = attributePair("Repeat Page Count:","number");
				repeatCount[1].value = 0;
				var loop = attributePair("Loop Element Playback","checkbox");
				var elementComments = attributePair("Enable Comment Boxes","checkbox");
				id.forEach(function(item){attributes.appendChild(item);},false);
				hostURL.forEach(function(item){attributes.appendChild(item);},false);
				sampleRate.forEach(function(item){attributes.appendChild(item);},false);
				hostURL.forEach(function(item){attributes.appendChild(item);},false);
				randomiseOrder.forEach(function(item){attributes.appendChild(item);},false);
				repeatCount.forEach(function(item){attributes.appendChild(item);},false);
				loop.forEach(function(item){attributes.appendChild(item);},false);
				elementComments.forEach(function(item){attributes.appendChild(item);},false);
				
				node.appendChild(nodeTitle);
				node.appendChild(attributes);
				
				var pretest = document.createElement("div");
				pretest.setAttribute('class','head');
				pretest.setAttribute('name','pre-test');
				var pretestTitle = document.createElement("h4");
				pretestTitle.textContent = "Pre Test";
				var buttonAddQ = document.createElement("button");
				buttonAddQ.textContent = "Add Pre Test Question";
				buttonAddQ.onclick = function(){event.srcElement.parentElement.appendChild(questionNode());};
				var buttonAddS = document.createElement("button");
				buttonAddS.textContent = "Add Pre Test Statement";
				buttonAddS.onclick = function(){event.srcElement.parentElement.appendChild(statementNode());};
				pretest.appendChild(pretestTitle);
				pretest.appendChild(buttonAddQ);
				pretest.appendChild(buttonAddS);
				
				var posttest = document.createElement("div");
				posttest.setAttribute('class','head');
				posttest.setAttribute('name','post-test');
				var posttestTitle = document.createElement("h4");
				posttestTitle.textContent = "Post Test";
				var buttonAddQ = document.createElement("button");
				buttonAddQ.textContent = "Add Post Test Question";
				buttonAddQ.onclick = function(){event.srcElement.parentElement.appendChild(questionNode());};
				var buttonAddS = document.createElement("button");
				buttonAddS.textContent = "Add Post Test Statement";
				buttonAddS.onclick = function(){event.srcElement.parentElement.appendChild(statementNode());};
				posttest.appendChild(posttestTitle);
				posttest.appendChild(buttonAddQ);
				posttest.appendChild(buttonAddS);
				
				node.appendChild(pretest);
				node.appendChild(posttest);
				
				var newAudioElementButton = document.createElement("button");
				newAudioElementButton.textContent = "Add audio element";
				newAudioElementButton.onclick = function(){
					event.srcElement.parentElement.appendChild(audioElementNode());
				};
				node.appendChild(newAudioElementButton);
				
				var newCommentButton = document.createElement("button");
				newCommentButton.textContent = "Add Comment Box";
				newCommentButton.onclick = function() {
					event.srcElement.parentElement.appendChild(commentBox());
				};
				node.appendChild(newCommentButton);
				
				var removeButton = document.createElement("button");
				removeButton.textContent = "Remove Audio Holder";
				removeButton.onclick = removeNode;
				node.appendChild(removeButton);
				return node;
			}
			
			function audioElementNode() {
				var parentStructure = event.srcElement.parentElement.childNodes;
				var audioElemCounts = 0;
				for (var i=0; i<parentStructure.length; i++) {
					if (parentStructure[i].getAttribute('name') == "audio-element")
					{audioElemCounts++;}
				}
				var node = document.createElement('div');
				node.setAttribute('class','head');
				node.setAttribute('name','audio-element');
				var nodeTitle = document.createElement('span');
				nodeTitle.textContent = 'Audio Element '+(audioElemCounts+1);
				
				var attributes = document.createElement("div");
				attributes.setAttribute('class','attrib');
				var id = attributePair("ID:","text",true);
				id[1].value = audioElemCounts;
				var url = attributePair("URL:","text",true);
				id.forEach(function(item){attributes.appendChild(item);},false);
				url.forEach(function(item){attributes.appendChild(item);},false);
				
				node.appendChild(nodeTitle);
				node.appendChild(attributes);
				
				var removeButton = document.createElement("button");
				removeButton.textContent = "Remove Audio Element";
				removeButton.onclick = removeNode;
				node.appendChild(removeButton);
				return node;
			}
			
			function commentBox() {
				var node = document.createElement('div');
				node.setAttribute('class','head');
				node.setAttribute('name','comment-question');
				var nodeTitle = document.createElement('h4');
				nodeTitle.textContent = "Comment Box";
				
				var attributes = document.createElement('div');
				attributes.setAttribute('class','attrib');
				var id = attributePair("ID:",'text',true);
				var question = attributePair("Question:",'text',true);
				id.forEach(function(item){attributes.appendChild(item);},false);
				question.forEach(function(item){attributes.appendChild(item);},false);
				
				var removeButton = document.createElement("button");
				removeButton.textContent = "Remove Comment Box";
				removeButton.onclick = removeNode;
				
				node.appendChild(nodeTitle);
				node.appendChild(attributes);
				node.appendChild(removeButton);
				return node;
			}
		</script>
		<style>
			div {
				padding: 2px;
				margin-top: 2px;
				margin-bottom: 2px;
			}
			div.head{
				margin-left: 10px;
				border: black;
				border-width: 2px;
				border-style: solid;
			}
			div.attrib{
				margin-left:25px;
				border: black;
				border-width: 2px;
				border-style: dashed;
				margin-bottom: 10px;
			}
		</style>
		
	</head>

	<body>
		<h1>Create Test Setup XML</h1>
		<button id="validateXML" onclick="buttonClickedValidate();">Validate</button>
		<button id="createXML" onclick="buttonClickedValidate();" disabled>Submit</button>
		<span id="errorMessage" visibility="hidden"></span>
		<div id="topLevelBody" align="left">
			<!-- Interface goes here -->
			<div name='test-setup'>
				<div id="setup" class="head">
					<h2>Setup Tag</h2>
					<div id="setup-attribs" class="attrib">
						<span>Interface</span>
						<select id="interface">
							<option value='APE'>APE</option>
						</select>
						<span>Project Return</span>
						<input type="text" id="projectReturn" mandatory="false">
						<span>Randomise Test Page Order</span>
						<input id="randomisePageOrder" type="checkbox" value="false">
						<span>Collect Session Metrics</span>
						<input id="collectMetrics" type="checkbox">
					</div>
					<div id="globalPreTest" class="head">
						<h3>Pre Test</h3>
						<button id="addPreTestQ" onclick="event.srcElement.parentElement.appendChild(questionNode());">Add Pre Test Question</button>
						<button id="addPreTestS" onclick="event.srcElement.parentElement.appendChild(statementNode());">Add Pre Test Statement</button>
					</div>
					<div id="globalPostTest" class="head">
						<h3>Post Test</h3>
						<button id="addPreTestQ" onclick="event.srcElement.parentElement.appendChild(questionNode());">Add Post Test Question</button>
						<button id="addPreTestS" onclick="event.srcElement.parentElement.appendChild(statementNode());">Add Post Test Statement</button>
					</div>
					<div id="globalMetric" class="head">
						<h3>Global Metrics</h3>
						<div id="globalMetric-attrib" class="attrib">
							<span>Test Timer</span>
							<input type="checkbox" id="testTimer" />
							<span>Element Playback Timer</span>
							<input type="checkbox" id="elementTimer" />
							<span>Element Initial Position</span>
							<input type="checkbox" id="elementInitialPosition" />
							<span>Element Tracker</span>
							<input type="checkbox" id="elementTracker" />
							<span>Element Flag Listened To</span>
							<input type="checkbox" id="elementFlagListenedTo" />
							<span>Element Flag Moved</span>
							<input type="checkbox" id="elementFlagMoved" />
						</div>
					</div>
					<button id="addAudioHolder" onclick="event.srcElement.parentElement.appendChild(audioHolderNode());">Add AudioHolder / Test Page</button>
				</div>
			</div>
		</div>
	</body>
</html>