changeset 918:1e1339e51701

Added check box mode to pre/post test survey
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Fri, 05 Jun 2015 12:10:49 +0100
parents 9d6803ed2fb8
children dd36d98cd4f9
files core.js example_eval/project.xml
diffstat 2 files changed, 82 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/core.js	Fri Jun 05 11:32:09 2015 +0100
+++ b/core.js	Fri Jun 05 12:10:49 2015 +0100
@@ -121,6 +121,29 @@
 			this.popupContent.appendChild(br);
 			this.popupContent.appendChild(textArea);
 			this.popupContent.childNodes[2].focus();
+		} else if (node.type == 'checkbox') {
+			var span = document.createElement('span');
+			span.textContent = node.statement;
+			this.popupContent.appendChild(span);
+			var optHold = document.createElement('div');
+			optHold.id = 'option-holder';
+			optHold.align = 'left';
+			for (var i=0; i<node.options.length; i++) {
+				var option = node.options[i];
+				var input = document.createElement('input');
+				input.id = option.id;
+				input.type = 'checkbox';
+				var span = document.createElement('span');
+				span.textContent = option.text;
+				var hold = document.createElement('div');
+				hold.setAttribute('name','option');
+				hold.style.float = 'left';
+				hold.style.padding = '4px';
+				hold.appendChild(input);
+				hold.appendChild(span);
+				optHold.appendChild(hold);
+			}
+			this.popupContent.appendChild(optHold);
 		}
 		this.popupContent.appendChild(this.popupButton);
 	};
@@ -164,6 +187,21 @@
 				console.log("Question Response: "+ textArea.value);
 				this.responses.appendChild(hold);
 			}
+		} else if (node.type == 'checkbox') {
+			// Must extract checkbox data
+			var optHold = document.getElementById('option-holder');
+			var hold = document.createElement('checkbox');
+			console.log("Checkbox: "+ node.statement);
+			for (var i=0; i<optHold.childElementCount; i++) {
+				var input = optHold.childNodes[i].getElementsByTagName('input')[0];
+				var statement = optHold.childNodes[i].getElementsByTagName('span')[0];
+				var response = document.createElement('option');
+				response.setAttribute('id',input.id);
+				response.setAttribute('checked',input.checked);
+				hold.appendChild(response);
+				console.log(input.id +': '+ input.checked);
+			}
+			this.responses.appendChild(hold);
 		}
 		this.currentIndex++;
 		if (this.currentIndex < this.popupOptions.length) {
@@ -1014,6 +1052,13 @@
 		this.options = [];
 		
 		this.OptionNode = function(child) {
+			
+			this.childOption = function(element) {
+				this.type = 'option';
+				this.id = element.id;
+				this.text = element.textContent;
+			}
+			
 			this.type = child.nodeName;
 			if (child.nodeName == "question") {
 				this.id = child.id;
@@ -1023,6 +1068,23 @@
 				this.question = child.textContent;
 			} else if (child.nodeName == "statement") {
 				this.statement = child.textContent;
+			} else if (child.nodeName == "checkbox") {
+				var element = child.firstElementChild;
+				if (element == null) {
+					console.log('Malformed checkbox entry');
+					this.statement = 'Malformed checkbox entry';
+					this.type = 'statement';
+				} else {
+					this.options = [];
+					while (element != null) {
+						if (element.nodeName == 'statement' && this.statement == undefined){
+							this.statement = element.textContent;
+						} else if (element.nodeName == 'option') {
+							this.options.push(new this.childOption(element));
+						}
+						element = element.nextElementSibling;
+					}
+				}
 			}
 		};
 		
--- a/example_eval/project.xml	Fri Jun 05 11:32:09 2015 +0100
+++ b/example_eval/project.xml	Fri Jun 05 12:10:49 2015 +0100
@@ -3,6 +3,14 @@
 	<setup interface="APE" projectReturn="/save" randomiseOrder='true' collectMetrics='true'>
 		<PreTest>
 			<question id="Location" mandatory="true">Please enter your location.</question>
+			<checkbox id="experience">
+				<statement>Check options which are relevant to you</statement>
+				<option id="digital">Digital Consoles</option>
+				<option id="analog">Analog Consoles</option>
+				<option id="live">Live Mixing</option>
+				<option id="studio">Studio Mixing</option>
+				<option id="player">Play an instrument</option>
+			</checkbox>
 			<statement>Please listen to all mixes</statement>
 		</PreTest>
 		<PostTest>
@@ -32,52 +40,24 @@
 		<audioElements url="1.wav" id="1"/>
 		<audioElements url="2.wav" id="2"/>
 		<audioElements url="3.wav" id="3"/>
-		<audioElements url="4.wav" id="4"/>
+		<!--<audioElements url="4.wav" id="4"/>
 		<audioElements url="5.wav" id="5"/>
 		<audioElements url="6.wav" id="6"/>
 		<audioElements url="7.wav" id="7"/>
 		<audioElements url="8.wav" id="8"/>
 		<audioElements url="9.wav" id="9"/>
-		<audioElements url="10.wav" id="10"/>
+		<audioElements url="10.wav" id="10"/>-->
 		<CommentQuestion id='mixingExperience'>What is your mixing experience</CommentQuestion>
-		<PostTest>
-			<question id="genre" mandatory="true">Please enter the genre</question>
-		</PostTest>
-	</audioHolder>
-	<audioHolder id='1' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='true' elementComments='true'>
-		<interface>
-			<title>Example Test Question</title>
-			<scale position="0">Min</scale>
-			<scale position="100">Max</scale>
-			<scale position="50">Middle</scale>
-			<scale position="20">20</scale>
-			<commentBoxPrefix>Comment on fragment</commentBoxPrefix>
-		</interface>
-		<audioElements url="0.wav" id="0"/>
-		<audioElements url="1.wav" id="1"/>
-		<audioElements url="2.wav" id="2"/>
-		<audioElements url="3.wav" id="3"/>
-		<CommentQuestion id='mixingExperience'>What is your mixing experience</CommentQuestion>
-		<PostTest>
-			<question id="genre" mandatory="true">Please enter the genre</question>
-		</PostTest>
-	</audioHolder>
-	<audioHolder id='2' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='true' elementComments='true'>
-		<interface>
-			<title>Example Test Question</title>
-			<scale position="0">Min</scale>
-			<scale position="100">Max</scale>
-			<scale position="50">Middle</scale>
-			<scale position="20">20</scale>
-			<commentBoxPrefix>Comment on fragment</commentBoxPrefix>
-		</interface>
-		<audioElements url="0.wav" id="0"/>
-		<audioElements url="1.wav" id="1"/>
-		<audioElements url="2.wav" id="2"/>
-		<audioElements url="3.wav" id="3"/>
-		<audioElements url="4.wav" id="4"/>
-		<audioElements url="5.wav" id="5"/>
-		<CommentQuestion id='mixingExperience'>What is your mixing experience</CommentQuestion>
+		<PreTest>
+			<checkbox id="experience">
+				<statement>Check options which are relevant to you</statement>
+				<option id="digital">Digital Consoles</option>
+				<option id="analog">Analog Consoles</option>
+				<option id="live">Live Mixing</option>
+				<option id="studio">Studio Mixing</option>
+				<option id="player">Play an instrument</option>
+			</checkbox>
+		</PreTest>
 		<PostTest>
 			<question id="genre" mandatory="true">Please enter the genre</question>
 		</PostTest>