comparison ape.js @ 952:c3a66f0b33cc

Popup now in core.js. Needs stress testing!!
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Tue, 26 May 2015 13:01:39 +0100
parents 55bf2500f278
children 17353d015d33
comparison
equal deleted inserted replaced
951:55bf2500f278 952:c3a66f0b33cc
1 /** 1 /**
2 * ape.js 2 * ape.js
3 * Create the APE interface 3 * Create the APE interface
4 */ 4 */
5 5
6 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
7 // preTest - In preTest state 6 // preTest - In preTest state
8 // testRun-ID - In test running, test Id number at the end 'testRun-2' 7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
9 // testRunPost-ID - Post test of test ID 8 // testRunPost-ID - Post test of test ID
10 // testRunPre-ID - Pre-test of test ID 9 // testRunPre-ID - Pre-test of test ID
11 // postTest - End of test, final submission! 10 // postTest - End of test, final submission!
231 currentState = 'preTest'; 230 currentState = 'preTest';
232 231
233 // Create Pre-Test Box 232 // Create Pre-Test Box
234 if (preTest != undefined && preTest.childElementCount >= 1) 233 if (preTest != undefined && preTest.childElementCount >= 1)
235 { 234 {
236 showPopup(); 235 //popup.showPopup();
237 preTestPopupStart(preTest); 236 //preTestPopupStart(preTest);
237 popup.initState(preTest);
238 } 238 }
239 239
240 // Inject into HTML 240 // Inject into HTML
241 testContent.appendChild(title); // Insert the title 241 testContent.appendChild(title); // Insert the title
242 testContent.appendChild(pagetitle); 242 testContent.appendChild(pagetitle);
353 } 353 }
354 354
355 currentTestHolder = document.createElement('audioHolder'); 355 currentTestHolder = document.createElement('audioHolder');
356 currentTestHolder.id = textXML.id; 356 currentTestHolder.id = textXML.id;
357 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value; 357 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
358 var currentPreTestHolder = document.createElement('preTest');
359 var currentPostTestHolder = document.createElement('postTest');
360 currentTestHolder.appendChild(currentPreTestHolder);
361 currentTestHolder.appendChild(currentPostTestHolder);
362 358
363 var randomise = textXML.attributes['randomiseOrder']; 359 var randomise = textXML.attributes['randomiseOrder'];
364 if (randomise != undefined) {randomise = randomise.value;} 360 if (randomise != undefined) {randomise = randomise.value;}
365 else {randomise = false;} 361 else {randomise = false;}
366 362
478 474
479 var preTest = $(testXMLSetups[id]).find('PreTest')[0]; 475 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
480 if (preTest.childElementCount > 0) 476 if (preTest.childElementCount > 0)
481 { 477 {
482 currentState = 'testRunPre-'+id; 478 currentState = 'testRunPre-'+id;
483 preTestPopupStart(preTest); 479 //preTestPopupStart(preTest);
484 showPopup(); 480 popup.initState(preTest);
481 //popup.showPopup();
485 } else { 482 } else {
486 currentState = 'testRun-'+id; 483 currentState = 'testRun-'+id;
487 } 484 }
488 } 485 }
486 /*
489 487
490 function preTestPopupStart(preTest) 488 function preTestPopupStart(preTest)
491 { 489 {
492 var popupHolder = document.getElementById('popupHolder'); 490 var popupHolder = document.getElementById('popupHolder');
493 popupHolder.innerHTML = null; 491 popupHolder.innerHTML = null;
596 } 594 }
597 } else { 595 } else {
598 // Time to clear 596 // Time to clear
599 preTestOption.innerHTML = null; 597 preTestOption.innerHTML = null;
600 if (currentState != 'postTest') { 598 if (currentState != 'postTest') {
601 hidePopup(); 599 popup.hidePopup();
602 // Progress the state! 600 // Progress the state!
603 advanceState(); 601 advanceState();
604 } else { 602 } else {
605 a = createProjectSave(projectReturn); 603 a = createProjectSave(projectReturn);
606 preTestOption.appendChild(a); 604 preTestOption.appendChild(a);
625 var store = $(currentTestHolder).find('postTest'); 623 var store = $(currentTestHolder).find('postTest');
626 } 624 }
627 store[0].appendChild(response); 625 store[0].appendChild(response);
628 } 626 }
629 } 627 }
630 628 */
631 function dragEnd(ev) { 629 function dragEnd(ev) {
632 // Function call when a div has been dropped 630 // Function call when a div has been dropped
633 var slider = document.getElementById('slider'); 631 var slider = document.getElementById('slider');
634 var w = slider.style.width; 632 var w = slider.style.width;
635 w = Number(w.substr(0,w.length-2)); 633 w = Number(w.substr(0,w.length-2));
642 } else { 640 } else {
643 this.style.left = (w+42) + 'px'; 641 this.style.left = (w+42) + 'px';
644 } 642 }
645 } 643 }
646 audioEngineContext.metric.sliderMoved(); 644 audioEngineContext.metric.sliderMoved();
647 }
648
649 function advanceState()
650 {
651 console.log(currentState);
652 if (currentState == 'preTest')
653 {
654 // End of pre-test, begin the test
655 loadTest(0);
656 } else if (currentState.substr(0,10) == 'testRunPre')
657 {
658 // Start the test
659 var testId = currentState.substr(11,currentState.length-10);
660 currentState = 'testRun-'+testId;
661 //audioEngineContext.timer.startTest();
662 //audioEngineContext.play();
663 } else if (currentState.substr(0,11) == 'testRunPost')
664 {
665 var testId = currentState.substr(12,currentState.length-11);
666 testEnded(testId);
667 } else if (currentState.substr(0,7) == 'testRun')
668 {
669 var testId = currentState.substr(8,currentState.length-7);
670 // Check if we have any post tests to perform
671 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
672 if (postXML == undefined || postXML.childElementCount == 0) {
673 testEnded(testId);
674 }
675 else if (postXML.childElementCount > 0)
676 {
677 currentState = 'testRunPost-'+testId;
678 showPopup();
679 preTestPopupStart(postXML);
680 }
681 else {
682
683
684 // No post tests, check if we have another test to perform instead
685
686 }
687 }
688 console.log(currentState);
689 }
690
691 function testEnded(testId)
692 {
693 pageXMLSave(testId);
694 if (testXMLSetups.length-1 > testId)
695 {
696 // Yes we have another test to perform
697 testId = (Number(testId)+1);
698 currentState = 'testRun-'+testId;
699 loadTest(testId);
700 } else {
701 console.log('Testing Completed!');
702 currentState = 'postTest';
703 // Check for any post tests
704 var xmlSetup = projectXML.find('setup');
705 var postTest = xmlSetup.find('PostTest')[0];
706 showPopup();
707 preTestPopupStart(postTest);
708 }
709 } 645 }
710 646
711 function buttonSubmitClick() // TODO: Only when all songs have been played! 647 function buttonSubmitClick() // TODO: Only when all songs have been played!
712 { 648 {
713 hasBeenPlayed = audioEngineContext.checkAllPlayed(); 649 hasBeenPlayed = audioEngineContext.checkAllPlayed();