annotate interfaces/AB.js @ 2576:d002a342cfaf

Cherry pick
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 18 Oct 2016 15:28:24 +0100
parents 249a1152e525
children 522f58e7773e
rev   line source
nickjillings@1341 1 // Once this is loaded and parsed, begin execution
nickjillings@1341 2 loadInterface();
nickjillings@1341 3
nickjillings@1341 4 function loadInterface() {
nicholas@2576 5 // Get the dimensions of the screen available to the page
nicholas@2576 6 var width = window.innerWidth;
nicholas@2576 7 var height = window.innerHeight;
nicholas@2576 8 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
nicholas@2576 9
nicholas@2576 10 // Custom comparator Object
nicholas@2576 11 Interface.prototype.comparator = null;
nicholas@2576 12
nicholas@2576 13 Interface.prototype.checkScaleRange = function (min, max) {
nicholas@2359 14 var page = testState.getCurrentTestPage();
nicholas@2359 15 var audioObjects = audioEngineContext.audioObjects;
nicholas@2359 16 var state = true;
nicholas@2359 17 var str = "Please keep listening. ";
nicholas@2359 18 var minRanking = Infinity;
nicholas@2359 19 var maxRanking = -Infinity;
nicholas@2359 20 for (var ao of audioObjects) {
nicholas@2359 21 var rank = ao.interfaceDOM.getValue();
nicholas@2576 22 if (rank < minRanking) {
nicholas@2576 23 minRanking = rank;
nicholas@2576 24 }
nicholas@2576 25 if (rank > maxRanking) {
nicholas@2576 26 maxRanking = rank;
nicholas@2576 27 }
nicholas@2359 28 }
nicholas@2576 29 if (maxRanking * 100 < max) {
nicholas@2359 30 str += "At least one fragment must be selected."
nicholas@2359 31 state = false;
nicholas@2359 32 }
nicholas@2359 33 if (!state) {
nicholas@2359 34 console.log(str);
nicholas@2359 35 this.storeErrorNode(str);
nicholas@2576 36 interfaceContext.lightbox.post("Message", str);
nicholas@2359 37 }
nicholas@2359 38 return state;
nicholas@2359 39 }
nicholas@2576 40
nicholas@2576 41 // The injection point into the HTML page
nicholas@2576 42 interfaceContext.insertPoint = document.getElementById("topLevelBody");
nicholas@2576 43 var testContent = document.createElement('div');
nicholas@2576 44 testContent.id = 'testContent';
nicholas@2576 45
nicholas@2576 46 // Create the top div for the Title element
nicholas@2576 47 var titleAttr = specification.title;
nicholas@2576 48 var title = document.createElement('div');
nicholas@2576 49 title.className = "title";
nicholas@2576 50 title.align = "center";
nicholas@2576 51 var titleSpan = document.createElement('span');
nicholas@2470 52 titleSpan.id = "test-title";
nicholas@2576 53
nicholas@2576 54 // Set title to that defined in XML, else set to default
nicholas@2576 55 if (titleAttr != undefined) {
nicholas@2576 56 titleSpan.textContent = titleAttr;
nicholas@2576 57 } else {
nicholas@2576 58 titleSpan.textContent = 'Listening test';
nicholas@2576 59 }
nicholas@2576 60 // Insert the titleSpan element into the title div element.
nicholas@2576 61 title.appendChild(titleSpan);
nicholas@2576 62
nicholas@2576 63 var pagetitle = document.createElement('div');
nicholas@2576 64 pagetitle.className = "pageTitle";
nicholas@2576 65 pagetitle.align = "center";
nicholas@2576 66 var titleSpan = document.createElement('span');
nicholas@2576 67 titleSpan.id = "pageTitle";
nicholas@2576 68 pagetitle.appendChild(titleSpan);
nicholas@2576 69
nicholas@2576 70 // Create Interface buttons!
nicholas@2576 71 var interfaceButtons = document.createElement('div');
nicholas@2576 72 interfaceButtons.id = 'interface-buttons';
nicholas@2576 73 interfaceButtons.style.height = '25px';
nicholas@2576 74
nicholas@2576 75 // Create playback start/stop points
nicholas@2576 76 var playback = document.createElement("button");
nicholas@2576 77 playback.innerHTML = 'Stop';
nicholas@2576 78 playback.id = 'playback-button';
nicholas@2576 79 playback.style.float = 'left';
nicholas@2576 80 // onclick function. Check if it is playing or not, call the correct function in the
nicholas@2576 81 // audioEngine, change the button text to reflect the next state.
nicholas@2576 82 playback.onclick = function () {
nicholas@2576 83 if (audioEngineContext.status == 1) {
nicholas@2576 84 audioEngineContext.stop();
nicholas@2576 85 this.innerHTML = 'Stop';
nickjillings@1341 86 var time = audioEngineContext.timer.getTestTime();
nickjillings@1341 87 console.log('Stopped at ' + time); // DEBUG/SAFETY
nicholas@2576 88 }
nicholas@2576 89 };
nicholas@2576 90 // Append the interface buttons into the interfaceButtons object.
nicholas@2576 91 interfaceButtons.appendChild(playback);
nicholas@2576 92
nicholas@2576 93 // Global parent for the comment boxes on the page
nicholas@2576 94 var feedbackHolder = document.createElement('div');
nicholas@2576 95 feedbackHolder.id = 'feedbackHolder';
nicholas@2576 96
nicholas@2396 97 // Create outside reference holder
nicholas@2396 98 var outsideRef = document.createElement("div");
nicholas@2396 99 outsideRef.id = "outside-reference-holder";
nicholas@2576 100
nicholas@2576 101 // Construct the AB Boxes
nicholas@2576 102 var boxes = document.createElement('div');
nicholas@2576 103 boxes.align = "center";
nicholas@2576 104 boxes.id = "box-holders";
nickjillings@1341 105 boxes.style.float = "left";
nicholas@2576 106
nicholas@2576 107 var submit = document.createElement('button');
nicholas@2576 108 submit.id = "submit";
nicholas@2576 109 submit.onclick = buttonSubmitClick;
nicholas@2576 110 submit.className = "big-button";
nicholas@2576 111 submit.textContent = "submit";
nicholas@2576 112 submit.style.position = "relative";
nicholas@2576 113 submit.style.left = (window.innerWidth - 250) / 2 + 'px';
nicholas@2576 114
nicholas@2576 115 feedbackHolder.appendChild(boxes);
nicholas@2576 116
nicholas@2475 117 // Create holder for comment boxes
nicholas@2475 118 var comments = document.createElement("div");
nicholas@2475 119 comments.id = "comment-box-holder";
nicholas@2576 120
nicholas@2576 121 // Inject into HTML
nicholas@2576 122 testContent.appendChild(title); // Insert the title
nicholas@2576 123 testContent.appendChild(pagetitle);
nicholas@2576 124 testContent.appendChild(interfaceButtons);
nicholas@2396 125 testContent.appendChild(outsideRef);
nicholas@2576 126 testContent.appendChild(feedbackHolder);
nicholas@2576 127 testContent.appendChild(submit);
nicholas@2475 128 testContent.appendChild(comments);
nicholas@2576 129 interfaceContext.insertPoint.appendChild(testContent);
nickjillings@1341 130
nicholas@2576 131 // Load the full interface
nicholas@2576 132 testState.initialise();
nicholas@2576 133 testState.advanceState();
nickjillings@1341 134 }
nickjillings@1341 135
nicholas@2576 136 function loadTest(audioHolderObject) {
nicholas@2576 137 var feedbackHolder = document.getElementById('feedbackHolder');
nicholas@2576 138 var interfaceObj = audioHolderObject.interfaces;
nicholas@2576 139 if (interfaceObj.length > 1) {
nicholas@2576 140 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
nicholas@2576 141 }
nicholas@2576 142 interfaceObj = interfaceObj[0];
nicholas@2576 143
nicholas@2475 144 var commentHolder = document.getElementById('comment-box-holder');
nicholas@2475 145 commentHolder.innerHTML = "";
nicholas@2576 146
nicholas@2396 147 // Delete outside reference
nicholas@2576 148 var outsideReferenceHolder = document.getElementById("outside-reference-holder");
nicholas@2396 149 outsideReferenceHolder.innerHTML = "";
nicholas@2576 150
nicholas@2470 151 // Set the page title
nicholas@2470 152 if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) {
nicholas@2470 153 document.getElementById("test-title").textContent = audioHolderObject.title
nicholas@2470 154 }
nicholas@2576 155
nicholas@2576 156 if (interfaceObj.title != null) {
nicholas@2576 157 document.getElementById("pageTitle").textContent = interfaceObj.title;
nicholas@2576 158 }
nicholas@2576 159
nickjillings@1356 160 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
nicholas@2394 161 // Clear the interfaceElements
nicholas@2394 162 {
nicholas@2394 163 var node = document.getElementById('playback-holder');
nicholas@2576 164 if (node) {
nicholas@2576 165 feedbackHolder.removeChild(node);
nicholas@2576 166 }
nicholas@2394 167 node = document.getElementById('page-count');
nicholas@2576 168 if (node) {
nicholas@2576 169 document.getElementById('interface-buttons').removeChild(node);
nicholas@2576 170 }
nicholas@2394 171 node = document.getElementById('master-volume-holder-float');
nicholas@2576 172 if (node) {
nicholas@2576 173 feedbackHolder.removeChild(node);
nicholas@2576 174 }
nicholas@2394 175 }
nicholas@2576 176
n@2407 177 // Populate the comparator object
nicholas@2576 178 interfaceContext.comparator = new comparator(audioHolderObject);
nicholas@2576 179
nicholas@2576 180 for (var option of interfaceOptions) {
nicholas@2576 181 if (option.type == "show") {
nicholas@2576 182 switch (option.name) {
nickjillings@1356 183 case "playhead":
nickjillings@1356 184 var playbackHolder = document.getElementById('playback-holder');
nicholas@2576 185 if (playbackHolder == null) {
nickjillings@1356 186 playbackHolder = document.createElement('div');
nicholas@2394 187 playbackHolder.id = 'playback-holder';
nickjillings@1356 188 playbackHolder.style.width = "100%";
nickjillings@1356 189 playbackHolder.style.float = "left";
nickjillings@1356 190 playbackHolder.align = 'center';
nickjillings@1356 191 playbackHolder.appendChild(interfaceContext.playhead.object);
nickjillings@1356 192 feedbackHolder.appendChild(playbackHolder);
nickjillings@1356 193 }
nickjillings@1356 194 break;
nickjillings@1356 195 case "page-count":
nickjillings@1356 196 var pagecountHolder = document.getElementById('page-count');
nicholas@2576 197 if (pagecountHolder == null) {
nickjillings@1356 198 pagecountHolder = document.createElement('div');
nickjillings@1356 199 pagecountHolder.id = 'page-count';
nicholas@2393 200 document.getElementById('interface-buttons').appendChild(pagecountHolder);
nickjillings@1356 201 }
nicholas@2576 202 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
nickjillings@1356 203 break;
nickjillings@1356 204 case "volume":
nicholas@2576 205 if (document.getElementById('master-volume-holder-float') == null) {
nickjillings@1356 206 feedbackHolder.appendChild(interfaceContext.volume.object);
nickjillings@1356 207 }
nickjillings@1356 208 break;
n@2407 209 case "comments":
n@2407 210 // Generate one comment box per presented page
nicholas@2576 211 for (var element of audioEngineContext.audioObjects) {
n@2407 212 interfaceContext.commentBoxes.createCommentBox(element);
n@2407 213 }
nicholas@2576 214 interfaceContext.commentBoxes.showCommentBoxes(commentHolder, true);
n@2407 215 break;
nickjillings@1356 216 }
nickjillings@1356 217 }
nickjillings@1356 218 }
nicholas@2576 219
nicholas@2576 220 $(audioHolderObject.commentQuestions).each(function (index, element) {
nicholas@2576 221 var node = interfaceContext.createCommentQuestion(element);
nicholas@2576 222 commentHolder.appendChild(node.holder);
nicholas@2576 223 });
nicholas@2576 224
nicholas@2576 225 resizeWindow(null);
nickjillings@1341 226 }
nickjillings@1341 227
nicholas@2576 228 function comparator(audioHolderObject) {
nicholas@2576 229 this.comparatorBox = function (audioElement, id, text) {
nicholas@2576 230 this.parent = audioElement;
nicholas@2576 231 this.id = id;
nicholas@2576 232 this.value = 0;
nicholas@2576 233 this.disabled = true;
nicholas@2576 234 this.box = document.createElement('div');
nicholas@2576 235 this.box.className = 'comparator-holder';
nicholas@2576 236 this.box.setAttribute('track-id', audioElement.id);
nicholas@2576 237 this.box.id = 'comparator-' + text;
nicholas@2576 238 this.selector = document.createElement('div');
nicholas@2576 239 this.selector.className = 'comparator-selector disabled';
nicholas@2576 240 var selectorText = document.createElement('span');
nicholas@2576 241 selectorText.textContent = text;
nicholas@2576 242 this.selector.appendChild(selectorText);
nicholas@2576 243 this.playback = document.createElement('button');
nicholas@2576 244 this.playback.className = 'comparator-button';
nicholas@2576 245 this.playback.disabled = true;
nicholas@2576 246 this.playback.textContent = "Listen";
nicholas@2576 247 this.box.appendChild(this.selector);
nicholas@2576 248 this.box.appendChild(this.playback);
nicholas@2576 249 this.selector.onclick = function (event) {
nicholas@2576 250 var time = audioEngineContext.timer.getTestTime();
nicholas@2576 251 if ($(event.currentTarget).hasClass('disabled')) {
nicholas@2576 252 console.log("Please wait until sample has loaded");
nicholas@2576 253 return;
nickjillings@2112 254 }
nicholas@2576 255 if (audioEngineContext.status == 0) {
nicholas@2576 256 interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection");
nicholas@2576 257 console.log("Please listen to the samples before making a selection");
nicholas@2576 258 return;
nicholas@2576 259 }
nicholas@2576 260 var id = event.currentTarget.parentElement.getAttribute('track-id');
nicholas@2576 261 interfaceContext.comparator.selected = id;
nickjillings@2112 262 if ($(event.currentTarget).hasClass("selected")) {
nickjillings@2112 263 $(".comparator-selector").removeClass('selected');
nicholas@2576 264 for (var i = 0; i < interfaceContext.comparator.comparators.length; i++) {
nicholas@2307 265 var obj = interfaceContext.comparator.comparators[i];
nicholas@2576 266 obj.parent.metric.moved(time, 0);
nicholas@2307 267 obj.value = 0;
nickjillings@2112 268 }
nickjillings@2112 269 } else {
nickjillings@2112 270 $(".comparator-selector").removeClass('selected');
nickjillings@2112 271 $(event.currentTarget).addClass('selected');
nicholas@2576 272 for (var i = 0; i < interfaceContext.comparator.comparators.length; i++) {
nickjillings@2112 273 var obj = interfaceContext.comparator.comparators[i];
nickjillings@2112 274 if (i == id) {
nickjillings@2112 275 obj.value = 1;
nickjillings@2112 276 } else {
nickjillings@2112 277 obj.value = 0;
nickjillings@2112 278 }
nicholas@2576 279 obj.parent.metric.moved(time, obj.value);
nickjillings@2112 280 }
nicholas@2576 281 console.log("Selected " + id + ' (' + time + ')');
nickjillings@2112 282 }
nicholas@2576 283 };
nicholas@2576 284 this.playback.setAttribute("playstate", "ready");
nicholas@2576 285 this.playback.onclick = function (event) {
nicholas@2576 286 var id = event.currentTarget.parentElement.getAttribute('track-id');
nicholas@2576 287 if (event.currentTarget.getAttribute("playstate") == "ready") {
nickjillings@1376 288 audioEngineContext.play(id);
nickjillings@1376 289 } else if (event.currentTarget.getAttribute("playstate") == "playing") {
nickjillings@1376 290 audioEngineContext.stop();
nickjillings@1376 291 }
nicholas@2576 292
nicholas@2576 293 };
nicholas@2576 294
nicholas@2576 295 this.enable = function () {
nicholas@2576 296 if (this.parent.state == 1) {
nicholas@2576 297 $(this.selector).removeClass('disabled');
nicholas@2576 298 this.playback.disabled = false;
nicholas@2576 299 }
nicholas@2576 300 };
nicholas@2576 301 this.updateLoading = function (progress) {
nicholas@2576 302 if (progress != 100) {
nicholas@2576 303 progress = String(progress);
nicholas@2576 304 progress = progress.split('.')[0];
nicholas@2576 305 this.playback.textContent = progress + '%';
nicholas@2576 306 } else {
nicholas@2576 307 this.playback.textContent = "Play";
nicholas@2576 308 }
nicholas@2576 309 };
nicholas@2576 310 this.error = function () {
nickjillings@2113 311 // audioObject has an error!!
nickjillings@2113 312 this.playback.textContent = "Error";
nickjillings@2113 313 $(this.playback).addClass("error-colour");
nickjillings@2113 314 }
nicholas@2576 315 this.startPlayback = function () {
n@2426 316 if (this.parent.specification.parent.playOne || specification.playOne) {
n@2426 317 $('.comparator-button').text('Wait');
nicholas@2576 318 <<<<<<< HEAD
n@2426 319 $('.comparator-button').attr("disabled","true");
nicholas@2503 320 $(this.playback).removeAttr("disabled");
nicholas@2576 321 =======
nicholas@2576 322 $('.comparator-button').attr("disabled", "true");
nicholas@2576 323 $(this.playback).css("disabled", "false");
nicholas@2576 324 >>>>>>> 0425ea2... Formatting of AB. WIP for #37
n@2426 325 } else {
n@2426 326 $('.comparator-button').text('Listen');
n@2426 327 }
nickjillings@1376 328 $(this.playback).text('Stop');
nicholas@2576 329 this.playback.setAttribute("playstate", "playing");
nickjillings@1360 330 };
nicholas@2576 331 this.stopPlayback = function () {
n@2426 332 if (this.playback.getAttribute("playstate") == "playing") {
n@2426 333 $('.comparator-button').text('Listen');
n@2426 334 $('.comparator-button').removeAttr("disabled");
nicholas@2576 335 this.playback.setAttribute("playstate", "ready");
n@2426 336 }
nickjillings@1360 337 };
nicholas@2576 338 this.exportXMLDOM = function (audioObject) {
nicholas@2576 339 var node = storage.document.createElement('value');
nicholas@2576 340 node.textContent = this.value;
nicholas@2576 341 return node;
nicholas@2576 342 };
nicholas@2576 343 this.getValue = function () {
nicholas@2576 344 return this.value;
nicholas@2576 345 };
nicholas@2576 346 this.getPresentedId = function () {
nicholas@2576 347 return this.selector.children[0].textContent;
nicholas@2576 348 };
nicholas@2576 349 this.canMove = function () {
nicholas@2576 350 return false;
nicholas@2576 351 };
nicholas@2576 352 };
nicholas@2576 353
nicholas@2576 354 this.boxHolders = document.getElementById('box-holders');
nicholas@2576 355 this.boxHolders.innerHTML = "";
nicholas@2576 356 this.comparators = [];
nicholas@2576 357 this.selected = null;
nicholas@2576 358
nicholas@2576 359 // First generate the Audio Objects for the Audio Engine
nicholas@2576 360 var label = audioHolderObject.labelStart;
nicholas@2576 361 if (label == "") {
nicholas@2576 362 switch (audioHolderObject.label) {
nicholas@2576 363 case "number":
nicholas@2576 364 label = "1";
nicholas@2576 365 break;
nicholas@2576 366 case "letter":
nicholas@2576 367 label = "a";
nicholas@2576 368 break;
nicholas@2576 369 case "none":
nicholas@2576 370 label = "";
nicholas@2576 371 break;
nicholas@2576 372 case "capital":
nicholas@2576 373 default:
nicholas@2576 374 label = "A";
nicholas@2576 375 break;
nicholas@2576 376 }
nicholas@2576 377 } else {
nicholas@2576 378 switch (audioHolderObject.label) {
nicholas@2576 379 case "number":
nicholas@2576 380 if (!isFinite(Number(label))) {
nicholas@2576 381 label = "1";
nicholas@2576 382 }
nicholas@2576 383 break;
nicholas@2576 384 case "letter":
nicholas@2576 385 if (label.charCodeAt(0) < 97 || label.charCodeAt(0) > 122) {
nicholas@2576 386 label = "a";
nicholas@2576 387 }
nicholas@2576 388 break;
nicholas@2576 389 case "none":
nicholas@2576 390 label = "";
nicholas@2576 391 break;
nicholas@2576 392 case "capital":
nicholas@2576 393 default:
nicholas@2576 394 if (label.charCodeAt(0) < 65 || label.charCodeAt(0) > 90) {
nicholas@2576 395 label = "A";
nicholas@2576 396 }
nicholas@2576 397 break;
nicholas@2576 398 }
nicholas@2576 399 }
nicholas@2576 400 for (var index = 0; index < audioHolderObject.audioElements.length; index++) {
nicholas@2576 401 var element = audioHolderObject.audioElements[index];
nickjillings@2177 402 var audioObject = audioEngineContext.newTrack(element);
nicholas@2576 403 if (index == audioHolderObject.outsideReference || element.type == 'outside-reference') {
nicholas@2576 404 var orNode = new interfaceContext.outsideReferenceDOM(audioObject, index, document.getElementById("outside-reference-holder"));
nicholas@2576 405 audioObject.bindInterface(orNode);
nickjillings@2177 406 } else {
nicholas@2576 407 var node = new this.comparatorBox(audioObject, index, label);
nicholas@2576 408 switch (audioHolderObject.label) {
nickjillings@2177 409 case "none":
nickjillings@2177 410 label = "";
nickjillings@2177 411 break;
nickjillings@2177 412 case "number":
nicholas@2576 413 label = (Number(label) + 1).toString(10);
nickjillings@2177 414 break;
nickjillings@2177 415 case "letter":
nicholas@2576 416 label = String.fromCharCode((label.charCodeAt(0) - 96) % 26 + 97);
nickjillings@2177 417 break;
nicholas@2576 418 case "capital":
nickjillings@2177 419 default:
nicholas@2576 420 label = String.fromCharCode((label.charCodeAt(0) - 64) % 26 + 65);
nickjillings@2177 421 break;
nickjillings@2177 422 }
nickjillings@2177 423 audioObject.bindInterface(node);
nickjillings@2177 424 this.comparators.push(node);
nickjillings@2177 425 this.boxHolders.appendChild(node.box);
nickjillings@1295 426 }
nicholas@2576 427 }
nicholas@2576 428 return this;
nickjillings@1341 429 }
nickjillings@1341 430
nicholas@2576 431 function resizeWindow(event) {
nicholas@2576 432 document.getElementById('submit').style.left = (window.innerWidth - 250) / 2 + 'px';
nicholas@2576 433 var numObj = interfaceContext.comparator.comparators.length;
nicholas@2576 434 var boxW = numObj * 312;
nickjillings@1341 435 var diff = window.innerWidth - boxW;
nicholas@2576 436 while (diff < 0) {
nicholas@2576 437 numObj = Math.ceil(numObj / 2);
nicholas@2576 438 boxW = numObj * 312;
nickjillings@1341 439 diff = window.innerWidth - boxW;
nickjillings@1341 440 }
nicholas@2576 441 document.getElementById('box-holders').style.marginLeft = diff / 2 + 'px';
nicholas@2576 442 document.getElementById('box-holders').style.marginRight = diff / 2 + 'px';
nickjillings@1341 443 document.getElementById('box-holders').style.width = boxW + 'px';
nicholas@2576 444
nickjillings@2177 445 var outsideRef = document.getElementById('outside-reference');
nicholas@2576 446 if (outsideRef != null) {
nicholas@2576 447 outsideRef.style.left = (window.innerWidth - 120) / 2 + 'px';
nicholas@2576 448 }
nickjillings@1341 449 }
nickjillings@1341 450
nicholas@2576 451 function buttonSubmitClick() {
nicholas@2576 452 var checks = [];
nicholas@2576 453 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
nicholas@2576 454 checks = checks.concat(specification.interfaces.options);
nicholas@2576 455 var canContinue = true;
nickjillings@1341 456
nicholas@2576 457 for (var i = 0; i < checks.length; i++) {
nicholas@2576 458 if (checks[i].type == 'check') {
nicholas@2576 459 switch (checks[i].name) {
nicholas@2576 460 case 'fragmentPlayed':
nicholas@2576 461 // Check if all fragments have been played
nicholas@2576 462 var checkState = interfaceContext.checkAllPlayed();
nicholas@2576 463 if (checkState == false) {
nicholas@2576 464 canContinue = false;
nicholas@2576 465 }
nicholas@2576 466 break;
nicholas@2576 467 case 'fragmentFullPlayback':
nicholas@2576 468 // Check all fragments have been played to their full length
nicholas@2576 469 var checkState = interfaceContext.checkFragmentsFullyPlayed();
nicholas@2576 470 if (checkState == false) {
nicholas@2576 471 canContinue = false;
nicholas@2576 472 }
nicholas@2576 473 break;
nicholas@2576 474 case 'fragmentMoved':
nicholas@2576 475 // Check all fragment sliders have been moved.
nicholas@2576 476 var checkState = interfaceContext.checkAllMoved();
nicholas@2576 477 if (checkState == false) {
nicholas@2576 478 canContinue = false;
nicholas@2576 479 }
nicholas@2576 480 break;
nicholas@2576 481 case 'fragmentComments':
nicholas@2576 482 // Check all fragment sliders have been moved.
nicholas@2576 483 var checkState = interfaceContext.checkAllCommented();
nicholas@2576 484 if (checkState == false) {
nicholas@2576 485 canContinue = false;
nicholas@2576 486 }
nicholas@2576 487 break;
nicholas@2576 488 case 'scalerange':
nicholas@2576 489 // Check the scale has been used effectively
nicholas@2576 490 var checkState = interfaceContext.checkScaleRange(checks[i].min, checks[i].max);
nicholas@2576 491 if (checkState == false) {
nicholas@2576 492 canContinue = false;
nicholas@2576 493 }
nicholas@2576 494 break;
nicholas@2576 495 default:
nicholas@2576 496 console.log("WARNING - Check option " + checks[i].check + " is not supported on this interface");
nicholas@2576 497 break;
nicholas@2576 498 }
nicholas@2576 499
nicholas@2576 500 }
nicholas@2576 501 if (!canContinue) {
nicholas@2576 502 break;
nicholas@2576 503 }
nicholas@2576 504 }
nicholas@2576 505 if (canContinue) {
nicholas@2576 506 if (audioEngineContext.status == 1) {
nicholas@2576 507 var playback = document.getElementById('playback-button');
nicholas@2576 508 playback.click();
nicholas@2576 509 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
nicholas@2576 510 } else {
nicholas@2576 511 if (audioEngineContext.timer.testStarted == false) {
nicholas@2576 512 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click play on a sample to begin the test!');
nicholas@2576 513 return;
nicholas@2576 514 }
nicholas@2576 515 }
nicholas@2576 516 testState.advanceState();
nicholas@2576 517 }
nickjillings@1341 518 }
nickjillings@1341 519
nicholas@2576 520 function pageXMLSave(store, pageSpecification) {
nicholas@2576 521 // MANDATORY
nicholas@2576 522 // Saves a specific test page
nicholas@2576 523 // You can use this space to add any extra nodes to your XML <audioHolder> saves
nicholas@2576 524 // Get the current <page> information in store (remember to appendChild your data to it)
nicholas@2576 525 // pageSpecification is the current page node configuration
nicholas@2576 526 // To create new XML nodes, use storage.document.createElement();
nicholas@2576 527 }