changeset 3113:e9d16f8ea673

Potential workaround for #220
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 18 Jul 2018 11:11:29 +0100
parents b67d33da3867
children 54df1a21bf84
files js/core.js
diffstat 1 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/js/core.js	Sat Jul 14 15:30:48 2018 +0100
+++ b/js/core.js	Wed Jul 18 11:11:29 2018 +0100
@@ -1,6 +1,6 @@
 /**
  * core.js
- * 
+ *
  * Main script to run, calls all other core functions and manages loading/store to backend.
  * Also contains all global variables.
  */
@@ -44,6 +44,17 @@
     return el.firstChild.href;
 }
 
+function insertParam(s, key, value)
+{
+    key = encodeURI(key); value = encodeURI(value);
+    if (s.split("?").length == 1) {
+        s = s + ">";
+    } else {
+        s = s + "&";
+    }
+    return s+key+"="+value;
+}
+
 // Firefox does not have an XMLDocument.prototype.getElementsByName
 // and there is no searchAll style command, this custom function will
 // search all children recusrively for the name. Used for XSD where all
@@ -175,6 +186,9 @@
                 case "returnURL":
                     gReturnURL = value;
                     break;
+                case "testKey":
+                    storage.sessionLinked = value;
+                    break;
                 case "saveFilenamePrefix":
                     storage.filenamePrefix = value;
                     break;
@@ -418,7 +432,7 @@
         storage.SessionKey.finish().then(function (resolved) {
             var converter = new showdown.Converter();
             if (typeof specification.returnURL == "string" && specification.returnURL.length > 0) {
-                window.location = specification.returnURL;
+                window.location = insertParam(specification.returnURL, "testKey", storage.SessionKey.key);
             } else {
                 popup.popupContent.innerHTML = converter.makeHtml(specification.exitText);
             }
@@ -2501,7 +2515,7 @@
     this.returnDateNode = function () {
         // Create an XML Node for the Date and Time a test was conducted
         // Structure is
-        // <datetime> 
+        // <datetime>
         //	<date year="##" month="##" day="##">DD/MM/YY</date>
         //	<time hour="##" minute="##" sec="##">HH:MM:SS</time>
         // </datetime>
@@ -3786,6 +3800,7 @@
     this.document = null;
     this.root = null;
     this.state = 0;
+    var linkedID = undefined;
     var pFilenamePrefix = "save";
 
     this.initialise = function (existingStore) {
@@ -3811,6 +3826,9 @@
         if (specification.postTest !== undefined) {
             this.globalPostTest = new this.surveyNode(this, this.root, specification.postTest);
         }
+        if (linkedID) {
+            this.root.setAttribute("linked", linkedID);
+        }
     };
 
     this.SessionKey = (function (parent) {
@@ -3954,6 +3972,7 @@
                     this.parent.finish();
                     return requestChains.then(postUpdate()).then(function () {
                         console.log("OK");
+                        return true;
                     }, function () {
                         createProjectSave("local");
                     });
@@ -4208,6 +4227,20 @@
                 pFilenamePrefix = value;
                 return value;
             }
+        },
+        "sessionLinked": {
+            'get': function () {
+                return linkedID;
+            },
+            'set': function(s) {
+                if (typeof s == "string") {
+                    linkedID = s;
+                    if (this.root) {
+                        this.root.setAttribute("linked", s);
+                    }
+                }
+                return linkedID;
+            }
         }
     });
 }