annotate interfaces/ABX.js @ 2436:25c1436706af

Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool
author www-data <www-data@sucuk.dcs.qmul.ac.uk>
date Thu, 02 Jun 2016 14:20:55 +0100
parents 78f2dbe417da
children 72cdcd6d143e
rev   line source
nickjillings@2161 1 /**
nickjillings@2161 2 * WAET Blank Template
nickjillings@2161 3 * Use this to start building your custom interface
nickjillings@2161 4 */
nickjillings@2161 5
nickjillings@2161 6 // Once this is loaded and parsed, begin execution
nickjillings@2161 7 loadInterface();
nickjillings@2161 8
nickjillings@2161 9 function loadInterface() {
nickjillings@2161 10 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects,
nickjillings@2161 11 // holding div's, or setting up any nodes which are present for the entire test sequence
nickjillings@2161 12
nicholas@2381 13 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
nickjillings@2163 14
nicholas@2359 15 Interface.prototype.checkScaleRange = function(min, max) {
nicholas@2359 16 var page = testState.getCurrentTestPage();
nicholas@2359 17 var audioObjects = audioEngineContext.audioObjects;
nicholas@2359 18 var state = true;
nicholas@2359 19 var str = "Please keep listening. ";
nicholas@2359 20 var minRanking = Infinity;
nicholas@2359 21 var maxRanking = -Infinity;
nicholas@2359 22 for (var ao of audioObjects) {
nicholas@2359 23 var rank = ao.interfaceDOM.getValue();
nicholas@2359 24 if (rank < minRanking) {minRanking = rank;}
nicholas@2359 25 if (rank > maxRanking) {maxRanking = rank;}
nicholas@2359 26 }
nicholas@2359 27 if (maxRanking*100 < max) {
nicholas@2359 28 str += "At least one fragment must be selected."
nicholas@2359 29 state = false;
nicholas@2359 30 }
nicholas@2359 31 if (!state) {
nicholas@2359 32 console.log(str);
nicholas@2359 33 this.storeErrorNode(str);
nicholas@2362 34 interfaceContext.lightbox.post("Message",str);
nicholas@2359 35 }
nicholas@2359 36 return state;
nicholas@2359 37 }
nicholas@2359 38
nickjillings@2161 39 // Custom comparator Object
nickjillings@2161 40 Interface.prototype.comparator = null;
nickjillings@2161 41
nickjillings@2161 42 // The injection point into the HTML page
nickjillings@2161 43 interfaceContext.insertPoint = document.getElementById("topLevelBody");
nickjillings@2161 44 var testContent = document.createElement('div');
nickjillings@2161 45 testContent.id = 'testContent';
nickjillings@2161 46
nickjillings@2161 47 // Create the top div for the Title element
nickjillings@2161 48 var titleAttr = specification.title;
nickjillings@2161 49 var title = document.createElement('div');
nickjillings@2161 50 title.className = "title";
nickjillings@2161 51 title.align = "center";
nickjillings@2161 52 var titleSpan = document.createElement('span');
nickjillings@2161 53
nickjillings@2161 54 // Set title to that defined in XML, else set to default
nickjillings@2161 55 if (titleAttr != undefined) {
nickjillings@2161 56 titleSpan.textContent = titleAttr;
nickjillings@2161 57 } else {
nickjillings@2161 58 titleSpan.textContent = 'Listening test';
nickjillings@2161 59 }
nickjillings@2161 60 // Insert the titleSpan element into the title div element.
nickjillings@2161 61 title.appendChild(titleSpan);
nickjillings@2161 62
nickjillings@2161 63 var pagetitle = document.createElement('div');
nickjillings@2161 64 pagetitle.className = "pageTitle";
nickjillings@2161 65 pagetitle.align = "center";
nickjillings@2161 66 var titleSpan = document.createElement('span');
nickjillings@2161 67 titleSpan.id = "pageTitle";
nickjillings@2161 68 pagetitle.appendChild(titleSpan);
nickjillings@2161 69
nickjillings@2161 70 // Create Interface buttons!
nickjillings@2161 71 var interfaceButtons = document.createElement('div');
nickjillings@2161 72 interfaceButtons.id = 'interface-buttons';
nickjillings@2161 73 interfaceButtons.style.height = '25px';
nickjillings@2161 74
nickjillings@2161 75 // Create playback start/stop points
nickjillings@2161 76 var playback = document.createElement("button");
nickjillings@2161 77 playback.innerHTML = 'Stop';
nickjillings@2161 78 playback.id = 'playback-button';
nickjillings@2161 79 playback.style.float = 'left';
nickjillings@2161 80 // onclick function. Check if it is playing or not, call the correct function in the
nickjillings@2161 81 // audioEngine, change the button text to reflect the next state.
nickjillings@2161 82 playback.onclick = function() {
nickjillings@2161 83 if (audioEngineContext.status == 1) {
nickjillings@2161 84 audioEngineContext.stop();
nickjillings@2161 85 this.innerHTML = 'Stop';
nickjillings@2161 86 var time = audioEngineContext.timer.getTestTime();
nickjillings@2161 87 console.log('Stopped at ' + time); // DEBUG/SAFETY
nickjillings@2161 88 }
nickjillings@2161 89 };
nickjillings@2161 90 // Append the interface buttons into the interfaceButtons object.
nickjillings@2161 91 interfaceButtons.appendChild(playback);
nickjillings@2161 92
nickjillings@2161 93 // Global parent for the comment boxes on the page
nickjillings@2161 94 var feedbackHolder = document.createElement('div');
nickjillings@2161 95 feedbackHolder.id = 'feedbackHolder';
nickjillings@2161 96
nickjillings@2161 97 // Construct the AB Boxes
nickjillings@2161 98 var boxes = document.createElement('div');
nickjillings@2161 99 boxes.align = "center";
nickjillings@2161 100 boxes.id = "box-holders";
nickjillings@2161 101 boxes.style.float = "left";
nickjillings@2161 102
nickjillings@2161 103 var submit = document.createElement('button');
nickjillings@2161 104 submit.id = "submit";
nickjillings@2161 105 submit.onclick = buttonSubmitClick;
nickjillings@2161 106 submit.className = "big-button";
nickjillings@2161 107 submit.textContent = "submit";
nickjillings@2161 108 submit.style.position = "relative";
nickjillings@2161 109 submit.style.left = (window.innerWidth-250)/2 + 'px';
nickjillings@2161 110
nickjillings@2161 111 feedbackHolder.appendChild(boxes);
nickjillings@2161 112
nickjillings@2161 113 // Inject into HTML
nickjillings@2161 114 testContent.appendChild(title); // Insert the title
nickjillings@2161 115 testContent.appendChild(pagetitle);
nickjillings@2161 116 testContent.appendChild(interfaceButtons);
nickjillings@2161 117 testContent.appendChild(feedbackHolder);
nickjillings@2161 118 testContent.appendChild(submit);
nickjillings@2161 119 interfaceContext.insertPoint.appendChild(testContent);
nickjillings@2161 120
nickjillings@2161 121 // Load the full interface
nickjillings@2161 122 testState.initialise();
nickjillings@2161 123 testState.advanceState();
nickjillings@2161 124 };
nickjillings@2161 125
nickjillings@2161 126 function loadTest(page)
nickjillings@2161 127 {
nickjillings@2161 128 // Called each time a new test page is to be build. The page specification node is the only item passed in
nicholas@2381 129 document.getElementById('box-holders').innerHTML = "";
nickjillings@2163 130
nickjillings@2163 131 var interfaceObj = page.interfaces;
nickjillings@2163 132 if (interfaceObj.length > 1)
nickjillings@2163 133 {
nickjillings@2163 134 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
nickjillings@2163 135 }
nickjillings@2163 136 interfaceObj = interfaceObj[0];
nickjillings@2163 137
nickjillings@2163 138 if(interfaceObj.title != null)
nickjillings@2163 139 {
nickjillings@2163 140 document.getElementById("pageTitle").textContent = interfaceObj.title;
nickjillings@2163 141 }
nickjillings@2163 142
nickjillings@2163 143 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
nickjillings@2163 144 for (var option of interfaceOptions)
nickjillings@2163 145 {
nickjillings@2163 146 if (option.type == "show")
nickjillings@2163 147 {
nickjillings@2163 148 switch(option.name) {
nickjillings@2163 149 case "playhead":
nickjillings@2163 150 var playbackHolder = document.getElementById('playback-holder');
nickjillings@2163 151 if (playbackHolder == null)
nickjillings@2163 152 {
nickjillings@2163 153 playbackHolder = document.createElement('div');
nickjillings@2163 154 playbackHolder.style.width = "100%";
nickjillings@2163 155 playbackHolder.style.float = "left";
nickjillings@2163 156 playbackHolder.align = 'center';
nickjillings@2163 157 playbackHolder.appendChild(interfaceContext.playhead.object);
nickjillings@2163 158 feedbackHolder.appendChild(playbackHolder);
nickjillings@2163 159 }
nickjillings@2163 160 break;
nickjillings@2163 161 case "page-count":
nickjillings@2163 162 var pagecountHolder = document.getElementById('page-count');
nickjillings@2163 163 if (pagecountHolder == null)
nickjillings@2163 164 {
nickjillings@2163 165 pagecountHolder = document.createElement('div');
nickjillings@2163 166 pagecountHolder.id = 'page-count';
nickjillings@2163 167 }
nickjillings@2163 168 pagecountHolder.innerHTML = '<span>Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+'</span>';
nickjillings@2163 169 var inject = document.getElementById('interface-buttons');
nickjillings@2163 170 inject.appendChild(pagecountHolder);
nickjillings@2163 171 break;
nickjillings@2163 172 case "volume":
nickjillings@2163 173 if (document.getElementById('master-volume-holder') == null)
nickjillings@2163 174 {
nickjillings@2163 175 feedbackHolder.appendChild(interfaceContext.volume.object);
nickjillings@2163 176 }
nickjillings@2163 177 break;
nickjillings@2163 178 }
nickjillings@2163 179 }
nickjillings@2163 180 }
nickjillings@2163 181
nickjillings@2161 182 interfaceContext.comparator = new comparator(page);
nickjillings@2163 183 resizeWindow(null);
nickjillings@2161 184 }
nickjillings@2161 185
nickjillings@2161 186 function comparator(page)
nickjillings@2161 187 {
nickjillings@2161 188 // Build prototype constructor
nickjillings@2161 189 this.interfaceObject = function(element,label)
nickjillings@2161 190 {
nickjillings@2161 191 // An example node, you can make this however you want for each audioElement.
nickjillings@2161 192 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following
nickjillings@2161 193 // You attach them by calling audioObject.bindInterface( )
nickjillings@2161 194 this.parent = element;
nickjillings@2161 195 this.id = element.id;
nickjillings@2161 196 this.value = 0;
nickjillings@2161 197 this.disabled = true;
nickjillings@2161 198 this.box = document.createElement('div');
nickjillings@2161 199 this.box.className = 'comparator-holder';
nickjillings@2161 200 this.box.setAttribute('track-id',element.id);
nickjillings@2161 201 this.box.id = 'comparator-'+label;
nickjillings@2161 202 this.selector = document.createElement('div');
nickjillings@2161 203 this.selector.className = 'comparator-selector disabled';
nickjillings@2161 204 var selectorText = document.createElement('span');
nickjillings@2161 205 selectorText.textContent = label;
nickjillings@2161 206 this.selector.appendChild(selectorText);
nickjillings@2161 207 this.playback = document.createElement('button');
nickjillings@2161 208 this.playback.className = 'comparator-button';
nickjillings@2161 209 this.playback.disabled = true;
nickjillings@2161 210 this.playback.textContent = "Listen";
nickjillings@2161 211 this.box.appendChild(this.selector);
nickjillings@2161 212 this.box.appendChild(this.playback);
nickjillings@2161 213 this.selector.onclick = function(event)
nickjillings@2161 214 {
nickjillings@2161 215 var label = event.currentTarget.children[0].textContent;
nickjillings@2161 216 if (label == "X" || label == "x") {return;}
nickjillings@2161 217 var time = audioEngineContext.timer.getTestTime();
nickjillings@2161 218 if ($(event.currentTarget).hasClass('disabled'))
nickjillings@2161 219 {
nickjillings@2161 220 console.log("Please wait until sample has loaded");
nickjillings@2161 221 return;
nickjillings@2161 222 }
nickjillings@2161 223 if (audioEngineContext.status == 0)
nickjillings@2161 224 {
nicholas@2362 225 interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection");
nickjillings@2161 226 console.log("Please listen to the samples before making a selection");
nickjillings@2161 227 return;
nickjillings@2161 228 }
nickjillings@2161 229 var id = event.currentTarget.parentElement.getAttribute('track-id');
nickjillings@2161 230 interfaceContext.comparator.selected = id;
nickjillings@2161 231 if ($(event.currentTarget).hasClass("selected")) {
nickjillings@2161 232 $(".comparator-selector").removeClass('selected');
giuliomoro@2291 233 for (var i=0; i<interfaceContext.comparator.pair.length; i++)
nickjillings@2161 234 {
nicholas@2308 235 var obj = interfaceContext.comparator.pair[i];
nickjillings@2161 236 obj.parent.metric.moved(time,0);
nicholas@2308 237 obj.value = 0;
nickjillings@2161 238 }
nickjillings@2161 239 } else {
nickjillings@2161 240 $(".comparator-selector").removeClass('selected');
nickjillings@2161 241 $(event.currentTarget).addClass('selected');
giuliomoro@2291 242 for (var i=0; i<interfaceContext.comparator.pair.length; i++)
nickjillings@2161 243 {
giuliomoro@2291 244 var obj = interfaceContext.comparator.pair[i];
nickjillings@2161 245 if (i == id) {
nickjillings@2161 246 obj.value = 1;
nickjillings@2161 247 } else {
nickjillings@2161 248 obj.value = 0;
nickjillings@2161 249 }
nickjillings@2161 250 obj.parent.metric.moved(time,obj.value);
nickjillings@2161 251 }
nickjillings@2161 252 console.log("Selected "+id+' ('+time+')');
nickjillings@2161 253 }
nickjillings@2161 254 };
nickjillings@2161 255 this.playback.setAttribute("playstate","ready");
nickjillings@2161 256 this.playback.onclick = function(event)
nickjillings@2161 257 {
nickjillings@2161 258 var id = event.currentTarget.parentElement.getAttribute('track-id');
nickjillings@2161 259 if (event.currentTarget.getAttribute("playstate") == "ready")
nickjillings@2161 260 {
nickjillings@2161 261 audioEngineContext.play(id);
nickjillings@2161 262 } else if (event.currentTarget.getAttribute("playstate") == "playing") {
nickjillings@2161 263 audioEngineContext.stop();
nickjillings@2161 264 }
nickjillings@2161 265
nickjillings@2161 266 };
nickjillings@2161 267 this.enable = function()
nickjillings@2161 268 {
nickjillings@2161 269 // This is used to tell the interface object that playback of this node is ready
nickjillings@2161 270 if (this.parent.state == 1)
nickjillings@2161 271 {
nickjillings@2161 272 $(this.selector).removeClass('disabled');
nickjillings@2161 273 this.playback.disabled = false;
nickjillings@2161 274 }
nickjillings@2161 275 };
nickjillings@2161 276 this.updateLoading = function(progress)
nickjillings@2161 277 {
nickjillings@2161 278 // progress is a value from 0 to 100 indicating the current download state of media files
nickjillings@2161 279 if (progress != 100)
nickjillings@2161 280 {
nickjillings@2161 281 progress = String(progress);
nickjillings@2161 282 progress = progress.split('.')[0];
nickjillings@2161 283 this.playback.textContent = progress+'%';
nickjillings@2161 284 } else {
nickjillings@2161 285 this.playback.textContent = "Play";
nickjillings@2161 286 }
nickjillings@2161 287 };
nickjillings@2161 288 this.error = function() {
nickjillings@2161 289 // audioObject has an error!!
nickjillings@2161 290 this.playback.textContent = "Error";
nickjillings@2161 291 $(this.playback).addClass("error-colour");
nickjillings@2161 292 };
nickjillings@2161 293 this.startPlayback = function()
nickjillings@2161 294 {
n@2428 295 if (this.parent.specification.parent.playOne || specification.playOne) {
n@2428 296 $('.comparator-button').text('Wait');
n@2428 297 $('.comparator-button').attr("disabled","true");
n@2428 298 $(this.playback).css("disabled","false");
n@2428 299 } else {
n@2428 300 $('.comparator-button').text('Listen');
n@2428 301 }
nickjillings@2161 302 $(this.playback).text('Stop');
nickjillings@2161 303 this.playback.setAttribute("playstate","playing");
nickjillings@2161 304 };
nickjillings@2161 305 this.stopPlayback = function()
nickjillings@2161 306 {
n@2428 307 if (this.playback.getAttribute("playstate") == "playing") {
n@2428 308 $('.comparator-button').text('Listen');
n@2428 309 $('.comparator-button').removeAttr("disabled");
n@2428 310 this.playback.setAttribute("playstate","ready");
n@2428 311 }
nickjillings@2161 312 };
nickjillings@2161 313 this.getValue = function()
nickjillings@2161 314 {
nickjillings@2161 315 // Return the current value of the object. If there is no value, return 0
nickjillings@2161 316 return this.value;
nickjillings@2161 317 };
nickjillings@2161 318 this.getPresentedId = function()
nickjillings@2161 319 {
nickjillings@2161 320 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale
nickjillings@2161 321 return this.selector.children[0].textContent;
nickjillings@2161 322 };
nickjillings@2161 323 this.canMove = function()
nickjillings@2161 324 {
nickjillings@2161 325 // Return either true or false if the interface object can be moved. AB / Reference cannot, whilst sliders can and therefore have a continuous scale.
nickjillings@2161 326 // These are checked primarily if the interface check option 'fragmentMoved' is enabled.
nickjillings@2161 327 return false;
nickjillings@2161 328 };
nickjillings@2161 329 this.exportXMLDOM = function(audioObject) {
nickjillings@2161 330 // Called by the audioObject holding this element to export the interface <value> node.
nickjillings@2161 331 // If there is no value node (such as outside reference), return null
nickjillings@2161 332 // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute
nickjillings@2161 333 // Use storage.document.createElement('value'); to generate the XML node.
nickjillings@2161 334 var node = storage.document.createElement('value');
nickjillings@2161 335 node.textContent = this.value;
nickjillings@2161 336 return node;
nickjillings@2161 337
nickjillings@2161 338 };
nickjillings@2161 339 this.error = function() {
nickjillings@2161 340 // If there is an error with the audioObject, this will be called to indicate a failure
nickjillings@2161 341 }
nickjillings@2161 342 };
nickjillings@2161 343 // Ensure there are only two comparisons per page
nickjillings@2161 344 if (page.audioElements.length != 2) {
nickjillings@2161 345 console.error('FATAL - There must be 2 <audioelement> nodes on each <page>: '+page.id);
nickjillings@2161 346 return;
nickjillings@2161 347 }
nickjillings@2161 348 // Build the three audio elements
nickjillings@2161 349 this.pair = [];
nickjillings@2161 350 this.X = null;
nickjillings@2161 351 this.boxHolders = document.getElementById('box-holders');
nickjillings@2161 352 for (var index=0; index<page.audioElements.length; index++) {
nickjillings@2161 353 var element = page.audioElements[index];
nickjillings@2161 354 if (element.type != 'normal')
nickjillings@2161 355 {
nickjillings@2161 356 console.log("WARNING - ABX can only have normal elements. Page "+page.id+", Element "+element.id);
nickjillings@2161 357 element.type = "normal";
nickjillings@2161 358 }
nickjillings@2161 359 var audioObject = audioEngineContext.newTrack(element);
nickjillings@2161 360 var label;
nickjillings@2161 361 switch(audioObject.specification.parent.label) {
nickjillings@2161 362 case "none":
nickjillings@2161 363 label = "";
nickjillings@2161 364 break;
nickjillings@2161 365 case "number":
nickjillings@2161 366 label = ""+index;
nickjillings@2161 367 break;
nickjillings@2161 368 case "letter":
nickjillings@2161 369 label = String.fromCharCode(97 + index);
nickjillings@2161 370 break;
nickjillings@2161 371 default:
nickjillings@2161 372 label = String.fromCharCode(65 + index);
nickjillings@2161 373 break;
nickjillings@2161 374 }
nickjillings@2161 375 var node = new this.interfaceObject(audioObject,label);
nickjillings@2161 376 audioObject.bindInterface(node);
nickjillings@2161 377 this.pair.push(node);
nickjillings@2161 378 this.boxHolders.appendChild(node.box);
nickjillings@2161 379 }
nickjillings@2161 380 var elementId = Math.floor(Math.random() * 2); //Randomly pick A or B to be X
giuliomoro@2291 381 var element = new page.audioElementNode(specification);
nickjillings@2161 382 for (var atr in page.audioElements[elementId]) {
nickjillings@2161 383 eval("element."+atr+" = page.audioElements[elementId]."+atr);
nickjillings@2161 384 }
nickjillings@2161 385 element.id += "-X";
nickjillings@2161 386 if (typeof element.name == "string") {element.name+="-X";}
nickjillings@2161 387 page.audioElements.push(element);
nickjillings@2161 388 // Create the save place-holder for the 'X' element
nickjillings@2161 389 var root = testState.currentStore.XMLDOM;
nickjillings@2161 390 var aeNode = storage.document.createElement('audioelement');
nickjillings@2161 391 aeNode.setAttribute('ref',element.id);
nickjillings@2161 392 if (typeof element.name == "string"){aeNode.setAttribute('name',element.name);}
nickjillings@2161 393 aeNode.setAttribute('type','normal');
nickjillings@2161 394 aeNode.setAttribute('url',element.url);
nickjillings@2161 395 aeNode.setAttribute('gain',element.gain);
nickjillings@2161 396 aeNode.appendChild(storage.document.createElement('metric'));
nickjillings@2161 397 root.appendChild(aeNode);
nickjillings@2161 398 // Build the 'X' element
nickjillings@2161 399 var audioObject = audioEngineContext.newTrack(element);
nickjillings@2161 400 var label;
nickjillings@2161 401 switch(audioObject.specification.parent.label) {
nickjillings@2161 402 case "letter":
nickjillings@2161 403 label = "x";
nickjillings@2161 404 break;
nickjillings@2161 405 default:
nickjillings@2161 406 label = "X";
nickjillings@2161 407 break;
nickjillings@2161 408 }
nickjillings@2161 409 var node = new this.interfaceObject(audioObject,label);
giuliomoro@2305 410 node.box.children[0].classList.add('inactive');
nickjillings@2161 411 audioObject.bindInterface(node);
nickjillings@2161 412 this.X = node;
nickjillings@2161 413 this.boxHolders.appendChild(node.box);
nickjillings@2161 414 }
nickjillings@2161 415
nickjillings@2161 416 function resizeWindow(event)
nickjillings@2161 417 {
nickjillings@2163 418 document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px';
nickjillings@2163 419 var numObj = 3;
nickjillings@2163 420 var boxW = numObj*312;
nickjillings@2163 421 var diff = window.innerWidth - boxW;
nickjillings@2163 422 while (diff < 0)
nickjillings@2163 423 {
nickjillings@2163 424 numObj = Math.ceil(numObj/2);
nickjillings@2163 425 boxW = numObj*312;
nickjillings@2163 426 diff = window.innerWidth - boxW;
nickjillings@2163 427 }
nickjillings@2163 428 document.getElementById('box-holders').style.marginLeft = diff/2 + 'px';
nickjillings@2163 429 document.getElementById('box-holders').style.marginRight = diff/2 + 'px';
nickjillings@2163 430 document.getElementById('box-holders').style.width = boxW + 'px';
nickjillings@2161 431 }
nickjillings@2161 432
nickjillings@2161 433 function buttonSubmitClick()
nickjillings@2161 434 {
nickjillings@2163 435 var checks = [];
nickjillings@2163 436 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
nickjillings@2163 437 checks = checks.concat(specification.interfaces.options);
nickjillings@2163 438 var canContinue = true;
nickjillings@2163 439
nickjillings@2163 440 for (var i=0; i<checks.length; i++) {
nickjillings@2163 441 if (checks[i].type == 'check')
nickjillings@2163 442 {
nickjillings@2163 443 switch(checks[i].name) {
nickjillings@2163 444 case 'fragmentPlayed':
nickjillings@2163 445 // Check if all fragments have been played
nickjillings@2163 446 var checkState = interfaceContext.checkAllPlayed();
nickjillings@2163 447 if (checkState == false) {canContinue = false;}
nickjillings@2163 448 break;
nickjillings@2163 449 case 'fragmentFullPlayback':
nickjillings@2163 450 // Check all fragments have been played to their full length
nickjillings@2163 451 var checkState = interfaceContext.checkFragmentsFullyPlayed();
nickjillings@2163 452 if (checkState == false) {canContinue = false;}
nickjillings@2163 453 break;
nickjillings@2163 454 case 'fragmentMoved':
nickjillings@2163 455 // Check all fragment sliders have been moved.
nickjillings@2163 456 var checkState = interfaceContext.checkAllMoved();
nickjillings@2163 457 if (checkState == false) {canContinue = false;}
nickjillings@2163 458 break;
nickjillings@2163 459 case 'fragmentComments':
nickjillings@2163 460 // Check all fragment sliders have been moved.
nickjillings@2163 461 var checkState = interfaceContext.checkAllCommented();
nickjillings@2163 462 if (checkState == false) {canContinue = false;}
nickjillings@2163 463 break;
nicholas@2310 464 case 'scalerange':
nicholas@2310 465 // Check the scale has been used effectively
nicholas@2310 466 var checkState = interfaceContext.checkScaleRange(checks[i].min,checks[i].max);
nicholas@2310 467 if (checkState == false) {canContinue = false;}
nicholas@2310 468 break;
nickjillings@2163 469 default:
nickjillings@2163 470 console.log("WARNING - Check option "+checks[i].check+" is not supported on this interface");
nickjillings@2163 471 break;
nickjillings@2163 472 }
nickjillings@2163 473
nickjillings@2163 474 }
nickjillings@2163 475 if (!canContinue) {break;}
nickjillings@2163 476 }
nickjillings@2163 477 if (canContinue)
nickjillings@2163 478 {
nickjillings@2163 479 if (audioEngineContext.status == 1) {
nickjillings@2163 480 var playback = document.getElementById('playback-button');
nickjillings@2163 481 playback.click();
nickjillings@2163 482 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
nickjillings@2163 483 } else
nickjillings@2163 484 {
nickjillings@2163 485 if (audioEngineContext.timer.testStarted == false)
nickjillings@2163 486 {
nicholas@2362 487 interfaceContext.lightbox.post("Warning",'You have not started the test! Please listen to a sample to begin the test!');
nickjillings@2163 488 return;
nickjillings@2163 489 }
nickjillings@2163 490 }
nickjillings@2163 491 testState.advanceState();
nickjillings@2163 492 }
nickjillings@2161 493 }
nickjillings@2161 494
nickjillings@2161 495 function pageXMLSave(store, pageSpecification)
nickjillings@2161 496 {
nickjillings@2161 497 // MANDATORY
nickjillings@2161 498 // Saves a specific test page
nickjillings@2161 499 // You can use this space to add any extra nodes to your XML <audioHolder> saves
nickjillings@2161 500 // Get the current <page> information in store (remember to appendChild your data to it)
nickjillings@2161 501 // pageSpecification is the current page node configuration
nickjillings@2161 502 // To create new XML nodes, use storage.document.createElement();
nickjillings@2161 503 }