annotate ape.js @ 673:d4e55184f776

Added preliminary metrics functions
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Sun, 12 Apr 2015 18:20:39 +0100
parents 9ea50bbcaf9a
children 436db2f29f73
rev   line source
n@656 1 /**
n@656 2 * ape.js
n@656 3 * Create the APE interface
n@656 4 */
n@656 5
n@656 6 /*
n@656 7 *
n@656 8 * WARNING!!!
n@656 9 *
n@656 10 * YOU ARE VIEWING THE DEV VERSION. THERE IS NO GUARANTEE THIS WILL BE FULLY FUNCTIONAL
n@656 11 *
n@656 12 * WARNING!!!
n@656 13 *
n@656 14 */
n@656 15
n@662 16 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
n@662 17 // preTest - In preTest state
n@662 18 // testRun-ID - In test running, test Id number at the end 'testRun-2'
n@662 19 // testRunPost-ID - Post test of test ID
n@662 20 // testRunPre-ID - Pre-test of test ID
n@662 21 // postTest - End of test, final submission!
n@662 22
n@656 23
n@656 24 // Once this is loaded and parsed, begin execution
n@656 25 loadInterface(projectXML);
n@656 26
n@656 27 function loadInterface(xmlDoc) {
n@656 28
n@656 29 // Get the dimensions of the screen available to the page
n@656 30 var width = window.innerWidth;
n@656 31 var height = window.innerHeight;
n@656 32
n@656 33 // The injection point into the HTML page
n@656 34 var insertPoint = document.getElementById("topLevelBody");
n@656 35 var testContent = document.createElement('div');
n@656 36 testContent.id = 'testContent';
n@656 37
n@656 38
n@656 39 // Decode parts of the xmlDoc that are needed
n@656 40 // xmlDoc MUST already be parsed by jQuery!
n@656 41 var xmlSetup = xmlDoc.find('setup');
n@656 42 // Should put in an error function here incase of malprocessed or malformed XML
n@656 43
n@658 44 // Extract the different test XML DOM trees
n@668 45 var audioHolders = xmlDoc.find('audioHolder');
n@668 46 audioHolders.each(function(index,element) {
n@668 47 var repeatN = element.attributes['repeatCount'].value;
n@668 48 for (var r=0; r<=repeatN; r++) {
n@668 49 testXMLSetups[testXMLSetups.length] = element;
n@668 50 }
n@668 51 });
n@668 52
n@668 53 // New check if we need to randomise the test order
n@669 54 var randomise = xmlSetup[0].attributes['randomiseOrder'];
n@669 55 if (randomise != undefined) {
n@668 56 randomise = Boolean(randomise.value);
n@668 57 } else {
n@668 58 randomise = false;
n@668 59 }
n@668 60 if (randomise)
n@668 61 {
n@668 62 // TODO: Implement Randomisation!!
n@668 63 }
n@668 64
n@658 65
n@656 66 // Create the top div for the Title element
n@656 67 var titleAttr = xmlSetup[0].attributes['title'];
n@656 68 var title = document.createElement('div');
n@656 69 title.className = "title";
n@656 70 title.align = "center";
n@656 71 var titleSpan = document.createElement('span');
n@656 72
n@656 73 // Set title to that defined in XML, else set to default
n@656 74 if (titleAttr != undefined) {
n@656 75 titleSpan.innerHTML = titleAttr.value;
n@656 76 } else {
n@656 77 titleSpan.innerHTML = 'APE Tool';
n@656 78 }
n@656 79 // Insert the titleSpan element into the title div element.
n@656 80 title.appendChild(titleSpan);
n@656 81
n@671 82 var pagetitle = document.createElement('div');
n@671 83 pagetitle.className = "pageTitle";
n@671 84 pagetitle.align = "center";
n@671 85 var titleSpan = document.createElement('span');
n@671 86 titleSpan.id = "pageTitle";
n@671 87 pagetitle.appendChild(titleSpan);
n@671 88
n@656 89 // Store the return URL path in global projectReturn
n@656 90 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
n@656 91
n@656 92 // Create Interface buttons!
n@656 93 var interfaceButtons = document.createElement('div');
n@656 94 interfaceButtons.id = 'interface-buttons';
n@656 95
n@656 96 // MANUAL DOWNLOAD POINT
n@656 97 // If project return is null, this MUST be specified as the location to create the download link
n@656 98 var downloadPoint = document.createElement('div');
n@656 99 downloadPoint.id = 'download-point';
n@656 100
n@656 101 // Create playback start/stop points
n@656 102 var playback = document.createElement("button");
n@656 103 playback.innerHTML = 'Start';
n@673 104 playback.id = 'playback-button';
n@656 105 // onclick function. Check if it is playing or not, call the correct function in the
n@656 106 // audioEngine, change the button text to reflect the next state.
n@656 107 playback.onclick = function() {
n@656 108 if (audioEngineContext.status == 0) {
n@656 109 audioEngineContext.play();
n@656 110 this.innerHTML = 'Stop';
n@656 111 } else {
n@656 112 audioEngineContext.stop();
n@656 113 this.innerHTML = 'Start';
n@656 114 }
n@656 115 };
n@656 116 // Create Submit (save) button
n@656 117 var submit = document.createElement("button");
n@656 118 submit.innerHTML = 'Submit';
n@667 119 submit.onclick = buttonSubmitClick;
n@673 120 submit.id = 'submit-button';
n@656 121 // Append the interface buttons into the interfaceButtons object.
n@656 122 interfaceButtons.appendChild(playback);
n@656 123 interfaceButtons.appendChild(submit);
n@656 124 interfaceButtons.appendChild(downloadPoint);
n@656 125
n@656 126 // Now create the slider and HTML5 canvas boxes
n@656 127
n@656 128 // Create the div box to center align
n@656 129 var sliderBox = document.createElement('div');
n@656 130 sliderBox.className = 'sliderCanvasDiv';
n@656 131 sliderBox.id = 'sliderCanvasHolder';
n@656 132 sliderBox.align = 'center';
n@656 133
n@656 134 // Create the slider box to hold the slider elements
n@656 135 var canvas = document.createElement('div');
n@656 136 canvas.id = 'slider';
n@656 137 // Must have a known EXACT width, as this is used later to determine the ratings
n@656 138 canvas.style.width = width - 100 +"px";
n@656 139 canvas.align = "left";
n@656 140 sliderBox.appendChild(canvas);
n@656 141
n@671 142 // Create the div to hold any scale objects
n@671 143 var scale = document.createElement('div');
n@671 144 scale.className = 'sliderScale';
n@671 145 scale.id = 'sliderScaleHolder';
n@671 146 scale.align = 'left';
n@671 147 sliderBox.appendChild(scale);
n@671 148
n@656 149 // Global parent for the comment boxes on the page
n@656 150 var feedbackHolder = document.createElement('div');
n@658 151 feedbackHolder.id = 'feedbackHolder';
n@656 152
n@662 153 testContent.style.zIndex = 1;
n@662 154 insertPoint.innerHTML = null; // Clear the current schema
n@662 155
n@656 156 // Create pre and post test questions
n@662 157 var blank = document.createElement('div');
n@662 158 blank.className = 'testHalt';
n@656 159
n@662 160 var popupHolder = document.createElement('div');
n@662 161 popupHolder.id = 'popupHolder';
n@662 162 popupHolder.className = 'popupHolder';
n@662 163 popupHolder.style.position = 'absolute';
n@662 164 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
n@662 165 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
n@662 166 insertPoint.appendChild(popupHolder);
n@662 167 insertPoint.appendChild(blank);
n@662 168 hidePopup();
n@656 169
n@660 170 var preTest = xmlSetup.find('PreTest');
n@660 171 var postTest = xmlSetup.find('PostTest');
n@656 172 preTest = preTest[0];
n@656 173 postTest = postTest[0];
n@662 174
n@662 175 currentState = 'preTest';
n@656 176
n@656 177 // Create Pre-Test Box
n@656 178 if (preTest != undefined && preTest.children.length >= 1)
n@656 179 {
n@662 180 showPopup();
n@663 181 preTestPopupStart(preTest);
n@656 182 }
n@662 183
n@662 184 // Inject into HTML
n@662 185 testContent.appendChild(title); // Insert the title
n@671 186 testContent.appendChild(pagetitle);
n@662 187 testContent.appendChild(interfaceButtons);
n@662 188 testContent.appendChild(sliderBox);
n@662 189 testContent.appendChild(feedbackHolder);
n@662 190 insertPoint.appendChild(testContent);
n@656 191
n@660 192 // Load the full interface
n@663 193
n@656 194 }
n@656 195
n@663 196 function loadTest(id)
n@658 197 {
n@658 198 // Used to load a specific test page
n@663 199 var textXML = testXMLSetups[id];
n@658 200
n@658 201 var feedbackHolder = document.getElementById('feedbackHolder');
n@658 202 var canvas = document.getElementById('slider');
n@658 203 feedbackHolder.innerHTML = null;
n@658 204 canvas.innerHTML = null;
n@671 205
n@671 206 // Setup question title
n@671 207 var interfaceObj = $(textXML).find('interface');
n@671 208 var titleNode = interfaceObj.find('title');
n@671 209 if (titleNode[0] != undefined)
n@671 210 {
n@671 211 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
n@671 212 }
n@671 213 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@671 214 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
n@671 215 // TODO: AUTOMATE ABOVE!!
n@671 216 var scale = document.getElementById('sliderScaleHolder');
n@671 217 scale.innerHTML = null;
n@671 218 interfaceObj.find('scale').each(function(index,scaleObj){
n@671 219 var position = Number(scaleObj.attributes['position'].value)*0.01;
n@671 220 var pixelPosition = (position*positionScale)+offset;
n@671 221 var scaleDOM = document.createElement('span');
n@671 222 scaleDOM.textContent = scaleObj.textContent;
n@671 223 scale.appendChild(scaleDOM);
n@671 224 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@671 225 });
n@658 226
n@658 227 // Extract the hostURL attribute. If not set, create an empty string.
n@658 228 var hostURL = textXML.attributes['hostURL'];
n@658 229 if (hostURL == undefined) {
n@658 230 hostURL = "";
n@658 231 } else {
n@658 232 hostURL = hostURL.value;
n@658 233 }
n@658 234 // Extract the sampleRate. If set, convert the string to a Number.
n@658 235 var hostFs = textXML.attributes['sampleRate'];
n@658 236 if (hostFs != undefined) {
n@658 237 hostFs = Number(hostFs.value);
n@658 238 }
n@658 239
n@658 240 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@658 241 if (hostFs != undefined) {
n@658 242 if (Number(hostFs) != audioContext.sampleRate) {
n@658 243 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
n@658 244 alert(errStr);
n@658 245 return;
n@658 246 }
n@658 247 }
n@669 248
n@670 249 currentTestHolder = document.createElement('audioHolder');
n@670 250 currentTestHolder.id = textXML.id;
n@670 251 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
n@670 252 var currentPreTestHolder = document.createElement('preTest');
n@670 253 var currentPostTestHolder = document.createElement('postTest');
n@670 254 currentTestHolder.appendChild(currentPreTestHolder);
n@670 255 currentTestHolder.appendChild(currentPostTestHolder);
n@670 256
n@669 257 var randomise = textXML.attributes['randomiseOrder'];
n@669 258 if (randomise != undefined) {randomise = randomise.value;}
n@669 259 else {randomise = false;}
n@669 260
n@658 261 var audioElements = $(textXML).find('audioElements');
n@658 262 audioElements.each(function(index,element){
n@669 263 // Find any blind-repeats
n@669 264 // Not implemented yet, but just incase
n@669 265 currentTrackOrder[index] = element;
n@669 266 });
n@669 267 if (randomise) {
n@669 268 // TODO: Randomise order
n@669 269 }
n@669 270
n@669 271 // Find all the audioElements from the audioHolder
n@669 272 $(currentTrackOrder).each(function(index,element){
n@658 273 // Find URL of track
n@658 274 // In this jQuery loop, variable 'this' holds the current audioElement.
n@658 275
n@658 276 // Now load each audio sample. First create the new track by passing the full URL
n@658 277 var trackURL = hostURL + this.attributes['url'].value;
n@658 278 audioEngineContext.newTrack(trackURL);
n@658 279 // Create document objects to hold the comment boxes
n@658 280 var trackComment = document.createElement('div');
n@661 281 trackComment.className = 'comment-div';
n@658 282 // Create a string next to each comment asking for a comment
n@658 283 var trackString = document.createElement('span');
n@658 284 trackString.innerHTML = 'Comment on track '+index;
n@658 285 // Create the HTML5 comment box 'textarea'
n@658 286 var trackCommentBox = document.createElement('textarea');
n@658 287 trackCommentBox.rows = '4';
n@658 288 trackCommentBox.cols = '100';
n@658 289 trackCommentBox.name = 'trackComment'+index;
n@658 290 trackCommentBox.className = 'trackComment';
n@658 291 var br = document.createElement('br');
n@658 292 // Add to the holder.
n@658 293 trackComment.appendChild(trackString);
n@658 294 trackComment.appendChild(br);
n@658 295 trackComment.appendChild(trackCommentBox);
n@658 296 feedbackHolder.appendChild(trackComment);
n@658 297
n@658 298 // Create a slider per track
n@658 299
n@658 300 var trackSliderObj = document.createElement('div');
n@658 301 trackSliderObj.className = 'track-slider';
n@658 302 trackSliderObj.id = 'track-slider-'+index;
n@658 303 // Distribute it randomnly
n@658 304 var w = window.innerWidth - 100;
n@658 305 w = Math.random()*w;
n@658 306 trackSliderObj.style.left = Math.floor(w)+50+'px';
n@658 307 trackSliderObj.innerHTML = '<span>'+index+'</span>';
n@658 308 trackSliderObj.draggable = true;
n@658 309 trackSliderObj.ondragend = dragEnd;
n@673 310 trackSliderObj.ondragstart = function()
n@673 311 {
n@673 312 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
n@673 313 audioEngineContext.metric.sliderMoveStart(id);
n@673 314 };
n@658 315
n@658 316 // Onclick, switch playback to that track
n@658 317 trackSliderObj.onclick = function() {
n@658 318 // Get the track ID from the object ID
n@658 319 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
n@673 320 audioEngineContext.metric.sliderPlayed(id);
n@658 321 audioEngineContext.selectedTrack(id);
n@658 322 };
n@658 323
n@658 324 canvas.appendChild(trackSliderObj);
n@658 325 });
n@663 326
n@663 327 // Now process any pre-test commands
n@663 328
n@668 329 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
n@663 330 if (preTest.children.length > 0)
n@663 331 {
n@663 332 currentState = 'testRunPre-'+id;
n@663 333 preTestPopupStart(preTest);
n@663 334 showPopup();
n@663 335 } else {
n@663 336 currentState = 'testRun-'+id;
n@663 337 }
n@663 338 }
n@663 339
n@663 340 function preTestPopupStart(preTest)
n@663 341 {
n@663 342 var popupHolder = document.getElementById('popupHolder');
n@663 343 popupHolder.innerHTML = null;
n@663 344 // Parse the first box
n@663 345 var preTestOption = document.createElement('div');
n@663 346 preTestOption.id = 'preTest';
n@663 347 preTestOption.style.marginTop = '25px';
n@663 348 preTestOption.align = "center";
n@663 349 var child = preTest.children[0];
n@663 350 if (child.nodeName == 'statement')
n@663 351 {
n@663 352 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@663 353 } else if (child.nodeName == 'question')
n@663 354 {
n@663 355 var questionId = child.attributes['id'].value;
n@663 356 var textHold = document.createElement('span');
n@663 357 textHold.innerHTML = child.innerHTML;
n@663 358 textHold.id = questionId + 'response';
n@663 359 var textEnter = document.createElement('textarea');
n@663 360 preTestOption.appendChild(textHold);
n@663 361 preTestOption.appendChild(textEnter);
n@663 362 }
n@663 363 var nextButton = document.createElement('button');
n@663 364 nextButton.className = 'popupButton';
n@663 365 nextButton.value = '0';
n@663 366 nextButton.innerHTML = 'Next';
n@663 367 nextButton.onclick = popupButtonClick;
n@663 368
n@663 369 popupHolder.appendChild(preTestOption);
n@663 370 popupHolder.appendChild(nextButton);
n@658 371 }
n@658 372
n@662 373 function popupButtonClick()
n@662 374 {
n@662 375 // Global call from the 'Next' button click
n@662 376 if (currentState == 'preTest')
n@662 377 {
n@662 378 // At the start of the preTest routine!
n@663 379 var xmlTree = projectXML.find('setup');
n@663 380 var preTest = xmlTree.find('PreTest')[0];
n@663 381 this.value = preTestButtonClick(preTest,this.value);
n@663 382 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 383 {
n@663 384 //Specific test pre-test
n@663 385 var testId = currentState.substr(11,currentState.length-10);
n@668 386 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
n@663 387 this.value = preTestButtonClick(preTest,this.value);
n@666 388 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 389 {
n@666 390 // Specific test post-test
n@666 391 var testId = currentState.substr(12,currentState.length-11);
n@668 392 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
n@666 393 this.value = preTestButtonClick(preTest,this.value);
n@665 394 } else if (currentState == 'postTest')
n@665 395 {
n@665 396 // At the end of the test, running global post test
n@665 397 var xmlTree = projectXML.find('setup');
n@665 398 var PostTest = xmlTree.find('PostTest')[0];
n@665 399 this.value = preTestButtonClick(PostTest,this.value);
n@662 400 }
n@662 401 }
n@662 402
n@663 403 function preTestButtonClick(preTest,index)
n@658 404 {
n@658 405 // Called on click of pre-test button
n@660 406 // Need to find and parse preTest again!
n@660 407 var preTestOption = document.getElementById('preTest');
n@660 408 // Check if current state is a question!
n@662 409 if (preTest.children[index].nodeName == 'question') {
n@662 410 var questionId = preTest.children[index].attributes['id'].value;
n@660 411 var questionHold = document.createElement('comment');
n@660 412 var questionResponse = document.getElementById(questionId + 'response');
n@660 413 questionHold.id = questionId;
n@660 414 questionHold.innerHTML = questionResponse.value;
n@670 415 postPopupResponse(questionHold);
n@660 416 }
n@662 417 index++;
n@662 418 if (index < preTest.children.length)
n@660 419 {
n@660 420 // More to process
n@662 421 var child = preTest.children[index];
n@660 422 if (child.nodeName == 'statement')
n@660 423 {
n@660 424 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@660 425 } else if (child.nodeName == 'question')
n@660 426 {
n@660 427 var textHold = document.createElement('span');
n@660 428 textHold.innerHTML = child.innerHTML;
n@660 429 var textEnter = document.createElement('textarea');
n@660 430 textEnter.id = child.attributes['id'].value + 'response';
n@660 431 var br = document.createElement('br');
n@660 432 preTestOption.innerHTML = null;
n@660 433 preTestOption.appendChild(textHold);
n@660 434 preTestOption.appendChild(br);
n@660 435 preTestOption.appendChild(textEnter);
n@660 436 }
n@660 437 } else {
n@660 438 // Time to clear
n@661 439 preTestOption.innerHTML = null;
n@667 440 if (currentState != 'postTest') {
n@667 441 hidePopup();
n@667 442 // Progress the state!
n@667 443 advanceState();
n@667 444 } else {
n@667 445 a = createProjectSave(projectReturn);
n@667 446 preTestOption.appendChild(a);
n@667 447 }
n@660 448 }
n@662 449 return index;
n@660 450 }
n@660 451
n@670 452 function postPopupResponse(response)
n@670 453 {
n@670 454 if (currentState == 'preTest') {
n@670 455 preTestQuestions.appendChild(response);
n@670 456 } else if (currentState == 'postTest') {
n@670 457 postTestQuestions.appendChild(response);
n@670 458 } else {
n@670 459 // Inside a specific test
n@670 460 if (currentState.substr(0,10) == 'testRunPre') {
n@670 461 // Pre Test
n@670 462 var store = $(currentTestHolder).find('preTest');
n@670 463 } else {
n@670 464 // Post Test
n@670 465 var store = $(currentTestHolder).find('postTest');
n@670 466 }
n@670 467 store[0].appendChild(response);
n@670 468 }
n@670 469 }
n@670 470
n@660 471 function showPopup()
n@660 472 {
n@661 473 var popupHolder = document.getElementById('popupHolder');
n@662 474 popupHolder.style.zIndex = 3;
n@661 475 popupHolder.style.visibility = 'visible';
n@661 476 var blank = document.getElementsByClassName('testHalt')[0];
n@661 477 blank.style.zIndex = 2;
n@661 478 blank.style.visibility = 'visible';
n@660 479 }
n@660 480
n@660 481 function hidePopup()
n@660 482 {
n@661 483 var popupHolder = document.getElementById('popupHolder');
n@661 484 popupHolder.style.zIndex = -1;
n@661 485 popupHolder.style.visibility = 'hidden';
n@661 486 var blank = document.getElementsByClassName('testHalt')[0];
n@661 487 blank.style.zIndex = -2;
n@661 488 blank.style.visibility = 'hidden';
n@658 489 }
n@658 490
n@656 491 function dragEnd(ev) {
n@656 492 // Function call when a div has been dropped
n@657 493 var slider = document.getElementById('slider');
n@656 494 if (ev.x >= 50 && ev.x < window.innerWidth-50) {
n@656 495 this.style.left = (ev.x)+'px';
n@656 496 } else {
n@656 497 if (ev.x<50) {
n@656 498 this.style.left = '50px';
n@656 499 } else {
n@656 500 this.style.left = window.innerWidth-50 + 'px';
n@656 501 }
n@656 502 }
n@673 503 audioEngineContext.metric.sliderMoved();
n@656 504 }
n@656 505
n@663 506 function advanceState()
n@663 507 {
n@663 508 console.log(currentState);
n@663 509 if (currentState == 'preTest')
n@663 510 {
n@663 511 // End of pre-test, begin the test
n@663 512 loadTest(0);
n@663 513 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 514 {
n@663 515 // Start the test
n@663 516 var testId = currentState.substr(11,currentState.length-10);
n@663 517 currentState = 'testRun-'+testId;
n@666 518 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 519 {
n@668 520 var testId = currentState.substr(12,currentState.length-11);
n@666 521 testEnded(testId);
n@664 522 } else if (currentState.substr(0,7) == 'testRun')
n@664 523 {
n@664 524 var testId = currentState.substr(8,currentState.length-7);
n@664 525 // Check if we have any post tests to perform
n@668 526 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
n@664 527 if (postXML.children.length > 0)
n@664 528 {
n@666 529 currentState = 'testRunPost-'+testId;
n@666 530 showPopup();
n@666 531 preTestPopupStart(postXML);
n@664 532 }
n@666 533 else {
n@664 534
n@664 535
n@666 536 // No post tests, check if we have another test to perform instead
n@666 537 testEnded(testId);
n@664 538 }
n@663 539 }
n@663 540 console.log(currentState);
n@663 541 }
n@663 542
n@666 543 function testEnded(testId)
n@666 544 {
n@669 545 pageXMLSave(testId);
n@666 546 if (testXMLSetups.length-1 > testId)
n@666 547 {
n@666 548 // Yes we have another test to perform
n@668 549 testId = (Number(testId)+1);
n@668 550 currentState = 'testRun-'+testId;
n@668 551 loadTest(testId);
n@666 552 } else {
n@666 553 console.log('Testing Completed!');
n@666 554 currentState = 'postTest';
n@666 555 // Check for any post tests
n@666 556 var xmlSetup = projectXML.find('setup');
n@666 557 var postTest = xmlSetup.find('PostTest')[0];
n@666 558 showPopup();
n@666 559 preTestPopupStart(postTest);
n@666 560 }
n@666 561 }
n@666 562
n@664 563 function buttonSubmitClick()
n@664 564 {
n@673 565 if (audioEngineContext.status == 1) {
n@673 566 var playback = document.getElementById('playback-button');
n@673 567 playback.click();
n@664 568 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
n@673 569 }
n@664 570 if (currentState.substr(0,7) == 'testRun')
n@664 571 {
n@673 572 audioEngineContext.timer.stopTest();
n@664 573 advanceState();
n@664 574 }
n@664 575 }
n@664 576
n@668 577 function pageXMLSave(testId)
n@668 578 {
n@668 579 // Saves a specific test page
n@670 580 var xmlDoc = currentTestHolder;
n@669 581 var trackSliderObjects = document.getElementsByClassName('track-slider');
n@669 582 var commentObjects = document.getElementsByClassName('comment-div');
n@669 583 var rateMin = 50;
n@669 584 var rateMax = window.innerWidth-50;
n@669 585 for (var i=0; i<trackSliderObjects.length; i++)
n@669 586 {
n@669 587 var audioElement = document.createElement('audioElement');
n@669 588 audioElement.id = currentTrackOrder[i].attributes['id'].value;
n@669 589 audioElement.url = currentTrackOrder[i].attributes['url'].value;
n@669 590 var value = document.createElement("value");
n@669 591 var rate = Number(trackSliderObjects[i].style.left.substr(0,trackSliderObjects[i].style.left.length-2));
n@669 592 rate = (rate-rateMin)/rateMax;
n@669 593 value.innerHTML = Math.floor(rate*100);
n@669 594 var comment = document.createElement("comment");
n@669 595 var question = document.createElement("question");
n@669 596 var response = document.createElement("response");
n@669 597 question.textContent = commentObjects[i].children[0].textContent;
n@669 598 response.textContent = commentObjects[i].children[2].value;
n@669 599 comment.appendChild(question);
n@669 600 comment.appendChild(response);
n@669 601 audioElement.appendChild(value);
n@669 602 audioElement.appendChild(comment);
n@669 603 xmlDoc.appendChild(audioElement);
n@669 604 }
n@669 605 testResultsHolders[testId] = xmlDoc;
n@668 606 }
n@668 607
n@656 608 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
n@656 609 function interfaceXMLSave(){
n@656 610 // Create the XML string to be exported with results
n@656 611 var xmlDoc = document.createElement("BrowserEvaluationResult");
n@669 612 for (var i=0; i<testResultsHolders.length; i++)
n@656 613 {
n@669 614 xmlDoc.appendChild(testResultsHolders[i]);
n@656 615 }
n@656 616 // Append Pre/Post Questions
n@656 617 xmlDoc.appendChild(preTestQuestions);
n@656 618 xmlDoc.appendChild(postTestQuestions);
n@656 619
n@656 620 return xmlDoc;
n@656 621 }
n@656 622