Mercurial > hg > webaudioevaluationtool
comparison core.js @ 602:6531e3903ea1
Intermediate saves can be used to resume a test. Note, previous saves will NOT work for resumption. To resume, use the save XML as the ?url= option.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 10 Mar 2016 15:33:39 +0000 |
parents | 0df685136c89 |
children | 640ffb822da1 |
comparison
equal
deleted
inserted
replaced
601:0df685136c89 | 602:6531e3903ea1 |
---|---|
218 // Generate the session-key | 218 // Generate the session-key |
219 storage.initialise(); | 219 storage.initialise(); |
220 | 220 |
221 } else if (responseDocument.children[0].nodeName == "waetresult") { | 221 } else if (responseDocument.children[0].nodeName == "waetresult") { |
222 // document is a result | 222 // document is a result |
223 projectXML = responseDocument.getElementsByTagName('waet')[0]; | 223 projectXML = document.implementation.createDocument(null,"waet"); |
224 projectXML.children[0].appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true)); | |
225 var child = responseDocument.children[0].children[0]; | |
226 while (child != null) { | |
227 if (child.nodeName == "survey") { | |
228 // One of the global survey elements | |
229 if (child.getAttribute("state") == "complete") { | |
230 // We need to remove this survey from <setup> | |
231 var location = child.getAttribute("location"); | |
232 var globalSurveys = projectXML.getElementsByTagName("setup")[0].getElementsByTagName("survey")[0]; | |
233 while(globalSurveys != null) { | |
234 if (location == "pre" || location == "before") { | |
235 if (globalSurveys.getAttribute("location") == "pre" || globalSurveys.getAttribute("location") == "before") { | |
236 projectXML.getElementsByTagName("setup")[0].removeChild(globalSurveys); | |
237 break; | |
238 } | |
239 } else { | |
240 if (globalSurveys.getAttribute("location") == "post" || globalSurveys.getAttribute("location") == "after") { | |
241 projectXML.getElementsByTagName("setup")[0].removeChild(globalSurveys); | |
242 break; | |
243 } | |
244 } | |
245 globalSurveys = globalSurveys.nextElementSibling; | |
246 } | |
247 } else { | |
248 // We need to complete this, so it must be regenerated by store | |
249 var copy = child; | |
250 child = child.previousElementSibling; | |
251 responseDocument.children[0].removeChild(copy); | |
252 } | |
253 } else if (child.nodeName == "page") { | |
254 if (child.getAttribute("state") == "empty") { | |
255 // We need to complete this page | |
256 projectXML.children[0].appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true)); | |
257 var copy = child; | |
258 child = child.previousElementSibling; | |
259 responseDocument.children[0].removeChild(copy); | |
260 } | |
261 } | |
262 child = child.nextElementSibling; | |
263 } | |
224 // Build the specification | 264 // Build the specification |
225 specification.decode(projectXML); | 265 specification.decode(projectXML); |
226 // Use the session-key | 266 // Use the original |
227 var sessionKey = responseDocument.children[0].getAttribute(key); | 267 storage.initialise(responseDocument); |
228 storage.initialise(sessionKey); | |
229 } | 268 } |
230 /// CHECK FOR SAMPLE RATE COMPATIBILITY | 269 /// CHECK FOR SAMPLE RATE COMPATIBILITY |
231 if (specification.sampleRate != undefined) { | 270 if (specification.sampleRate != undefined) { |
232 if (Number(specification.sampleRate) != audioContext.sampleRate) { | 271 if (Number(specification.sampleRate) != audioContext.sampleRate) { |
233 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; | 272 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; |
715 this.hidePopup(); | 754 this.hidePopup(); |
716 for (var node of this.popupOptions) | 755 for (var node of this.popupOptions) |
717 { | 756 { |
718 this.store.postResult(node); | 757 this.store.postResult(node); |
719 } | 758 } |
759 this.store.complete(); | |
720 advanceState(); | 760 advanceState(); |
721 } | 761 } |
722 }; | 762 }; |
723 | 763 |
724 this.previousClick = function() { | 764 this.previousClick = function() { |
921 for (var element of interfaceContext.commentQuestions) | 961 for (var element of interfaceContext.commentQuestions) |
922 { | 962 { |
923 element.exportXMLDOM(storePoint); | 963 element.exportXMLDOM(storePoint); |
924 } | 964 } |
925 pageXMLSave(storePoint.XMLDOM, this.currentStateMap); | 965 pageXMLSave(storePoint.XMLDOM, this.currentStateMap); |
966 storePoint.complete(); | |
926 }; | 967 }; |
927 } | 968 } |
928 | 969 |
929 function AudioEngine(specification) { | 970 function AudioEngine(specification) { |
930 | 971 |
1174 this.audioObjects[audioObjectId].url = URL; | 1215 this.audioObjects[audioObjectId].url = URL; |
1175 // Obtain store node | 1216 // Obtain store node |
1176 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement'); | 1217 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement'); |
1177 for (var i=0; i<aeNodes.length; i++) | 1218 for (var i=0; i<aeNodes.length; i++) |
1178 { | 1219 { |
1179 if(aeNodes[i].id == element.id) | 1220 if(aeNodes[i].getAttribute("ref") == element.id) |
1180 { | 1221 { |
1181 this.audioObjects[audioObjectId].storeDOM = aeNodes[i]; | 1222 this.audioObjects[audioObjectId].storeDOM = aeNodes[i]; |
1182 break; | 1223 break; |
1183 } | 1224 } |
1184 } | 1225 } |
3101 { | 3142 { |
3102 // Holds results in XML format until ready for collection | 3143 // Holds results in XML format until ready for collection |
3103 this.globalPreTest = null; | 3144 this.globalPreTest = null; |
3104 this.globalPostTest = null; | 3145 this.globalPostTest = null; |
3105 this.testPages = []; | 3146 this.testPages = []; |
3106 this.document = document.implementation.createDocument(null,"waetresult"); | 3147 this.document = null; |
3107 this.root = this.document.childNodes[0]; | 3148 this.root = null; |
3108 this.state = 0; | 3149 this.state = 0; |
3109 | 3150 |
3110 this.initialise = function(sessionKey) | 3151 this.initialise = function(existingStore) |
3111 { | 3152 { |
3112 if (sessionKey == undefined) { | 3153 if (existingStore == undefined) { |
3113 // We need to get the sessionKey | 3154 // We need to get the sessionKey |
3114 this.SessionKey.generateKey(); | 3155 this.SessionKey.generateKey(); |
3156 this.document = document.implementation.createDocument(null,"waetresult"); | |
3157 this.root = this.document.childNodes[0]; | |
3115 var projectDocument = specification.projectXML; | 3158 var projectDocument = specification.projectXML; |
3116 projectDocument.setAttribute('file-name',url); | 3159 projectDocument.setAttribute('file-name',url); |
3117 this.root.appendChild(projectDocument); | 3160 this.root.appendChild(projectDocument); |
3118 this.root.appendChild(returnDateNode()); | 3161 this.root.appendChild(returnDateNode()); |
3119 this.root.appendChild(interfaceContext.returnNavigator()); | 3162 this.root.appendChild(interfaceContext.returnNavigator()); |
3120 } else { | 3163 } else { |
3121 this.SessionKey.key = sessionKey; | 3164 this.document = existingStore; |
3165 this.root = existingStore.children[0]; | |
3166 this.SessionKey.key = this.root.getAttribute("key"); | |
3122 } | 3167 } |
3123 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} | 3168 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} |
3124 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} | 3169 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} |
3125 }; | 3170 }; |
3126 | 3171 |
3127 this.SessionKey = { | 3172 this.SessionKey = { |
3128 key: null, | 3173 key: null, |
3129 request: new XMLHttpRequest(), | 3174 request: new XMLHttpRequest(), |
3185 | 3230 |
3186 this.surveyNode = function(parent,root,specification) | 3231 this.surveyNode = function(parent,root,specification) |
3187 { | 3232 { |
3188 this.specification = specification; | 3233 this.specification = specification; |
3189 this.parent = parent; | 3234 this.parent = parent; |
3235 this.state = "empty"; | |
3190 this.XMLDOM = this.parent.document.createElement('survey'); | 3236 this.XMLDOM = this.parent.document.createElement('survey'); |
3191 this.XMLDOM.setAttribute('location',this.specification.location); | 3237 this.XMLDOM.setAttribute('location',this.specification.location); |
3238 this.XMLDOM.setAttribute("state",this.state); | |
3192 for (var optNode of this.specification.options) | 3239 for (var optNode of this.specification.options) |
3193 { | 3240 { |
3194 if (optNode.type != 'statement') | 3241 if (optNode.type != 'statement') |
3195 { | 3242 { |
3196 var node = this.parent.document.createElement('surveyresult'); | 3243 var node = this.parent.document.createElement('surveyresult'); |
3197 node.id = optNode.id; | 3244 node.setAttribute("ref",optNode.id); |
3198 node.setAttribute('type',optNode.type); | 3245 node.setAttribute('type',optNode.type); |
3199 this.XMLDOM.appendChild(node); | 3246 this.XMLDOM.appendChild(node); |
3200 } | 3247 } |
3201 } | 3248 } |
3202 root.appendChild(this.XMLDOM); | 3249 root.appendChild(this.XMLDOM); |
3204 this.postResult = function(node) | 3251 this.postResult = function(node) |
3205 { | 3252 { |
3206 // From popup: node is the popupOption node containing both spec. and results | 3253 // From popup: node is the popupOption node containing both spec. and results |
3207 // ID is the position | 3254 // ID is the position |
3208 if (node.specification.type == 'statement'){return;} | 3255 if (node.specification.type == 'statement'){return;} |
3209 var surveyresult = this.parent.document.getElementById(node.specification.id); | 3256 var surveyresult = this.XMLDOM.children[0]; |
3257 while(surveyresult != null) { | |
3258 if (surveyresult.getAttribute("ref") == node.specification.id) | |
3259 { | |
3260 break; | |
3261 } | |
3262 surveyresult = surveyresult.nextElementSibling; | |
3263 } | |
3210 switch(node.specification.type) | 3264 switch(node.specification.type) |
3211 { | 3265 { |
3212 case "number": | 3266 case "number": |
3213 case "question": | 3267 case "question": |
3214 var child = this.parent.document.createElement('response'); | 3268 var child = this.parent.document.createElement('response'); |
3230 surveyresult.appendChild(checkNode); | 3284 surveyresult.appendChild(checkNode); |
3231 } | 3285 } |
3232 break; | 3286 break; |
3233 } | 3287 } |
3234 }; | 3288 }; |
3289 this.complete = function() { | |
3290 this.state = "complete"; | |
3291 this.XMLDOM.setAttribute("state",this.state); | |
3292 } | |
3235 }; | 3293 }; |
3236 | 3294 |
3237 this.pageNode = function(parent,specification) | 3295 this.pageNode = function(parent,specification) |
3238 { | 3296 { |
3239 // Create one store per test page | 3297 // Create one store per test page |
3240 this.specification = specification; | 3298 this.specification = specification; |
3241 this.parent = parent; | 3299 this.parent = parent; |
3300 this.state = "empty"; | |
3242 this.XMLDOM = this.parent.document.createElement('page'); | 3301 this.XMLDOM = this.parent.document.createElement('page'); |
3243 this.XMLDOM.setAttribute('id',specification.id); | 3302 this.XMLDOM.setAttribute('ref',specification.id); |
3244 this.XMLDOM.setAttribute('presentedId',specification.presentedId); | 3303 this.XMLDOM.setAttribute('presentedId',specification.presentedId); |
3304 this.XMLDOM.setAttribute("state",this.state); | |
3245 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);} | 3305 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);} |
3246 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);} | 3306 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);} |
3247 | 3307 |
3248 // Add any page metrics | 3308 // Add any page metrics |
3249 var page_metric = this.parent.document.createElement('metric'); | 3309 var page_metric = this.parent.document.createElement('metric'); |
3251 | 3311 |
3252 // Add the audioelement | 3312 // Add the audioelement |
3253 for (var element of this.specification.audioElements) | 3313 for (var element of this.specification.audioElements) |
3254 { | 3314 { |
3255 var aeNode = this.parent.document.createElement('audioelement'); | 3315 var aeNode = this.parent.document.createElement('audioelement'); |
3256 aeNode.id = element.id; | 3316 aeNode.setAttribute('ref',element.id); |
3317 if (element.name != undefined){aeNode.setAttribute('name',element.name)}; | |
3257 aeNode.setAttribute('type',element.type); | 3318 aeNode.setAttribute('type',element.type); |
3258 aeNode.setAttribute('url', element.url); | 3319 aeNode.setAttribute('url', element.url); |
3259 aeNode.setAttribute('gain', element.gain); | 3320 aeNode.setAttribute('gain', element.gain); |
3260 if (element.type == 'anchor' || element.type == 'reference') | 3321 if (element.type == 'anchor' || element.type == 'reference') |
3261 { | 3322 { |
3268 aeNode.appendChild(ae_metric); | 3329 aeNode.appendChild(ae_metric); |
3269 this.XMLDOM.appendChild(aeNode); | 3330 this.XMLDOM.appendChild(aeNode); |
3270 } | 3331 } |
3271 | 3332 |
3272 this.parent.root.appendChild(this.XMLDOM); | 3333 this.parent.root.appendChild(this.XMLDOM); |
3334 | |
3335 this.complete = function() { | |
3336 this.state = "complete"; | |
3337 this.XMLDOM.setAttribute("state","complete"); | |
3338 } | |
3273 }; | 3339 }; |
3274 this.update = function() { | 3340 this.update = function() { |
3275 this.SessionKey.update(); | 3341 this.SessionKey.update(); |
3276 } | 3342 } |
3277 this.finish = function() | 3343 this.finish = function() |