Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2722:a087cb7b5972
#186. Interim saves now use the prefix. Re-writting completion save to use correct stores
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Sat, 15 Apr 2017 11:10:38 +0100 |
parents | a6a0d2b786af |
children | 2e1cafe93c78 |
comparison
equal
deleted
inserted
replaced
2720:a6a0d2b786af | 2722:a087cb7b5972 |
---|---|
173 break; | 173 break; |
174 case "returnURL": | 174 case "returnURL": |
175 gReturnURL = value; | 175 gReturnURL = value; |
176 break; | 176 break; |
177 case "saveFilenamePrefix": | 177 case "saveFilenamePrefix": |
178 gSaveFilenamePrefix = value; | 178 storage.filenamePrefix = value; |
179 break; | 179 break; |
180 } | 180 } |
181 } | 181 } |
182 loadProjectSpec(url); | 182 loadProjectSpec(url); |
183 window.onbeforeunload = function () { | 183 window.onbeforeunload = function () { |
1211 testState.advanceState(); | 1211 testState.advanceState(); |
1212 } | 1212 } |
1213 | 1213 |
1214 function stateMachine() { | 1214 function stateMachine() { |
1215 // Object prototype for tracking and managing the test state | 1215 // Object prototype for tracking and managing the test state |
1216 | 1216 |
1217 function pickSubPool(pool, numElements) { | 1217 function pickSubPool(pool, numElements) { |
1218 // Assumes each element of pool has function "alwaysInclude" | 1218 // Assumes each element of pool has function "alwaysInclude" |
1219 | 1219 |
1220 // First extract those excluded from picking process | 1220 // First extract those excluded from picking process |
1221 var picked = []; | 1221 var picked = []; |
1225 } | 1225 } |
1226 }); | 1226 }); |
1227 | 1227 |
1228 return picked.concat(randomSubArray(pool, numElements - picked.length)); | 1228 return picked.concat(randomSubArray(pool, numElements - picked.length)); |
1229 } | 1229 } |
1230 | 1230 |
1231 this.stateMap = []; | 1231 this.stateMap = []; |
1232 this.preTestSurvey = null; | 1232 this.preTestSurvey = null; |
1233 this.postTestSurvey = null; | 1233 this.postTestSurvey = null; |
1234 this.stateIndex = null; | 1234 this.stateIndex = null; |
1235 this.currentStateMap = null; | 1235 this.currentStateMap = null; |
1237 this.currentStore = null; | 1237 this.currentStore = null; |
1238 this.initialise = function () { | 1238 this.initialise = function () { |
1239 | 1239 |
1240 // Get the data from Specification | 1240 // Get the data from Specification |
1241 var pagePool = []; | 1241 var pagePool = []; |
1242 specification.pages.forEach(function(page){ | 1242 specification.pages.forEach(function (page) { |
1243 if (page.position !== null || page.alwaysInclude) { | 1243 if (page.position !== null || page.alwaysInclude) { |
1244 page.alwaysInclude = true; | 1244 page.alwaysInclude = true; |
1245 } | 1245 } |
1246 pagePool.push(page); | 1246 pagePool.push(page); |
1247 }); | 1247 }); |
1250 pagePool = pickSubPool(pagePool, specification.numPages); | 1250 pagePool = pickSubPool(pagePool, specification.numPages); |
1251 } | 1251 } |
1252 | 1252 |
1253 // Now get the order of pages | 1253 // Now get the order of pages |
1254 var fixed = []; | 1254 var fixed = []; |
1255 pagePool.forEach(function(page){ | 1255 pagePool.forEach(function (page) { |
1256 if (page.position !== null) { | 1256 if (page.position !== null) { |
1257 fixed.push(page); | 1257 fixed.push(page); |
1258 var i = pagePool.indexOf(page); | 1258 var i = pagePool.indexOf(page); |
1259 pagePool.splice(i, 1); | 1259 pagePool.splice(i, 1); |
1260 } | 1260 } |
1263 if (specification.randomiseOrder) { | 1263 if (specification.randomiseOrder) { |
1264 pagePool = randomiseOrder(pagePool); | 1264 pagePool = randomiseOrder(pagePool); |
1265 } | 1265 } |
1266 | 1266 |
1267 // Place in the correct order | 1267 // Place in the correct order |
1268 fixed.forEach(function(page) { | 1268 fixed.forEach(function (page) { |
1269 pagePool.splice(page.position, 0, page); | 1269 pagePool.splice(page.position, 0, page); |
1270 }); | 1270 }); |
1271 | 1271 |
1272 // Now process the pages | 1272 // Now process the pages |
1273 pagePool.forEach(function (page, i) { | 1273 pagePool.forEach(function (page, i) { |
2583 | 2583 |
2584 var optCount = commentQuestion.options.length; | 2584 var optCount = commentQuestion.options.length; |
2585 for (var i = 0; i < optCount; i++) { | 2585 for (var i = 0; i < optCount; i++) { |
2586 var div = document.createElement('div'); | 2586 var div = document.createElement('div'); |
2587 div.className = "comment-checkbox-inputs-flex"; | 2587 div.className = "comment-checkbox-inputs-flex"; |
2588 | 2588 |
2589 var span = document.createElement('span'); | 2589 var span = document.createElement('span'); |
2590 span.textContent = commentQuestion.options[i].text; | 2590 span.textContent = commentQuestion.options[i].text; |
2591 span.className = 'comment-radio-span'; | 2591 span.className = 'comment-radio-span'; |
2592 div.appendChild(span); | 2592 div.appendChild(span); |
2593 | 2593 |
2594 var input = document.createElement('input'); | 2594 var input = document.createElement('input'); |
2595 input.type = 'radio'; | 2595 input.type = 'radio'; |
2596 input.name = commentQuestion.id; | 2596 input.name = commentQuestion.id; |
2597 input.setAttribute('setvalue', commentQuestion.options[i].name); | 2597 input.setAttribute('setvalue', commentQuestion.options[i].name); |
2598 input.className = 'comment-radio'; | 2598 input.className = 'comment-radio'; |
2599 div.appendChild(input); | 2599 div.appendChild(input); |
2600 | 2600 |
2601 this.inputs.appendChild(div); | 2601 this.inputs.appendChild(div); |
2602 this.options.push(input); | 2602 this.options.push(input); |
2603 } | 2603 } |
2604 this.holder.appendChild(this.inputs); | 2604 this.holder.appendChild(this.inputs); |
2605 | 2605 |
2658 | 2658 |
2659 var optCount = commentQuestion.options.length; | 2659 var optCount = commentQuestion.options.length; |
2660 for (var i = 0; i < optCount; i++) { | 2660 for (var i = 0; i < optCount; i++) { |
2661 var div = document.createElement('div'); | 2661 var div = document.createElement('div'); |
2662 div.className = "comment-checkbox-inputs-flex"; | 2662 div.className = "comment-checkbox-inputs-flex"; |
2663 | 2663 |
2664 var span = document.createElement('span'); | 2664 var span = document.createElement('span'); |
2665 span.textContent = commentQuestion.options[i].text; | 2665 span.textContent = commentQuestion.options[i].text; |
2666 span.className = 'comment-radio-span'; | 2666 span.className = 'comment-radio-span'; |
2667 div.appendChild(span); | 2667 div.appendChild(span); |
2668 | 2668 |
2669 var input = document.createElement('input'); | 2669 var input = document.createElement('input'); |
2670 input.type = 'checkbox'; | 2670 input.type = 'checkbox'; |
2671 input.name = commentQuestion.id; | 2671 input.name = commentQuestion.id; |
2672 input.setAttribute('setvalue', commentQuestion.options[i].name); | 2672 input.setAttribute('setvalue', commentQuestion.options[i].name); |
2673 input.className = 'comment-radio'; | 2673 input.className = 'comment-radio'; |
2674 div.appendChild(input); | 2674 div.appendChild(input); |
2675 | 2675 |
2676 this.inputs.appendChild(div); | 2676 this.inputs.appendChild(div); |
2677 this.options.push(input); | 2677 this.options.push(input); |
2678 } | 2678 } |
2679 this.holder.appendChild(this.inputs); | 2679 this.holder.appendChild(this.inputs); |
2680 | 2680 |
2838 this.outsideReferenceHolder.style.backgroundColor = "#F00"; | 2838 this.outsideReferenceHolder.style.backgroundColor = "#F00"; |
2839 }; | 2839 }; |
2840 }; | 2840 }; |
2841 | 2841 |
2842 this.playhead = (function () { | 2842 this.playhead = (function () { |
2843 var playhead ={}; | 2843 var playhead = {}; |
2844 playhead.object = document.createElement('div'); | 2844 playhead.object = document.createElement('div'); |
2845 playhead.object.className = 'playhead'; | 2845 playhead.object.className = 'playhead'; |
2846 playhead.object.align = 'left'; | 2846 playhead.object.align = 'left'; |
2847 var curTime = document.createElement('div'); | 2847 var curTime = document.createElement('div'); |
2848 curTime.style.width = '50px'; | 2848 curTime.style.width = '50px'; |
3400 this.globalPostTest = null; | 3400 this.globalPostTest = null; |
3401 this.testPages = []; | 3401 this.testPages = []; |
3402 this.document = null; | 3402 this.document = null; |
3403 this.root = null; | 3403 this.root = null; |
3404 this.state = 0; | 3404 this.state = 0; |
3405 var pFilenamePrefix = ""; | |
3405 | 3406 |
3406 this.initialise = function (existingStore) { | 3407 this.initialise = function (existingStore) { |
3407 if (existingStore === undefined) { | 3408 if (existingStore === undefined) { |
3408 // We need to get the sessionKey | 3409 // We need to get the sessionKey |
3409 this.SessionKey.requestKey(); | 3410 this.SessionKey.requestKey(); |
3478 if (typeof specification.projectReturn == "string") { | 3479 if (typeof specification.projectReturn == "string") { |
3479 if (specification.projectReturn.substr(0, 4) == "http") { | 3480 if (specification.projectReturn.substr(0, 4) == "http") { |
3480 returnURL = specification.projectReturn; | 3481 returnURL = specification.projectReturn; |
3481 } | 3482 } |
3482 } | 3483 } |
3483 xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key); | 3484 xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key + "&saveFilenamePrefix=" + this.parent.filenamePrefix); |
3484 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); | 3485 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); |
3485 xmlhttp.onerror = function () { | 3486 xmlhttp.onerror = function () { |
3486 console.log('Error updating file to server!'); | 3487 console.log('Error updating file to server!'); |
3487 }; | 3488 }; |
3488 var hold = document.createElement("div"); | 3489 var hold = document.createElement("div"); |
3648 } | 3649 } |
3649 this.state = 1; | 3650 this.state = 1; |
3650 this.root.setAttribute("state", "complete"); | 3651 this.root.setAttribute("state", "complete"); |
3651 return this.root; | 3652 return this.root; |
3652 }; | 3653 }; |
3654 | |
3655 Object.defineProperties(this, { | |
3656 'filenamePrefix': { | |
3657 'get': function () { | |
3658 return pFilenamePrefix; | |
3659 }, | |
3660 'set': function (value) { | |
3661 if (typeof value !== "string") { | |
3662 value = String(value); | |
3663 } | |
3664 pFilenamePrefix = value; | |
3665 return value; | |
3666 } | |
3667 } | |
3668 }) | |
3653 } | 3669 } |
3654 | 3670 |
3655 var window_depedancy_callback; | 3671 var window_depedancy_callback; |
3656 window_depedancy_callback = window.setInterval(function () { | 3672 window_depedancy_callback = window.setInterval(function () { |
3657 if (check_dependancies()) { | 3673 if (check_dependancies()) { |