Mercurial > hg > webaudioevaluationtool
comparison core.js @ 606:65c7223bd817 Dev_main
Merge
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 10 Mar 2016 17:08:10 +0000 |
parents | 640ffb822da1 |
children | 0256f3748b27 c99d334d8534 |
comparison
equal
deleted
inserted
replaced
597:5a3b74e95d4a | 606:65c7223bd817 |
---|---|
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.'; |
332 popup.showPopup(); | 371 popup.showPopup(); |
333 popup.popupContent.innerHTML = "</span>Please save the file below to give to your test supervisor</span><br>"; | 372 popup.popupContent.innerHTML = "</span>Please save the file below to give to your test supervisor</span><br>"; |
334 popup.popupContent.appendChild(a); | 373 popup.popupContent.appendChild(a); |
335 } else { | 374 } else { |
336 var xmlhttp = new XMLHttpRequest; | 375 var xmlhttp = new XMLHttpRequest; |
337 xmlhttp.open("POST",destURL,true); | 376 xmlhttp.open("POST","\save.php?key="+storage.SessionKey.key,true); |
338 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); | 377 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); |
339 xmlhttp.onerror = function(){ | 378 xmlhttp.onerror = function(){ |
340 console.log('Error saving file to server! Presenting download locally'); | 379 console.log('Error saving file to server! Presenting download locally'); |
341 createProjectSave(null); | 380 createProjectSave("local"); |
342 }; | 381 }; |
343 xmlhttp.onload = function() { | 382 xmlhttp.onload = function() { |
344 console.log(xmlhttp); | 383 console.log(xmlhttp); |
345 if (this.status >= 300) { | 384 if (this.status >= 300) { |
346 console.log("WARNING - Could not update at this time"); | 385 console.log("WARNING - Could not update at this time"); |
386 createProjectSave("local"); | |
347 } else { | 387 } else { |
348 var parser = new DOMParser(); | 388 var parser = new DOMParser(); |
349 var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml"); | 389 var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml"); |
350 var response = xmlDoc.getElementsByTagName('response')[0]; | 390 var response = xmlDoc.getElementsByTagName('response')[0]; |
351 if (response.getAttribute("state") == "OK") { | 391 if (response.getAttribute("state") == "OK") { |
714 this.hidePopup(); | 754 this.hidePopup(); |
715 for (var node of this.popupOptions) | 755 for (var node of this.popupOptions) |
716 { | 756 { |
717 this.store.postResult(node); | 757 this.store.postResult(node); |
718 } | 758 } |
759 this.store.complete(); | |
719 advanceState(); | 760 advanceState(); |
720 } | 761 } |
721 }; | 762 }; |
722 | 763 |
723 this.previousClick = function() { | 764 this.previousClick = function() { |
920 for (var element of interfaceContext.commentQuestions) | 961 for (var element of interfaceContext.commentQuestions) |
921 { | 962 { |
922 element.exportXMLDOM(storePoint); | 963 element.exportXMLDOM(storePoint); |
923 } | 964 } |
924 pageXMLSave(storePoint.XMLDOM, this.currentStateMap); | 965 pageXMLSave(storePoint.XMLDOM, this.currentStateMap); |
966 storePoint.complete(); | |
925 }; | 967 }; |
926 } | 968 } |
927 | 969 |
928 function AudioEngine(specification) { | 970 function AudioEngine(specification) { |
929 | 971 |
1173 this.audioObjects[audioObjectId].url = URL; | 1215 this.audioObjects[audioObjectId].url = URL; |
1174 // Obtain store node | 1216 // Obtain store node |
1175 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement'); | 1217 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement'); |
1176 for (var i=0; i<aeNodes.length; i++) | 1218 for (var i=0; i<aeNodes.length; i++) |
1177 { | 1219 { |
1178 if(aeNodes[i].id == element.id) | 1220 if(aeNodes[i].getAttribute("ref") == element.id) |
1179 { | 1221 { |
1180 this.audioObjects[audioObjectId].storeDOM = aeNodes[i]; | 1222 this.audioObjects[audioObjectId].storeDOM = aeNodes[i]; |
1181 break; | 1223 break; |
1182 } | 1224 } |
1183 } | 1225 } |
2136 this.randomiseOrder = undefined; | 2178 this.randomiseOrder = undefined; |
2137 this.loop = undefined; | 2179 this.loop = undefined; |
2138 this.showElementComments = undefined; | 2180 this.showElementComments = undefined; |
2139 this.outsideReference = null; | 2181 this.outsideReference = null; |
2140 this.loudness = null; | 2182 this.loudness = null; |
2183 this.label = null; | |
2141 this.preTest = null; | 2184 this.preTest = null; |
2142 this.postTest = null; | 2185 this.postTest = null; |
2143 this.interfaces = []; | 2186 this.interfaces = []; |
2144 this.commentBoxPrefix = "Comment on track"; | 2187 this.commentBoxPrefix = "Comment on track"; |
2145 this.audioElements = []; | 2188 this.audioElements = []; |
3000 } | 3043 } |
3001 } | 3044 } |
3002 if (passed == false) | 3045 if (passed == false) |
3003 { | 3046 { |
3004 check_pass = false; | 3047 check_pass = false; |
3005 console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); | 3048 console.log("Continue listening to track-"+object.interfaceDOM.getPresentedId()); |
3006 error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); | 3049 error_obj.push(object.interfaceDOM.getPresentedId()); |
3007 } | 3050 } |
3008 } | 3051 } |
3009 if (check_pass == false) | 3052 if (check_pass == false) |
3010 { | 3053 { |
3011 var str_start = "You have not completely listened to fragments "; | 3054 var str_start = "You have not completely listened to fragments "; |
3100 { | 3143 { |
3101 // Holds results in XML format until ready for collection | 3144 // Holds results in XML format until ready for collection |
3102 this.globalPreTest = null; | 3145 this.globalPreTest = null; |
3103 this.globalPostTest = null; | 3146 this.globalPostTest = null; |
3104 this.testPages = []; | 3147 this.testPages = []; |
3105 this.document = document.implementation.createDocument(null,"waetresult"); | 3148 this.document = null; |
3106 this.root = this.document.childNodes[0]; | 3149 this.root = null; |
3107 this.state = 0; | 3150 this.state = 0; |
3108 | 3151 |
3109 this.initialise = function(sessionKey) | 3152 this.initialise = function(existingStore) |
3110 { | 3153 { |
3111 if (sessionKey == undefined) { | 3154 if (existingStore == undefined) { |
3112 // We need to get the sessionKey | 3155 // We need to get the sessionKey |
3113 this.SessionKey.generateKey(); | 3156 this.SessionKey.generateKey(); |
3157 this.document = document.implementation.createDocument(null,"waetresult"); | |
3158 this.root = this.document.childNodes[0]; | |
3114 var projectDocument = specification.projectXML; | 3159 var projectDocument = specification.projectXML; |
3115 projectDocument.setAttribute('file-name',url); | 3160 projectDocument.setAttribute('file-name',url); |
3116 this.root.appendChild(projectDocument); | 3161 this.root.appendChild(projectDocument); |
3117 this.root.appendChild(returnDateNode()); | 3162 this.root.appendChild(returnDateNode()); |
3118 this.root.appendChild(interfaceContext.returnNavigator()); | 3163 this.root.appendChild(interfaceContext.returnNavigator()); |
3119 } else { | 3164 } else { |
3120 this.SessionKey.key = sessionKey; | 3165 this.document = existingStore; |
3166 this.root = existingStore.children[0]; | |
3167 this.SessionKey.key = this.root.getAttribute("key"); | |
3121 } | 3168 } |
3122 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} | 3169 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} |
3123 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} | 3170 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} |
3124 }; | 3171 }; |
3125 | 3172 |
3126 this.SessionKey = { | 3173 this.SessionKey = { |
3127 key: null, | 3174 key: null, |
3128 request: new XMLHttpRequest(), | 3175 request: new XMLHttpRequest(), |
3184 | 3231 |
3185 this.surveyNode = function(parent,root,specification) | 3232 this.surveyNode = function(parent,root,specification) |
3186 { | 3233 { |
3187 this.specification = specification; | 3234 this.specification = specification; |
3188 this.parent = parent; | 3235 this.parent = parent; |
3236 this.state = "empty"; | |
3189 this.XMLDOM = this.parent.document.createElement('survey'); | 3237 this.XMLDOM = this.parent.document.createElement('survey'); |
3190 this.XMLDOM.setAttribute('location',this.specification.location); | 3238 this.XMLDOM.setAttribute('location',this.specification.location); |
3239 this.XMLDOM.setAttribute("state",this.state); | |
3191 for (var optNode of this.specification.options) | 3240 for (var optNode of this.specification.options) |
3192 { | 3241 { |
3193 if (optNode.type != 'statement') | 3242 if (optNode.type != 'statement') |
3194 { | 3243 { |
3195 var node = this.parent.document.createElement('surveyresult'); | 3244 var node = this.parent.document.createElement('surveyresult'); |
3196 node.id = optNode.id; | 3245 node.setAttribute("ref",optNode.id); |
3197 node.setAttribute('type',optNode.type); | 3246 node.setAttribute('type',optNode.type); |
3198 this.XMLDOM.appendChild(node); | 3247 this.XMLDOM.appendChild(node); |
3199 } | 3248 } |
3200 } | 3249 } |
3201 root.appendChild(this.XMLDOM); | 3250 root.appendChild(this.XMLDOM); |
3203 this.postResult = function(node) | 3252 this.postResult = function(node) |
3204 { | 3253 { |
3205 // From popup: node is the popupOption node containing both spec. and results | 3254 // From popup: node is the popupOption node containing both spec. and results |
3206 // ID is the position | 3255 // ID is the position |
3207 if (node.specification.type == 'statement'){return;} | 3256 if (node.specification.type == 'statement'){return;} |
3208 var surveyresult = this.parent.document.getElementById(node.specification.id); | 3257 var surveyresult = this.XMLDOM.children[0]; |
3258 while(surveyresult != null) { | |
3259 if (surveyresult.getAttribute("ref") == node.specification.id) | |
3260 { | |
3261 break; | |
3262 } | |
3263 surveyresult = surveyresult.nextElementSibling; | |
3264 } | |
3209 switch(node.specification.type) | 3265 switch(node.specification.type) |
3210 { | 3266 { |
3211 case "number": | 3267 case "number": |
3212 case "question": | 3268 case "question": |
3213 var child = this.parent.document.createElement('response'); | 3269 var child = this.parent.document.createElement('response'); |
3229 surveyresult.appendChild(checkNode); | 3285 surveyresult.appendChild(checkNode); |
3230 } | 3286 } |
3231 break; | 3287 break; |
3232 } | 3288 } |
3233 }; | 3289 }; |
3290 this.complete = function() { | |
3291 this.state = "complete"; | |
3292 this.XMLDOM.setAttribute("state",this.state); | |
3293 } | |
3234 }; | 3294 }; |
3235 | 3295 |
3236 this.pageNode = function(parent,specification) | 3296 this.pageNode = function(parent,specification) |
3237 { | 3297 { |
3238 // Create one store per test page | 3298 // Create one store per test page |
3239 this.specification = specification; | 3299 this.specification = specification; |
3240 this.parent = parent; | 3300 this.parent = parent; |
3301 this.state = "empty"; | |
3241 this.XMLDOM = this.parent.document.createElement('page'); | 3302 this.XMLDOM = this.parent.document.createElement('page'); |
3242 this.XMLDOM.setAttribute('id',specification.id); | 3303 this.XMLDOM.setAttribute('ref',specification.id); |
3243 this.XMLDOM.setAttribute('presentedId',specification.presentedId); | 3304 this.XMLDOM.setAttribute('presentedId',specification.presentedId); |
3305 this.XMLDOM.setAttribute("state",this.state); | |
3244 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);} | 3306 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);} |
3245 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);} | 3307 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);} |
3246 | 3308 |
3247 // Add any page metrics | 3309 // Add any page metrics |
3248 var page_metric = this.parent.document.createElement('metric'); | 3310 var page_metric = this.parent.document.createElement('metric'); |
3250 | 3312 |
3251 // Add the audioelement | 3313 // Add the audioelement |
3252 for (var element of this.specification.audioElements) | 3314 for (var element of this.specification.audioElements) |
3253 { | 3315 { |
3254 var aeNode = this.parent.document.createElement('audioelement'); | 3316 var aeNode = this.parent.document.createElement('audioelement'); |
3255 aeNode.id = element.id; | 3317 aeNode.setAttribute('ref',element.id); |
3318 if (element.name != undefined){aeNode.setAttribute('name',element.name)}; | |
3256 aeNode.setAttribute('type',element.type); | 3319 aeNode.setAttribute('type',element.type); |
3257 aeNode.setAttribute('url', element.url); | 3320 aeNode.setAttribute('url', element.url); |
3258 aeNode.setAttribute('gain', element.gain); | 3321 aeNode.setAttribute('gain', element.gain); |
3259 if (element.type == 'anchor' || element.type == 'reference') | 3322 if (element.type == 'anchor' || element.type == 'reference') |
3260 { | 3323 { |
3267 aeNode.appendChild(ae_metric); | 3330 aeNode.appendChild(ae_metric); |
3268 this.XMLDOM.appendChild(aeNode); | 3331 this.XMLDOM.appendChild(aeNode); |
3269 } | 3332 } |
3270 | 3333 |
3271 this.parent.root.appendChild(this.XMLDOM); | 3334 this.parent.root.appendChild(this.XMLDOM); |
3335 | |
3336 this.complete = function() { | |
3337 this.state = "complete"; | |
3338 this.XMLDOM.setAttribute("state","complete"); | |
3339 } | |
3272 }; | 3340 }; |
3273 this.update = function() { | 3341 this.update = function() { |
3274 this.SessionKey.update(); | 3342 this.SessionKey.update(); |
3275 } | 3343 } |
3276 this.finish = function() | 3344 this.finish = function() |