changeset 2304:b74241682c17

Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool
author www-data <www-data@sucuk.dcs.qmul.ac.uk>
date Thu, 28 Apr 2016 10:21:05 +0100
parents b1a8d6d311c2 (current diff) e4a2a39838db (diff)
children a5299dfc0814
files
diffstat 5 files changed, 45 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/js/core.js	Wed Apr 27 22:20:54 2016 +0100
+++ b/js/core.js	Thu Apr 28 10:21:05 2016 +0100
@@ -408,7 +408,13 @@
 		popup.popupContent.appendChild(a);
 	} else {
 		var xmlhttp = new XMLHttpRequest;
-		xmlhttp.open("POST","php/save.php?key="+storage.SessionKey.key,true);
+        var returnURL = "";
+        if (typeof specification.projectReturn == "string") {
+            if (specification.projectReturn.substr(0,4) == "http") {
+                returnURL = specification.projectReturn;
+            }
+        }
+		xmlhttp.open("POST",returnURL+"php/save.php?key="+storage.SessionKey.key,true);
 		xmlhttp.setRequestHeader('Content-Type', 'text/xml');
 		xmlhttp.onerror = function(){
 			console.log('Error saving file to server! Presenting download locally');
@@ -424,9 +430,14 @@
                 var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml");
                 var response = xmlDoc.getElementsByTagName('response')[0];
                 if (response.getAttribute("state") == "OK") {
+                    window.onbeforeunload = undefined;
                     var file = response.getElementsByTagName("file")[0];
                     console.log("Save: OK, written "+file.getAttribute("bytes")+"B");
-                    popup.popupContent.textContent = specification.exitText;
+                    if (typeof specification.returnURL == "string") {
+                        window.location = returnURL;
+                    } else {
+                        popup.popupContent.textContent = specification.exitText;
+                    }
                 } else {
                     var message = response.getElementsByTagName("message");
                     console.log("Save: Error! "+message.textContent);
@@ -2822,24 +2833,41 @@
         handleEvent: function() {
             var parse = new DOMParser();
             var xml = parse.parseFromString(this.request.response,"text/xml");
-            if (xml.getAllElementsByTagName("state")[0].textContent == "OK") {
-                this.key = xml.getAllElementsByTagName("key")[0].textContent;
-                this.parent.root.setAttribute("key",this.key);
-                this.parent.root.setAttribute("state","empty");
-            } else {
-                this.generateKey();
-            }
+            var shouldGenerateKey = true;
+            if(xml.getAllElementsByTagName("state").length > 0){
+				if (xml.getAllElementsByTagName("state")[0].textContent == "OK") {
+					this.key = xml.getAllElementsByTagName("key")[0].textContent;
+					this.parent.root.setAttribute("key",this.key);
+					this.parent.root.setAttribute("state","empty");
+					shouldGenerateKey = false;
+				}
+			}
+			if(shouldGenerateKey === true){
+				this.generateKey();
+			}
         },
         generateKey: function() {
             var temp_key = randomString(32);
-            this.request.open("GET","php/keygen.php?key="+temp_key,true);
+            var returnURL = "";
+            if (typeof specification.projectReturn == "string") {
+                if (specification.projectReturn.substr(0,4) == "http") {
+                    returnURL = specification.projectReturn;
+                }
+            }
+            this.request.open("GET",returnURL+"php/keygen.php?key="+temp_key,true);
             this.request.addEventListener("load",this);
             this.request.send();
         },
         update: function() {
             this.parent.root.setAttribute("state","update");
             var xmlhttp = new XMLHttpRequest();
-            xmlhttp.open("POST","php/"+specification.projectReturn+"?key="+this.key);
+            var returnURL = "";
+            if (typeof specification.projectReturn == "string") {
+                if (specification.projectReturn.substr(0,4) == "http") {
+                    returnURL = specification.projectReturn;
+                }
+            }
+            xmlhttp.open("POST",returnURL+"php/save.php?key="+this.key);
             xmlhttp.setRequestHeader('Content-Type', 'text/xml');
             xmlhttp.onerror = function(){
                 console.log('Error updating file to server!');
--- a/js/specification.js	Wed Apr 27 22:20:54 2016 +0100
+++ b/js/specification.js	Thu Apr 28 10:21:05 2016 +0100
@@ -2,7 +2,8 @@
 	// Handles the decoding of the project specification XML into a simple JavaScript Object.
 	
 	this.interface = null;
-	this.projectReturn = "null";
+	this.projectReturn = null;
+    this.returnURL = null;
 	this.randomiseOrder = null;
 	this.testPages = null;
 	this.pages = [];
--- a/test_create/attributes.json	Wed Apr 27 22:20:54 2016 +0100
+++ b/test_create/attributes.json	Thu Apr 28 10:21:05 2016 +0100
@@ -3,7 +3,8 @@
     "mandatory": "Mandatory",
     "name": "Name",
     "interface": "Interface Module",
-    "projectReturn": "Save URL",
+    "projectReturn": "Save Return URL",
+    "returnURL": "On complete redirect URL",
     "randomiseOrder": "Randomise Order",
     "testPages": "Test Pages",
     "loudness": "Target Loudness (LUFS)",
--- a/tests/examples/radio_example.xml	Wed Apr 27 22:20:54 2016 +0100
+++ b/tests/examples/radio_example.xml	Thu Apr 28 10:21:05 2016 +0100
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd">
-	<setup interface="likert" projectReturn="save.php" crossFade="3.0">
+	<setup interface="likert" projectReturn="save.php" crossFade="3.0">
 		<metric>
 			<metricenable>testTimer</metricenable>
 			<metricenable>elementTimer</metricenable>
--- a/xml/test-schema.xsd	Wed Apr 27 22:20:54 2016 +0100
+++ b/xml/test-schema.xsd	Thu Apr 28 10:21:05 2016 +0100
@@ -47,6 +47,7 @@
                 </xs:sequence>
                 <xs:attribute name="interface" type="xs:string" use="required" />
                 <xs:attribute name="projectReturn" type="xs:string" use="optional" default="" />
+                <xs:attribute name="returnURL" type="xs:string" use="optional" default="" />
                 <xs:attribute name="randomiseOrder" type="xs:boolean" default="false" />
                 <xs:attribute ref="poolSize" />
                 <xs:attribute name="loudness" type="xs:nonPositiveInteger" use="optional" />