annotate test_create/test_core.js @ 3099:fc9718756d55

#200 Auto-pair fragments for AB and ABX in test create.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 16 Jan 2018 16:11:35 +0000
parents 348d59ab726e
children 1ae8c03dd6a6
rev   line source
nicholas@2885 1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification, XMLSerializer, Blob, DOMParser, FileReader, $*/
nicholas@2851 2 function get(url) {
nicholas@2851 3 // Return a new promise.
nicholas@2851 4 return new Promise(function (resolve, reject) {
nicholas@2851 5 // Do the usual XHR stuff
nicholas@2851 6 var req = new XMLHttpRequest();
nicholas@2851 7 req.open('GET', url);
nickjillings@1370 8
nicholas@2851 9 req.onload = function () {
nicholas@2851 10 // This is called even on 404 etc
nicholas@2851 11 // so check the status
nicholas@2851 12 if (req.status == 200) {
nicholas@2851 13 // Resolve the promise with the response text
nicholas@2851 14 resolve(req.response);
nicholas@2851 15 } else {
nicholas@2851 16 // Otherwise reject with the status text
nicholas@2851 17 // which will hopefully be a meaningful error
nicholas@2851 18 reject(Error(req.statusText));
nicholas@2851 19 }
nicholas@2851 20 };
nicholas@2851 21
nicholas@2851 22 // Handle network errors
nicholas@2851 23 req.onerror = function () {
nicholas@2851 24 reject(Error("Network Error"));
nicholas@2851 25 };
nicholas@2851 26
nicholas@2851 27 // Make the request
nicholas@2851 28 req.send();
nicholas@2851 29 });
nickjillings@1370 30 }
nickjillings@1370 31
nicholas@2851 32 var AngularInterface = angular.module("creator", []);
nickjillings@1370 33
nicholas@3097 34 AngularInterface.directive("dropzone", function () {
nicholas@3097 35 return {
nicholas@3097 36 restrict: "A",
nicholas@3097 37 link: function (scope, elem) {
nicholas@3097 38 elem.bind('dragover', function (evt) {
nicholas@3097 39 evt.stopPropagation();
nicholas@3097 40 evt.preventDefault();
nicholas@3097 41 });
nicholas@3097 42 elem.bind('dragend', function (evt) {
nicholas@3097 43 console.log(evt);
nicholas@3097 44 evt.stopPropagation();
nicholas@3097 45 evt.preventDefault();
nicholas@3097 46 });
nicholas@3097 47 elem.bind('drop', function (event) {
nicholas@3097 48 var evt = event.originalEvent;
nicholas@3097 49 console.log(evt);
nicholas@3097 50 evt.stopPropagation();
nicholas@3097 51 evt.preventDefault();
nicholas@3097 52
nicholas@3097 53 var files = evt.dataTransfer.files;
nicholas@3097 54 for (var i = 0, f; f = files[i]; i++) {
nicholas@3097 55 var reader = new FileReader();
nicholas@3097 56 reader.readAsArrayBuffer(f);
nicholas@3097 57
nicholas@3097 58 reader.onload = (function (theFile) {
nicholas@3097 59 return function (e) {
nicholas@3099 60 scope.ondrop(theFile.name);
nicholas@3097 61 scope.$apply();
nicholas@3097 62 };
nicholas@3097 63 })(f);
nicholas@3097 64 }
nicholas@3097 65 });
nicholas@3097 66 }
nicholas@3097 67 }
nicholas@3097 68 });
nicholas@3097 69
nicholas@2851 70 var specification = new Specification();
nickjillings@1370 71
nicholas@2535 72 window.onload = function () {
nicholas@2851 73 // Get the test interface specifications
n@2911 74 toggleDropdowns();
nicholas@3098 75 $("#popupHolder").modal("show");
n@2911 76 };
n@2911 77
n@2911 78 function toggleDropdowns() {
nicholas@2884 79 $(function () {
nicholas@2884 80 $('[data-toggle="popover"]').popover();
nicholas@2884 81 });
n@2911 82 }
nicholas@2535 83
nicholas@2861 84 function handleFiles(event) {
nicholas@2861 85 var s = angular.element(event.currentTarget).scope();
nicholas@2861 86 s.handleFiles(event);
nicholas@2861 87 s.$apply();
nicholas@2861 88 }
nicholas@2861 89
nicholas@2851 90 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2864 91 $s.testSpecifications = {};
nicholas@2864 92
nicholas@2864 93 (function () {
nicholas@2864 94 new Promise(function (resolve, reject) {
nicholas@2864 95 var xml = new XMLHttpRequest();
nicholas@2864 96 xml.open("GET", "test_create/interfaces/specifications.json");
nicholas@2864 97 xml.onload = function () {
nicholas@2864 98 if (xml.status === 200) {
nicholas@2864 99 resolve(xml.responseText);
nicholas@2864 100 return;
nicholas@2864 101 }
nicholas@2864 102 reject(xml.status);
nicholas@2864 103 };
nicholas@2864 104 xml.onerror = function () {
nicholas@2864 105 reject(new Error("Network Error"));
nicholas@2864 106 };
nicholas@2864 107 xml.send();
nicholas@2864 108 }).then(JSON.parse).then(function (data) {
nicholas@2864 109 $s.testSpecifications = data;
nicholas@2864 110 $s.$apply();
nicholas@2865 111 });
nicholas@2864 112 })();
nickjillings@1370 113
nicholas@2851 114 $s.globalSchema = undefined;
nicholas@2851 115 get("xml/test-schema.xsd").then(function (text) {
nicholas@2851 116 specification.processSchema(text);
nicholas@2851 117 $s.globalSchema = specification.getSchema();
nicholas@2851 118 });
n@2912 119 $s.availableInterfaceModules = [];
n@2912 120 get("interfaces/interfaces.json").then(JSON.parse).then(function (d) {
n@2912 121 $s.availableInterfaceModules = d.interfaces;
n@2912 122 $s.$apply();
n@2912 123 });
nicholas@2851 124 $s.specification = specification;
nicholas@2886 125 $s.selectedTestPrototype = undefined;
nicholas@2886 126 $s.setTestPrototype = function (obj) {
nicholas@2886 127 $s.selectedTestPrototype = obj;
nicholas@2886 128 $w.specification.interface = obj.interface;
nicholas@2886 129 }
nicholas@2857 130
nicholas@2857 131 $s.addPage = function () {
nicholas@2857 132 $s.specification.createNewPage();
nicholas@2859 133 };
nicholas@2860 134
nicholas@2862 135 $s.removePage = function (page) {
nicholas@2862 136 var index = $s.specification.pages.findIndex(function (a) {
nicholas@2862 137 return a == page;
nicholas@2862 138 });
nicholas@2862 139 if (index === -1) {
nicholas@2862 140 throw ("Invalid Page");
nicholas@2862 141 }
nicholas@2862 142 $s.specification.pages.splice(index, 1);
nicholas@2862 143 };
nicholas@2862 144
nicholas@2860 145 $s.exportXML = function () {
nicholas@2860 146 var s = new XMLSerializer();
schlien@2961 147 var doc = specification.encode();
nicholas@2891 148 var xmlstr = s.serializeToString(doc);
schlien@2961 149 var bb = new Blob(["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(doc)], {
nicholas@2860 150 type: 'application/xml'
nicholas@2860 151 });
nicholas@2860 152 var dnlk = window.URL.createObjectURL(bb);
nicholas@2891 153 var a = document.createElement("a");
n@2913 154 document.body.appendChild(a)
nicholas@2891 155 a.href = dnlk;
nicholas@2891 156 a.download = "test.xml";
nicholas@2891 157 a.click();
nicholas@2891 158 window.URL.revokeObjectURL(dnlk);
n@2913 159 document.body.removeChild(a);
nicholas@2861 160 };
nicholas@2887 161 $s.validated = false;
nicholas@2887 162 $s.showValidationMessages = false;
nicholas@2887 163 $s.validate = function () {
nicholas@2887 164 var s = new XMLSerializer();
nicholas@2887 165 var Module = {
nicholas@2959 166 xml: "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(specification.encode()),
nicholas@2887 167 schema: specification.getSchemaString(),
nicholas@2887 168 arguments: ["--noout", "--schema", 'test-schema.xsd', 'document.xml']
nicholas@2887 169 };
nicholas@2887 170 var xmllint = validateXML(Module);
nicholas@2887 171 console.log(xmllint);
nicholas@2887 172 if (xmllint != 'document.xml validates\n') {
nicholas@2887 173 $s.validated = false;
nicholas@2887 174 var list = $e[0].querySelector("#validation-error-list");
nicholas@2887 175 while (list.firstChild) {
nicholas@2887 176 list.removeChild(list.firstChild);
nicholas@2887 177 }
nicholas@2887 178 var errors = xmllint.split('\n');
nicholas@2887 179 errors = errors.slice(0, errors.length - 2);
nicholas@2887 180 errors.forEach(function (str) {
nicholas@2887 181 var li = document.createElement("li");
nicholas@2887 182 li.textContent = str;
nicholas@2887 183 list.appendChild(li);
nicholas@2887 184 });
nicholas@2887 185 } else {
nicholas@2887 186 $s.validated = true;
nicholas@2887 187 }
nicholas@2887 188 $s.showValidationMessages = true;
nicholas@2887 189 }
nicholas@2887 190 $s.hideValidationMessages = function () {
nicholas@2887 191 $s.showValidationMessages = false;
nicholas@2887 192 }
n@2911 193 $s.$watch(function () {
n@2911 194 return document.querySelectorAll("div.pageNode").length;
n@2911 195 }, $w.toggleDropdowns);
n@2911 196 $s.$watch(function () {
n@2911 197 return document.querySelectorAll("div.surveyentry").length;
n@2911 198 }, $w.toggleDropdowns);
n@2911 199 $s.$watch(function () {
n@2911 200 return document.querySelectorAll("div.interface").length;
n@2911 201 }, $w.toggleDropdowns);
n@2911 202 $s.$watch(function () {
n@2911 203 return document.querySelectorAll("div.audioelement").length;
n@2911 204 }, $w.toggleDropdowns);
nicholas@2851 205 }]);
nickjillings@1370 206
nicholas@2851 207 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 208 $s.state = 0;
n@2908 209 $s.selected = undefined;
nicholas@3099 210 $s.close = function () {
nicholas@3099 211 $($e[0]).modal('hide');
nicholas@3099 212 }
nicholas@2851 213 $s.next = function () {
nicholas@3099 214 if (($s.state === 0 && $s.file) || $s.state === 1) {
nicholas@3099 215 $s.initialise($s.selected);
nicholas@3099 216 if ($s.selected != "AB" && $s.selected != "ABX") {
nicholas@3099 217 $s.close();
nicholas@3099 218 }
nicholas@3099 219 } else if ($s.state === 2 && $s.audioFragments.length > 0) {
nicholas@3099 220 // Populate the audio pages by creating a pairwise set of pairs
nicholas@3099 221 $s.populatePages((function (a) {
nicholas@3099 222 var b = [];
nicholas@3099 223 a.forEach(function (e1, i1, a) {
nicholas@3099 224 a.forEach(function (e2, i2) {
nicholas@3099 225 var entry = [e1, e2];
nicholas@3099 226 if (i1 > i2) {
nicholas@3099 227 b.push(entry);
nicholas@3099 228 }
nicholas@3099 229 });
nicholas@3099 230 });
nicholas@3099 231 return b;
nicholas@3099 232 })($s.audioFragments));
nicholas@3099 233 $s.close();
nicholas@3099 234 } else if ($s.state > 2) {
nicholas@3099 235 $s.close();
nicholas@3099 236 }
nicholas@2851 237 $s.state++;
nicholas@3099 238 console.log("Modal state " + $s.state);
nicholas@2851 239 };
nicholas@3099 240 $s.skip = function () {
nicholas@3099 241 $s.close();
nicholas@3099 242 }
nicholas@2851 243 $s.back = function () {
nicholas@2851 244 $s.state--;
nicholas@2851 245 };
nicholas@2851 246 $s.mouseover = function (name) {
nicholas@2864 247 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 248 return i.name == name;
nicholas@2851 249 });
nicholas@2851 250 if (obj) {
nicholas@2851 251 $s.description = obj.description.en;
nicholas@2851 252 }
nicholas@2851 253 };
nicholas@2851 254 $s.initialise = function (name) {
nicholas@2885 255 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 256 return i.name == name;
nicholas@2851 257 });
nicholas@2886 258 if (obj === undefined) {
nicholas@2886 259 throw ("Cannot find specification");
nicholas@2886 260 }
n@2908 261 if (typeof obj.template === "string") {
n@2908 262 get(obj.template).then(function (data) {
n@2908 263 $s.parseFile(data);
n@2908 264 }, function (err) {})
n@2908 265 } else {
n@2908 266 $s.setTestPrototype(obj);
n@2908 267 }
nicholas@2851 268 };
n@2908 269 $s.select = function (name) {
nicholas@3099 270 $s.selected = name;
nicholas@3099 271 };
nicholas@3099 272 // Get the test interface specifications
nicholas@2861 273 $s.file = undefined;
nicholas@2851 274 $s.description = "";
nicholas@2861 275
n@2908 276 $s.parseFile = function (f) {
n@2908 277 var p = new DOMParser();
n@2908 278 specification.decode(p.parseFromString(f, "text/xml"));
n@2908 279 $s.$apply();
n@2908 280 }
n@2908 281
nicholas@2861 282 $s.handleFiles = function ($event) {
nicholas@2861 283 $s.file = $event.currentTarget.files[0];
nicholas@2861 284 var r = new FileReader();
nicholas@2861 285 r.onload = function () {
n@2908 286 $s.parseFile(r.result);
nicholas@2862 287 };
nicholas@2861 288 r.readAsText($s.file);
nicholas@2861 289 };
nicholas@3099 290
nicholas@3099 291 $s.audioFragments = [];
nicholas@3099 292 $s.ondrop = function (filename) {
nicholas@3099 293 $s.audioFragments.push({
nicholas@3099 294 fname: filename,
nicholas@3099 295 name: "fragment-" + String($s.audioFragments.length)
nicholas@3099 296 });
nicholas@3099 297 };
nicholas@3099 298
nicholas@3099 299 $s.populatePages = function (structures) {
nicholas@3099 300 structures.forEach(function (p, i) {
nicholas@3099 301 var page = $w.specification.createNewPage();
nicholas@3099 302 page.id = "page-" + String(i);
nicholas@3099 303 p.forEach(function (a) {
nicholas@3099 304 var fragment = page.addAudioElement();
nicholas@3099 305 fragment.name = a.name;
nicholas@3099 306 fragment.id = a.name + "-p" + String(i);
nicholas@3099 307 fragment.url = a.fname;
nicholas@3099 308 });
nicholas@3099 309 page.addInterface();
nicholas@3099 310 });
nicholas@3099 311 }
nicholas@2851 312 }]);
nickjillings@1370 313
nicholas@2851 314 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 315 function initialise() {
nicholas@2851 316 if ($s.globalSchema) {
nicholas@2851 317 $s.schema = $s.globalSchema.querySelector("[name=setup]");
nickjillings@1385 318 }
nickjillings@1370 319 }
nicholas@2851 320 $s.schema = undefined;
nicholas@2851 321 $s.attributes = [];
nickjillings@1370 322
nicholas@2851 323 $s.$watch("globalSchema", initialise);
nicholas@2853 324 $s.$watch("specification.metrics.enabled.length", function () {
nicholas@2853 325 var metricsNode = document.getElementById("metricsNode");
nicholas@2853 326 if (!$s.specification.metrics) {
nicholas@2853 327 return;
nicholas@2853 328 }
nicholas@2853 329 metricsNode.querySelectorAll("input").forEach(function (DOM) {
nicholas@2853 330 DOM.checked = false;
nicholas@2853 331 });
nicholas@2853 332 $s.specification.metrics.enabled.forEach(function (metric) {
nicholas@2853 333 var DOM = metricsNode.querySelector("[value=" + metric + "]");
nicholas@2853 334 if (DOM) {
nicholas@2853 335 DOM.checked = true;
nicholas@2853 336 }
nicholas@2853 337 });
nicholas@2855 338 });
nicholas@2853 339
nicholas@2853 340 $s.enableMetric = function ($event) {
nicholas@2853 341 var metric = $event.currentTarget.value;
nicholas@2853 342 var index = specification.metrics.enabled.findIndex(function (a) {
nicholas@2853 343 return a == metric;
nicholas@2853 344 });
nicholas@2853 345 if ($event.currentTarget.checked) {
nicholas@2853 346 if (index == -1) {
nicholas@2853 347 specification.metrics.enabled.push(metric);
nicholas@2853 348 }
nicholas@2853 349 } else {
nicholas@2853 350 if (index >= 0) {
nicholas@2853 351 specification.metrics.enabled.splice(index, 1);
nicholas@2853 352 }
nicholas@2853 353 }
nicholas@2855 354 };
nicholas@2886 355
nicholas@2886 356 $s.configure = function () {}
nicholas@2886 357
nicholas@2886 358 $s.$watch("selectedTestPrototype", $s.configure);
n@2907 359
n@2907 360 $s.placeholder = function (name) {
n@2908 361 if ($s.schema) {
n@2908 362 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2908 363 var attr = spec.getAttribute("default");
n@2912 364 if (attr === null) {
n@2912 365 return "Not set";
n@2908 366 }
n@2908 367 return attr;
n@2907 368 }
n@2907 369 }
nicholas@2851 370 }]);
nicholas@2853 371
nicholas@2858 372 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2858 373 $s.addSurveyEntry = function () {
nicholas@2858 374 $s.survey.addOption();
nicholas@2858 375 };
nicholas@2858 376 $s.removeSurveyEntry = function (entry) {
nicholas@2858 377 var index = $s.survey.options.findIndex(function (a) {
nicholas@2858 378 return a == entry;
nicholas@2858 379 });
nicholas@2858 380 if (index === -1) {
nicholas@2858 381 throw ("Invalid Entry");
nicholas@2858 382 }
nicholas@2858 383 $s.survey.options.splice(index, 1);
nicholas@2858 384 };
nicholas@2858 385 }]);
nicholas@2858 386
nicholas@2853 387 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2853 388
nicholas@2853 389 $s.removeOption = function (option) {
nicholas@2853 390 var index = $s.opt.options.findIndex(function (a) {
nicholas@2853 391 return a == option;
nicholas@2853 392 });
nicholas@2853 393 if (index === -1) {
nicholas@2853 394 throw ("Invalid option");
nicholas@2853 395 }
nicholas@2853 396 $s.opt.options.splice(index, 1);
nicholas@2853 397 };
nicholas@2853 398 $s.addOption = function () {
nicholas@2853 399 $s.opt.options.push({
nicholas@2853 400 name: "",
nicholas@2853 401 text: ""
nicholas@2853 402 });
nicholas@2855 403 };
nicholas@2857 404
nicholas@2857 405 $s.addCondition = function () {
nicholas@2857 406 $s.opt.conditions.push({
nicholas@2857 407 check: "equals",
nicholas@2857 408 value: "",
nicholas@2857 409 jumpToOnPass: undefined,
nicholas@2857 410 jumpToOnFail: undefined
nicholas@2857 411 });
nicholas@2857 412 };
nicholas@2857 413
nicholas@2857 414 $s.removeCondition = function (condition) {
nicholas@2857 415 var index = $s.opt.conditions.findIndex(function (c) {
nicholas@2857 416 return c == condition;
nicholas@2857 417 });
nicholas@2857 418 if (index === -1) {
nicholas@2857 419 throw ("Invalid Condition");
nicholas@2857 420 }
nicholas@2857 421 $s.opt.conditions.splice(index, 1);
nicholas@2857 422 };
nicholas@2855 423 }]);
nicholas@2855 424
nicholas@2855 425 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2855 426 $s.$watch("interface.options.length", function () {
nicholas@2855 427 if (!$s.interface || !$s.interface.options) {
nicholas@2855 428 return;
nicholas@2855 429 }
nicholas@2855 430 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
nicholas@2855 431 options.forEach(function (option) {
nicholas@2855 432 var name = option.getAttribute("name");
nicholas@2855 433 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 434 return io.name == name;
nicholas@2855 435 });
nicholas@2855 436 option.querySelector("input").checked = (index >= 0);
nicholas@2855 437 if (name == "scalerange" && index >= 0) {
nicholas@2855 438 option.querySelector("[name=min]").value = $s.interface.options[index].min;
nicholas@2855 439 option.querySelector("[name=max]").value = $s.interface.options[index].max;
nicholas@2855 440 }
nicholas@2855 441 });
nicholas@2855 442 });
nicholas@2855 443 $s.enableInterfaceOption = function ($event) {
nicholas@2855 444 var name = $event.currentTarget.parentElement.getAttribute("name");
nicholas@2855 445 var type = $event.currentTarget.parentElement.getAttribute("type");
nicholas@2855 446 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 447 return io.name == name;
nicholas@2855 448 });
nicholas@2855 449 if (index == -1 && $event.currentTarget.checked) {
nicholas@2855 450 var obj = $s.interface.options.push({
nicholas@2855 451 name: name,
nicholas@2855 452 type: type
nicholas@2855 453 });
nicholas@2855 454 if (name == "scalerange") {
nicholas@2855 455 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
nicholas@2855 456 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
nicholas@2855 457 }
nicholas@2855 458 } else if (index >= 0 && !$event.currentTarget.checked) {
nicholas@2855 459 $s.interface.options.splice(index, 1);
nicholas@2855 460 }
nicholas@2857 461 };
nicholas@2886 462 $s.scales = [];
nicholas@2857 463 $s.removeScale = function (scale) {
nicholas@2857 464 var index = $s.interface.scales.findIndex(function (s) {
nicholas@2857 465 return s == scale;
nicholas@2857 466 });
nicholas@2857 467 if (index >= 0) {
nicholas@2857 468 $s.interface.scales.splice(index, 1);
nicholas@2857 469 }
nicholas@2857 470 };
nicholas@2857 471 $s.addScale = function () {
nicholas@2857 472 $s.interface.scales.push({
nicholas@2857 473 position: undefined,
nicholas@2857 474 text: undefined
nicholas@2857 475 });
nicholas@2857 476 };
nicholas@2864 477 $s.clearScales = function () {
nicholas@2864 478 $s.interface.scales = [];
nicholas@2864 479 };
nicholas@2876 480 $s.useScales = function (scale) {
nicholas@2864 481 $s.clearScales();
nicholas@2876 482 scale.scales.forEach(function (s) {
nicholas@2864 483 $s.interface.scales.push(s);
nicholas@2864 484 });
nicholas@2886 485 $s.selectedScale = scale.name;
nicholas@2864 486 };
nicholas@2886 487 $s.selectedScale = undefined;
nicholas@2886 488
nicholas@2886 489 $s.configure = function () {
nicholas@2886 490 if ($s.selectedTestPrototype === undefined) {
nicholas@2886 491 return;
nicholas@2886 492 }
nicholas@2886 493 if ($s.selectedTestPrototype.checks && $s.selectedTestPrototype.checks.length >= 1) {
nicholas@2886 494 $s.selectedTestPrototype.checks.forEach(function (entry) {
nicholas@2886 495 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 496 if (entry.support == "none") {
nicholas@2886 497 dom.checked = false;
nicholas@2886 498 dom.disabled = true;
nicholas@2886 499 }
nicholas@2886 500 });
nicholas@2886 501 }
nicholas@2886 502 if ($s.selectedTestPrototype.show && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 503 $s.selectedTestPrototype.show.forEach(function (entry) {
nicholas@2886 504 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 505 if (entry.support == "none") {
nicholas@2886 506 dom.checked = false;
nicholas@2886 507 dom.disabled = true;
nicholas@2886 508 }
nicholas@2886 509 });
nicholas@2886 510 }
nicholas@2886 511 if ($s.interface !== specification.interfaces) {
nicholas@2886 512 // Page specific interface nodes
nicholas@2886 513 if ($s.selectedTestPrototype.hasScales !== undefined && ($s.selectedTestPrototype.hasScales == "false" || $s.selectedTestPrototype.hasScales == false)) {
nicholas@2886 514 var elem = $e[0].querySelector("[name=\"scale-selection\"]")
nicholas@2886 515 elem.style.visibility = "hidden";
nicholas@2886 516 elem.style.height = "0px";
nicholas@2886 517 }
nicholas@2886 518 if ($s.selectedTestPrototype.scales && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 519 $s.scales = [];
nicholas@2886 520 $s.selectedTestPrototype.scales.forEach(function (scalename) {
nicholas@2886 521 var obj = $s.testSpecifications.scales.find(function (a) {
nicholas@2886 522 return a.name == scalename;
nicholas@2886 523 });
nicholas@2886 524 $s.scales.push(obj);
nicholas@2886 525 });
nicholas@2886 526 if ($s.selectedTestPrototype.scales.includes($s.selectedScale) == false) {
nicholas@2886 527 $s.clearScales();
nicholas@2886 528 }
nicholas@2886 529 if ($s.scales.length == 1) {
nicholas@2886 530 $s.clearScales();
nicholas@2886 531 $s.useScales($s.scales[0]);
nicholas@2886 532 }
nicholas@2886 533 } else {
nicholas@2886 534 $s.scales = $s.testSpecifications.scales;
nicholas@2886 535 }
nicholas@2886 536 }
nicholas@2886 537 };
nicholas@2886 538
nicholas@2886 539 $s.$watch("selectedTestPrototype", $s.configure);
nicholas@2886 540 $s.configure();
nicholas@2853 541 }]);
nicholas@2859 542 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
n@2907 543 $s.schema = $w.specification.schema.querySelector("element[name=\"page\"]");
n@2909 544 $s.page.label = $s.page.label || "default";
nicholas@2859 545 $s.addInterface = function () {
nicholas@2859 546 $s.page.addInterface();
nicholas@2859 547 };
nicholas@2859 548 $s.removeInterface = function (node) {
nicholas@2859 549 var index = $s.page.interfaces.findIndex(function (a) {
nicholas@2859 550 return a == node;
nicholas@2859 551 });
nicholas@2859 552 if (index === -1) {
nicholas@2859 553 throw ("Invalid node");
nicholas@2859 554 }
nicholas@2859 555 $s.page.interfaces.splice(index, 1);
nicholas@2859 556 };
nicholas@2859 557
nicholas@2859 558 $s.addCommentQuestion = function () {
nicholas@2859 559 $s.page.addCommentQuestion();
nicholas@2859 560 };
nicholas@2859 561 $s.removeCommentQuestion = function (node) {
nicholas@2859 562 var index = $s.page.commentQuestions.findIndex(function (a) {
nicholas@2859 563 return a == node;
nicholas@2859 564 });
nicholas@2859 565 if (index === -1) {
nicholas@2859 566 throw ("Invalid node");
nicholas@2859 567 }
nicholas@2859 568 $s.page.commentQuestions.splice(index, 1);
nicholas@2859 569 };
nicholas@2859 570 $s.addAudioElement = function () {
nicholas@2859 571 $s.page.addAudioElement();
nicholas@2859 572 };
nicholas@3099 573 $s.ondrop = function (filename) {
nicholas@3097 574 var fragment = $s.page.addAudioElement();
nicholas@3097 575 fragment.url = filename;
nicholas@3097 576 };
nicholas@2859 577 $s.removeAudioElement = function (element) {
nicholas@2859 578 var index = $s.page.audioElements.findIndex(function (a) {
nicholas@2859 579 return a == element;
nicholas@2859 580 });
nicholas@2859 581 if (index === -1) {
nicholas@2859 582 throw ("Invalid node");
nicholas@2859 583 }
nicholas@2859 584 $s.page.audioElements.splice(index, 1);
nicholas@2859 585 };
n@2907 586
n@2907 587 $s.placeholder = function (name) {
n@2907 588 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2907 589 var attr = spec.getAttribute("default");
n@2912 590 if (attr === null) {
n@2912 591 return "Not set";
n@2907 592 }
n@2907 593 return attr;
n@2907 594 }
nicholas@2859 595 }]);