changeset 663:ba6cc0a042d8

Completed Pre-Test of global test and page tests
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 10 Apr 2015 14:52:39 +0100
parents 2991b5476c7c
children efeaf92d9906
files ape.js example_eval/project.xml
diffstat 2 files changed, 81 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Fri Apr 10 13:46:04 2015 +0100
+++ b/ape.js	Fri Apr 10 14:52:39 2015 +0100
@@ -146,34 +146,7 @@
 	if (preTest != undefined && preTest.children.length >= 1)
 	{
 		showPopup();
-		
-		// Parse the first box
-		var preTestOption = document.createElement('div');
-		preTestOption.id = 'preTest';
-		preTestOption.style.marginTop = '25px';
-		preTestOption.align = "center";
-		var child = preTest.children[0];
-		if (child.nodeName == 'statement')
-		{
-			preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
-		} else if (child.nodeName == 'question')
-		{
-			var questionId = child.attributes['id'].value;
-			var textHold = document.createElement('span');
-			textHold.innerHTML = child.innerHTML;
-			textHold.id = questionId + 'response';
-			var textEnter = document.createElement('textarea');
-			preTestOption.appendChild(textHold);
-			preTestOption.appendChild(textEnter);
-		}
-		var nextButton = document.createElement('button');
-		nextButton.className = 'popupButton';
-		nextButton.value = '0';
-		nextButton.innerHTML = 'Next';
-		nextButton.onclick = popupButtonClick;
-		
-		popupHolder.appendChild(preTestOption);
-		popupHolder.appendChild(nextButton);
+		preTestPopupStart(preTest);
 	}
 	
 	// Inject into HTML
@@ -184,13 +157,13 @@
 	insertPoint.appendChild(testContent);
 
 	// Load the full interface
-	loadTest(testXMLSetups[0]);
+	
 }
 
-function loadTest(textXML)
+function loadTest(id)
 {
 	// Used to load a specific test page
-	
+	var textXML = testXMLSetups[id];
 	
 	var feedbackHolder = document.getElementById('feedbackHolder');
 	var canvas = document.getElementById('slider');
@@ -268,6 +241,51 @@
 		
 		canvas.appendChild(trackSliderObj);
 	});
+	
+	// Now process any pre-test commands
+	
+	var preTest = testXMLSetups.find('PreTest')[0];
+	if (preTest.children.length > 0)
+	{
+		currentState = 'testRunPre-'+id;
+		preTestPopupStart(preTest);
+		showPopup();
+	} else {
+		currentState = 'testRun-'+id;
+	}
+}
+
+function preTestPopupStart(preTest)
+{
+	var popupHolder = document.getElementById('popupHolder');
+	popupHolder.innerHTML = null;
+	// Parse the first box
+	var preTestOption = document.createElement('div');
+	preTestOption.id = 'preTest';
+	preTestOption.style.marginTop = '25px';
+	preTestOption.align = "center";
+	var child = preTest.children[0];
+	if (child.nodeName == 'statement')
+	{
+		preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
+	} else if (child.nodeName == 'question')
+	{
+		var questionId = child.attributes['id'].value;
+		var textHold = document.createElement('span');
+		textHold.innerHTML = child.innerHTML;
+		textHold.id = questionId + 'response';
+		var textEnter = document.createElement('textarea');
+		preTestOption.appendChild(textHold);
+		preTestOption.appendChild(textEnter);
+	}
+	var nextButton = document.createElement('button');
+	nextButton.className = 'popupButton';
+	nextButton.value = '0';
+	nextButton.innerHTML = 'Next';
+	nextButton.onclick = popupButtonClick;
+	
+	popupHolder.appendChild(preTestOption);
+	popupHolder.appendChild(nextButton);
 }
 
 function popupButtonClick()
@@ -276,16 +294,22 @@
 	if (currentState == 'preTest')
 	{
 		// At the start of the preTest routine!
-		this.value = preTestButtonClick(this.value);
+		var xmlTree = projectXML.find('setup');
+		var preTest = xmlTree.find('PreTest')[0];
+		this.value = preTestButtonClick(preTest,this.value);
+	} else if (currentState.substr(0,10) == 'testRunPre')
+	{
+		//Specific test pre-test
+		var testId = currentState.substr(11,currentState.length-10);
+		var preTest = testXMLSetups.find('PreTest')[testId];
+		this.value = preTestButtonClick(preTest,this.value);
 	}
 }
 
-function preTestButtonClick(index)
+function preTestButtonClick(preTest,index)
 {
 	// Called on click of pre-test button
 	// Need to find and parse preTest again!
-	var xmlSetup = projectXML.find('setup');
-	var preTest = xmlSetup.find('PreTest')[0];
 	var preTestOption = document.getElementById('preTest');
 	// Check if current state is a question!
 	if (preTest.children[index].nodeName == 'question') {
@@ -321,6 +345,7 @@
 		preTestOption.innerHTML = null;
 		hidePopup();
 		// Progress the state!
+		advanceState();
 	}
 	return index;
 }
@@ -359,6 +384,22 @@
 	}
 }
 
+function advanceState()
+{
+	console.log(currentState);
+	if (currentState == 'preTest')
+	{
+		// End of pre-test, begin the test
+		loadTest(0);
+	} else if (currentState.substr(0,10) == 'testRunPre')
+	{
+		// Start the test
+		var testId = currentState.substr(11,currentState.length-10);
+		currentState = 'testRun-'+testId;
+	}
+	console.log(currentState);
+}
+
 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
 function interfaceXMLSave(){
 	// Create the XML string to be exported with results
--- a/example_eval/project.xml	Fri Apr 10 13:46:04 2015 +0100
+++ b/example_eval/project.xml	Fri Apr 10 14:52:39 2015 +0100
@@ -30,7 +30,11 @@
 		<audioElements url="9.wav"/>
 		<audioElements url="10.wav"/>
 		<CommentQuestion id='mixingExperiance'>What is your mixing experiance</CommentQuestion>
-		<PreTest/>
+		<PreTest>
+			<statement>Start the Test 3</statement>
+			<statement>Start the Test 2</statement>
+			<statement>Start the Test 1</statement>
+		</PreTest>
 		<PostTest>
 			<statement>Please take a break before the next test</statement>
 		</PostTest>