comparison js/core.js @ 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 1ae8c03dd6a6
children f78a66fbc018
comparison
equal deleted inserted replaced
3112:b67d33da3867 3113:e9d16f8ea673
1 /** 1 /**
2 * core.js 2 * core.js
3 * 3 *
4 * Main script to run, calls all other core functions and manages loading/store to backend. 4 * Main script to run, calls all other core functions and manages loading/store to backend.
5 * Also contains all global variables. 5 * Also contains all global variables.
6 */ 6 */
7 7
8 /*globals window, document, XMLDocument, Element, XMLHttpRequest, DOMParser, console, Blob, $, Promise, navigator */ 8 /*globals window, document, XMLDocument, Element, XMLHttpRequest, DOMParser, console, Blob, $, Promise, navigator */
40 40
41 function qualifyURL(url) { 41 function qualifyURL(url) {
42 var el = document.createElement('div'); 42 var el = document.createElement('div');
43 el.innerHTML = '<a href="' + escapeHTML(url) + '">x</a>'; 43 el.innerHTML = '<a href="' + escapeHTML(url) + '">x</a>';
44 return el.firstChild.href; 44 return el.firstChild.href;
45 }
46
47 function insertParam(s, key, value)
48 {
49 key = encodeURI(key); value = encodeURI(value);
50 if (s.split("?").length == 1) {
51 s = s + ">";
52 } else {
53 s = s + "&";
54 }
55 return s+key+"="+value;
45 } 56 }
46 57
47 // Firefox does not have an XMLDocument.prototype.getElementsByName 58 // Firefox does not have an XMLDocument.prototype.getElementsByName
48 // and there is no searchAll style command, this custom function will 59 // and there is no searchAll style command, this custom function will
49 // search all children recusrively for the name. Used for XSD where all 60 // search all children recusrively for the name. Used for XSD where all
172 url = value; 183 url = value;
173 specification.url = url; 184 specification.url = url;
174 break; 185 break;
175 case "returnURL": 186 case "returnURL":
176 gReturnURL = value; 187 gReturnURL = value;
188 break;
189 case "testKey":
190 storage.sessionLinked = value;
177 break; 191 break;
178 case "saveFilenamePrefix": 192 case "saveFilenamePrefix":
179 storage.filenamePrefix = value; 193 storage.filenamePrefix = value;
180 break; 194 break;
181 } 195 }
416 } 430 }
417 } 431 }
418 storage.SessionKey.finish().then(function (resolved) { 432 storage.SessionKey.finish().then(function (resolved) {
419 var converter = new showdown.Converter(); 433 var converter = new showdown.Converter();
420 if (typeof specification.returnURL == "string" && specification.returnURL.length > 0) { 434 if (typeof specification.returnURL == "string" && specification.returnURL.length > 0) {
421 window.location = specification.returnURL; 435 window.location = insertParam(specification.returnURL, "testKey", storage.SessionKey.key);
422 } else { 436 } else {
423 popup.popupContent.innerHTML = converter.makeHtml(specification.exitText); 437 popup.popupContent.innerHTML = converter.makeHtml(specification.exitText);
424 } 438 }
425 }, function (message) { 439 }, function (message) {
426 console.log("Save: Error! " + message.textContent); 440 console.log("Save: Error! " + message.textContent);
2499 }; 2513 };
2500 2514
2501 this.returnDateNode = function () { 2515 this.returnDateNode = function () {
2502 // Create an XML Node for the Date and Time a test was conducted 2516 // Create an XML Node for the Date and Time a test was conducted
2503 // Structure is 2517 // Structure is
2504 // <datetime> 2518 // <datetime>
2505 // <date year="##" month="##" day="##">DD/MM/YY</date> 2519 // <date year="##" month="##" day="##">DD/MM/YY</date>
2506 // <time hour="##" minute="##" sec="##">HH:MM:SS</time> 2520 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
2507 // </datetime> 2521 // </datetime>
2508 var dateTime = new Date(); 2522 var dateTime = new Date();
2509 var hold = storage.document.createElement("datetime"); 2523 var hold = storage.document.createElement("datetime");
3784 this.globalPostTest = null; 3798 this.globalPostTest = null;
3785 this.testPages = []; 3799 this.testPages = [];
3786 this.document = null; 3800 this.document = null;
3787 this.root = null; 3801 this.root = null;
3788 this.state = 0; 3802 this.state = 0;
3803 var linkedID = undefined;
3789 var pFilenamePrefix = "save"; 3804 var pFilenamePrefix = "save";
3790 3805
3791 this.initialise = function (existingStore) { 3806 this.initialise = function (existingStore) {
3792 if (existingStore === undefined) { 3807 if (existingStore === undefined) {
3793 // We need to get the sessionKey 3808 // We need to get the sessionKey
3808 if (specification.preTest !== undefined) { 3823 if (specification.preTest !== undefined) {
3809 this.globalPreTest = new this.surveyNode(this, this.root, specification.preTest); 3824 this.globalPreTest = new this.surveyNode(this, this.root, specification.preTest);
3810 } 3825 }
3811 if (specification.postTest !== undefined) { 3826 if (specification.postTest !== undefined) {
3812 this.globalPostTest = new this.surveyNode(this, this.root, specification.postTest); 3827 this.globalPostTest = new this.surveyNode(this, this.root, specification.postTest);
3828 }
3829 if (linkedID) {
3830 this.root.setAttribute("linked", linkedID);
3813 } 3831 }
3814 }; 3832 };
3815 3833
3816 this.SessionKey = (function (parent) { 3834 this.SessionKey = (function (parent) {
3817 var returnURL = ""; 3835 var returnURL = "";
3952 throw ("Cannot save as key == null"); 3970 throw ("Cannot save as key == null");
3953 } 3971 }
3954 this.parent.finish(); 3972 this.parent.finish();
3955 return requestChains.then(postUpdate()).then(function () { 3973 return requestChains.then(postUpdate()).then(function () {
3956 console.log("OK"); 3974 console.log("OK");
3975 return true;
3957 }, function () { 3976 }, function () {
3958 createProjectSave("local"); 3977 createProjectSave("local");
3959 }); 3978 });
3960 } 3979 }
3961 } 3980 }
4206 value = String(value); 4225 value = String(value);
4207 } 4226 }
4208 pFilenamePrefix = value; 4227 pFilenamePrefix = value;
4209 return value; 4228 return value;
4210 } 4229 }
4230 },
4231 "sessionLinked": {
4232 'get': function () {
4233 return linkedID;
4234 },
4235 'set': function(s) {
4236 if (typeof s == "string") {
4237 linkedID = s;
4238 if (this.root) {
4239 this.root.setAttribute("linked", s);
4240 }
4241 }
4242 return linkedID;
4243 }
4211 } 4244 }
4212 }); 4245 });
4213 } 4246 }
4214 4247
4215 var window_depedancy_callback; 4248 var window_depedancy_callback;