comparison core.js @ 2149:90212e9e9295

WIP. Adding intermediate save options. Will require mass editing of save engine as it stands, so still WIP (note: this version will not work on python server).
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 09 Mar 2016 11:12:06 +0000
parents 0eeb17318f7e
children 987ccc04250b
comparison
equal deleted inserted replaced
2148:2ae80808c753 2149:90212e9e9295
211 span.textContent = xmllint[i]; 211 span.textContent = xmllint[i];
212 document.getElementsByTagName('body')[0].appendChild(span); 212 document.getElementsByTagName('body')[0].appendChild(span);
213 } 213 }
214 return; 214 return;
215 } 215 }
216 216 // Build the specification
217 specification.decode(projectXML);
217 // Generate the session-key 218 // Generate the session-key
218 storage.initialise(); 219 storage.initialise();
219 220
220 } else if (responseDocument.children[0].nodeName == "waetresult") { 221 } else if (responseDocument.children[0].nodeName == "waetresult") {
221 // document is a result 222 // document is a result
222 projectXML = responseDocument.getElementsByTagName('waet')[0]; 223 projectXML = responseDocument.getElementsByTagName('waet')[0];
224 // Build the specification
225 specification.decode(projectXML);
223 // Use the session-key 226 // Use the session-key
224 var sessionKey = responseDocument.children[0].getAttribute(key); 227 var sessionKey = responseDocument.children[0].getAttribute(key);
225 storage.initialise(sessionKey); 228 storage.initialise(sessionKey);
226 } 229 }
227
228 // Build the specification
229 specification.decode(projectXML);
230 /// CHECK FOR SAMPLE RATE COMPATIBILITY 230 /// CHECK FOR SAMPLE RATE COMPATIBILITY
231 if (specification.sampleRate != undefined) { 231 if (specification.sampleRate != undefined) {
232 if (Number(specification.sampleRate) != audioContext.sampleRate) { 232 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.'; 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.';
234 alert(errStr); 234 alert(errStr);
742 this.hidePopup(); 742 this.hidePopup();
743 for (var node of this.popupOptions) 743 for (var node of this.popupOptions)
744 { 744 {
745 this.store.postResult(node); 745 this.store.postResult(node);
746 } 746 }
747 this.store.finish();
747 advanceState(); 748 advanceState();
748 } 749 }
749 }; 750 };
750 751
751 this.previousClick = function() { 752 this.previousClick = function() {
820 } 821 }
821 for (var i=0; i<specification.pages.length; i++) 822 for (var i=0; i<specification.pages.length; i++)
822 { 823 {
823 if (specification.testPages <= i && specification.testPages != 0) {break;} 824 if (specification.testPages <= i && specification.testPages != 0) {break;}
824 this.stateMap.push(pageHolder[i]); 825 this.stateMap.push(pageHolder[i]);
826 storage.createTestPageStore(pageHolder[i]);
825 } 827 }
826 828
827 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;} 829 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;}
828 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;} 830 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;}
829 831
870 this.currentStateMap = this.stateMap[this.stateIndex]; 872 this.currentStateMap = this.stateMap[this.stateIndex];
871 if (this.currentStateMap.randomiseOrder) 873 if (this.currentStateMap.randomiseOrder)
872 { 874 {
873 this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements); 875 this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements);
874 } 876 }
875 this.currentStore = storage.createTestPageStore(this.currentStateMap); 877 this.currentStore = storage.testPages[this.stateIndex];
876 if (this.currentStateMap.preTest != null) 878 if (this.currentStateMap.preTest != null)
877 { 879 {
878 this.currentStatePosition = 'pre'; 880 this.currentStatePosition = 'pre';
879 popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest); 881 popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest);
880 } else { 882 } else {
901 } 903 }
902 break; 904 break;
903 case 'post': 905 case 'post':
904 this.stateIndex++; 906 this.stateIndex++;
905 this.currentStateMap = null; 907 this.currentStateMap = null;
908 this.currentStore.finish();
906 this.advanceState(); 909 this.advanceState();
907 break; 910 break;
908 }; 911 };
909 } 912 }
910 }; 913 };
3142 generateKey: function() { 3145 generateKey: function() {
3143 var temp_key = randomString(32); 3146 var temp_key = randomString(32);
3144 this.request.open("GET","keygen.php?key="+temp_key,true); 3147 this.request.open("GET","keygen.php?key="+temp_key,true);
3145 this.request.addEventListener("load",this); 3148 this.request.addEventListener("load",this);
3146 this.request.send(); 3149 this.request.send();
3150 },
3151 postData: function(nodeName,id,xml) {
3152 // nodeName: the node name to find
3153 // id: the id of the node (null if location==root)
3154 // xml: the XML node to append
3155 if (this.key != null) {
3156 var postXML = new XMLHttpRequest;
3157 postXML.open("POST","intermediate.php?key="+this.key+"&node="+nodeName+"&id="+id);
3158 postXML.setRequestHeader('Content-Type','text/xml');
3159 postXML.onerror = function() {
3160 console.log("Error posting: "+this.responseText);
3161 }
3162 var parent = document.createElement("div");
3163 parent.appendChild(xml);
3164 postXML.send([parent.innerHTML]);
3165 }
3147 } 3166 }
3148 } 3167 }
3149 3168
3150 this.createTestPageStore = function(specification) 3169 this.createTestPageStore = function(specification)
3151 { 3170 {
3201 surveyresult.appendChild(checkNode); 3220 surveyresult.appendChild(checkNode);
3202 } 3221 }
3203 break; 3222 break;
3204 } 3223 }
3205 }; 3224 };
3225
3226 this.finish = function() {
3227 if (this.parent.document != undefined) {
3228 this.parent.SessionKey.postData("waetresult",null,this.XMLDOM);
3229 }
3230 };
3206 }; 3231 };
3207 3232
3208 this.pageNode = function(parent,specification) 3233 this.pageNode = function(parent,specification)
3209 { 3234 {
3210 // Create one store per test page 3235 // Create one store per test page
3239 aeNode.appendChild(ae_metric); 3264 aeNode.appendChild(ae_metric);
3240 this.XMLDOM.appendChild(aeNode); 3265 this.XMLDOM.appendChild(aeNode);
3241 } 3266 }
3242 3267
3243 this.parent.root.appendChild(this.XMLDOM); 3268 this.parent.root.appendChild(this.XMLDOM);
3269
3270 this.finish = function() {
3271 this.parent.SessionKey.postData("waetresult",null,this.XMLDOM);
3272 }
3244 }; 3273 };
3245 this.finish = function() 3274 this.finish = function()
3246 { 3275 {
3247 if (this.state == 0) 3276 if (this.state == 0)
3248 { 3277 {