diff ape.js @ 1610:63217e7bd1a7

Don't allow to submit before all songs are played (slightly hacky patch)
author Brecht De Man <b.deman@qmul.ac.uk>
date Sun, 17 May 2015 09:00:09 +0100
parents 590e487fe3f1
children 36d5c460f04b
line wrap: on
line diff
--- a/ape.js	Sat May 16 20:58:15 2015 +0100
+++ b/ape.js	Sun May 17 09:00:09 2015 +0100
@@ -11,6 +11,10 @@
 // postTest - End of test, final submission!
 
 
+// Create empty array to log whether different samples have been played
+var hasBeenPlayed = []; // HERE?
+
+
 // Once this is loaded and parsed, begin execution
 loadInterface(projectXML);
 
@@ -493,16 +497,20 @@
             document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
             for (var i = 0; i<$(currentTrackOrder).length; i++)
             {
-                if (i!=index)
+                if (i!=index) // Make all other sliders green
                 {
                     document.getElementById('track-slider-'+i).style.backgroundColor = "rgb(100,200,100)";
                 }
                               
             }
             audioEngineContext.play();
+            hasBeenPlayed[index] = true; // mark as played
 		};
 		
 		canvas.appendChild(trackSliderObj);
+        
+        // Add corresponding element to array to check whether sound has been played
+        hasBeenPlayed.push(false);
 	});
 	
 	// Append any commentQuestion boxes
@@ -781,23 +789,31 @@
 
 function buttonSubmitClick() // TODO: Only when all songs have been played!
 {
-	if (audioEngineContext.status == 1) {
-		var playback = document.getElementById('playback-button');
-		playback.click();
-	// This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
-	} else
-	{
-		if (audioEngineContext.timer.testStarted == false)
-		{
-			alert('You have not started the test! Please press start to begin the test!');
-			return;
-		}
-	}
-	if (currentState.substr(0,7) == 'testRun')
-	{
-		audioEngineContext.timer.stopTest();
-		advanceState();
-	}
+    if (hasBeenPlayed.indexOf(false)==-1)
+        {
+        if (audioEngineContext.status == 1) {
+            var playback = document.getElementById('playback-button');
+            playback.click();
+        // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
+        } else
+        {
+            if (audioEngineContext.timer.testStarted == false)
+            {
+                alert('You have not started the test! Please press start to begin the test!');
+                return;
+            }
+        }
+        if (currentState.substr(0,7) == 'testRun')
+        {
+            hasBeenPlayed = []; // clear array to prepare for next test
+            audioEngineContext.timer.stopTest();
+            advanceState();
+        }
+    } else // if a fragment has not been played yet
+    {
+        alert('You have not played fragment ' + hasBeenPlayed.indexOf(false) + ' yet. Please listen, rate and comment all samples before submitting.');
+        return;
+    }
 }
 
 function convSliderPosToRate(id)