annotate test_create/test_core.js @ 3097:c8707694f4e7

#200 Dragging audio onto the page element will add the audio fragment to that page.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 16 Jan 2018 14:33:07 +0000
parents 1593792ae742
children 348d59ab726e
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@3097 60 scope.addAudioElementFromFile(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();
n@2911 75 };
n@2911 76
n@2911 77 function toggleDropdowns() {
nicholas@2884 78 $(function () {
nicholas@2884 79 $('[data-toggle="popover"]').popover();
nicholas@2884 80 });
n@2911 81 }
nicholas@2535 82
nicholas@2861 83 function handleFiles(event) {
nicholas@2861 84 var s = angular.element(event.currentTarget).scope();
nicholas@2861 85 s.handleFiles(event);
nicholas@2861 86 s.$apply();
nicholas@2861 87 }
nicholas@2861 88
nicholas@2851 89 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 90 $s.popupVisible = true;
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.showPopup = function () {
nicholas@2851 115 $s.popupVisible = true;
nicholas@2851 116 };
nicholas@2851 117 $s.hidePopup = function () {
nicholas@2851 118 $s.popupVisible = false;
nicholas@2851 119 };
nicholas@2851 120 $s.globalSchema = undefined;
nicholas@2851 121 get("xml/test-schema.xsd").then(function (text) {
nicholas@2851 122 specification.processSchema(text);
nicholas@2851 123 $s.globalSchema = specification.getSchema();
nicholas@2851 124 });
n@2912 125 $s.availableInterfaceModules = [];
n@2912 126 get("interfaces/interfaces.json").then(JSON.parse).then(function (d) {
n@2912 127 $s.availableInterfaceModules = d.interfaces;
n@2912 128 $s.$apply();
n@2912 129 });
nicholas@2851 130 $s.specification = specification;
nicholas@2886 131 $s.selectedTestPrototype = undefined;
nicholas@2886 132 $s.setTestPrototype = function (obj) {
nicholas@2886 133 $s.selectedTestPrototype = obj;
nicholas@2886 134 $w.specification.interface = obj.interface;
nicholas@2886 135 }
nicholas@2857 136
nicholas@2857 137 $s.addPage = function () {
nicholas@2857 138 $s.specification.createNewPage();
nicholas@2859 139 };
nicholas@2860 140
nicholas@2862 141 $s.removePage = function (page) {
nicholas@2862 142 var index = $s.specification.pages.findIndex(function (a) {
nicholas@2862 143 return a == page;
nicholas@2862 144 });
nicholas@2862 145 if (index === -1) {
nicholas@2862 146 throw ("Invalid Page");
nicholas@2862 147 }
nicholas@2862 148 $s.specification.pages.splice(index, 1);
nicholas@2862 149 };
nicholas@2862 150
nicholas@2860 151 $s.exportXML = function () {
nicholas@2860 152 var s = new XMLSerializer();
schlien@2961 153 var doc = specification.encode();
nicholas@2891 154 var xmlstr = s.serializeToString(doc);
schlien@2961 155 var bb = new Blob(["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(doc)], {
nicholas@2860 156 type: 'application/xml'
nicholas@2860 157 });
nicholas@2860 158 var dnlk = window.URL.createObjectURL(bb);
nicholas@2891 159 var a = document.createElement("a");
n@2913 160 document.body.appendChild(a)
nicholas@2891 161 a.href = dnlk;
nicholas@2891 162 a.download = "test.xml";
nicholas@2891 163 a.click();
nicholas@2891 164 window.URL.revokeObjectURL(dnlk);
n@2913 165 document.body.removeChild(a);
nicholas@2861 166 };
nicholas@2887 167 $s.validated = false;
nicholas@2887 168 $s.showValidationMessages = false;
nicholas@2887 169 $s.validate = function () {
nicholas@2887 170 var s = new XMLSerializer();
nicholas@2887 171 var Module = {
nicholas@2959 172 xml: "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(specification.encode()),
nicholas@2887 173 schema: specification.getSchemaString(),
nicholas@2887 174 arguments: ["--noout", "--schema", 'test-schema.xsd', 'document.xml']
nicholas@2887 175 };
nicholas@2887 176 var xmllint = validateXML(Module);
nicholas@2887 177 console.log(xmllint);
nicholas@2887 178 if (xmllint != 'document.xml validates\n') {
nicholas@2887 179 $s.validated = false;
nicholas@2887 180 var list = $e[0].querySelector("#validation-error-list");
nicholas@2887 181 while (list.firstChild) {
nicholas@2887 182 list.removeChild(list.firstChild);
nicholas@2887 183 }
nicholas@2887 184 var errors = xmllint.split('\n');
nicholas@2887 185 errors = errors.slice(0, errors.length - 2);
nicholas@2887 186 errors.forEach(function (str) {
nicholas@2887 187 var li = document.createElement("li");
nicholas@2887 188 li.textContent = str;
nicholas@2887 189 list.appendChild(li);
nicholas@2887 190 });
nicholas@2887 191 } else {
nicholas@2887 192 $s.validated = true;
nicholas@2887 193 }
nicholas@2887 194 $s.showValidationMessages = true;
nicholas@2887 195 }
nicholas@2887 196 $s.hideValidationMessages = function () {
nicholas@2887 197 $s.showValidationMessages = false;
nicholas@2887 198 }
n@2911 199 $s.$watch(function () {
n@2911 200 return document.querySelectorAll("div.pageNode").length;
n@2911 201 }, $w.toggleDropdowns);
n@2911 202 $s.$watch(function () {
n@2911 203 return document.querySelectorAll("div.surveyentry").length;
n@2911 204 }, $w.toggleDropdowns);
n@2911 205 $s.$watch(function () {
n@2911 206 return document.querySelectorAll("div.interface").length;
n@2911 207 }, $w.toggleDropdowns);
n@2911 208 $s.$watch(function () {
n@2911 209 return document.querySelectorAll("div.audioelement").length;
n@2911 210 }, $w.toggleDropdowns);
nicholas@2851 211 }]);
nickjillings@1370 212
nicholas@2851 213 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 214 $s.state = 0;
n@2908 215 $s.selected = undefined;
nicholas@2851 216 $s.next = function () {
nicholas@2851 217 $s.state++;
nicholas@2861 218 if ($s.state > 1 || $s.file) {
nicholas@2851 219 $s.hidePopup();
n@2908 220 $s.initialise($s.selected);
nicholas@2851 221 }
nicholas@2851 222 };
nicholas@2851 223 $s.back = function () {
nicholas@2851 224 $s.state--;
nicholas@2851 225 };
nicholas@2851 226 $s.mouseover = function (name) {
nicholas@2864 227 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 228 return i.name == name;
nicholas@2851 229 });
nicholas@2851 230 if (obj) {
nicholas@2851 231 $s.description = obj.description.en;
nicholas@2851 232 }
nicholas@2851 233 };
nicholas@2851 234 $s.initialise = function (name) {
nicholas@2885 235 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 236 return i.name == name;
nicholas@2851 237 });
nicholas@2886 238 if (obj === undefined) {
nicholas@2886 239 throw ("Cannot find specification");
nicholas@2886 240 }
n@2908 241 if (typeof obj.template === "string") {
n@2908 242 get(obj.template).then(function (data) {
n@2908 243 $s.parseFile(data);
n@2908 244 }, function (err) {})
n@2908 245 } else {
n@2908 246 $s.setTestPrototype(obj);
n@2908 247 }
nicholas@2851 248 };
n@2908 249 $s.select = function (name) {
nicholas@3097 250 $s.selected = name;
nicholas@3097 251 }
nicholas@3097 252 // Get the test interface specifications
nicholas@2861 253 $s.file = undefined;
nicholas@2851 254 $s.description = "";
nicholas@2861 255
n@2908 256 $s.parseFile = function (f) {
n@2908 257 var p = new DOMParser();
n@2908 258 specification.decode(p.parseFromString(f, "text/xml"));
n@2908 259 $s.$apply();
n@2908 260 }
n@2908 261
nicholas@2861 262 $s.handleFiles = function ($event) {
nicholas@2861 263 $s.file = $event.currentTarget.files[0];
nicholas@2861 264 var r = new FileReader();
nicholas@2861 265 r.onload = function () {
n@2908 266 $s.parseFile(r.result);
nicholas@2862 267 };
nicholas@2861 268 r.readAsText($s.file);
nicholas@2861 269 };
nicholas@2851 270 }]);
nickjillings@1370 271
nicholas@2851 272 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 273 function initialise() {
nicholas@2851 274 if ($s.globalSchema) {
nicholas@2851 275 $s.schema = $s.globalSchema.querySelector("[name=setup]");
nickjillings@1385 276 }
nickjillings@1370 277 }
nicholas@2851 278 $s.schema = undefined;
nicholas@2851 279 $s.attributes = [];
nickjillings@1370 280
nicholas@2851 281 $s.$watch("globalSchema", initialise);
nicholas@2853 282 $s.$watch("specification.metrics.enabled.length", function () {
nicholas@2853 283 var metricsNode = document.getElementById("metricsNode");
nicholas@2853 284 if (!$s.specification.metrics) {
nicholas@2853 285 return;
nicholas@2853 286 }
nicholas@2853 287 metricsNode.querySelectorAll("input").forEach(function (DOM) {
nicholas@2853 288 DOM.checked = false;
nicholas@2853 289 });
nicholas@2853 290 $s.specification.metrics.enabled.forEach(function (metric) {
nicholas@2853 291 var DOM = metricsNode.querySelector("[value=" + metric + "]");
nicholas@2853 292 if (DOM) {
nicholas@2853 293 DOM.checked = true;
nicholas@2853 294 }
nicholas@2853 295 });
nicholas@2855 296 });
nicholas@2853 297
nicholas@2853 298 $s.enableMetric = function ($event) {
nicholas@2853 299 var metric = $event.currentTarget.value;
nicholas@2853 300 var index = specification.metrics.enabled.findIndex(function (a) {
nicholas@2853 301 return a == metric;
nicholas@2853 302 });
nicholas@2853 303 if ($event.currentTarget.checked) {
nicholas@2853 304 if (index == -1) {
nicholas@2853 305 specification.metrics.enabled.push(metric);
nicholas@2853 306 }
nicholas@2853 307 } else {
nicholas@2853 308 if (index >= 0) {
nicholas@2853 309 specification.metrics.enabled.splice(index, 1);
nicholas@2853 310 }
nicholas@2853 311 }
nicholas@2855 312 };
nicholas@2886 313
nicholas@2886 314 $s.configure = function () {}
nicholas@2886 315
nicholas@2886 316 $s.$watch("selectedTestPrototype", $s.configure);
n@2907 317
n@2907 318 $s.placeholder = function (name) {
n@2908 319 if ($s.schema) {
n@2908 320 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2908 321 var attr = spec.getAttribute("default");
n@2912 322 if (attr === null) {
n@2912 323 return "Not set";
n@2908 324 }
n@2908 325 return attr;
n@2907 326 }
n@2907 327 }
nicholas@2851 328 }]);
nicholas@2853 329
nicholas@2858 330 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2858 331 $s.addSurveyEntry = function () {
nicholas@2858 332 $s.survey.addOption();
nicholas@2858 333 };
nicholas@2858 334 $s.removeSurveyEntry = function (entry) {
nicholas@2858 335 var index = $s.survey.options.findIndex(function (a) {
nicholas@2858 336 return a == entry;
nicholas@2858 337 });
nicholas@2858 338 if (index === -1) {
nicholas@2858 339 throw ("Invalid Entry");
nicholas@2858 340 }
nicholas@2858 341 $s.survey.options.splice(index, 1);
nicholas@2858 342 };
nicholas@2858 343 }]);
nicholas@2858 344
nicholas@2853 345 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2853 346
nicholas@2853 347 $s.removeOption = function (option) {
nicholas@2853 348 var index = $s.opt.options.findIndex(function (a) {
nicholas@2853 349 return a == option;
nicholas@2853 350 });
nicholas@2853 351 if (index === -1) {
nicholas@2853 352 throw ("Invalid option");
nicholas@2853 353 }
nicholas@2853 354 $s.opt.options.splice(index, 1);
nicholas@2853 355 };
nicholas@2853 356 $s.addOption = function () {
nicholas@2853 357 $s.opt.options.push({
nicholas@2853 358 name: "",
nicholas@2853 359 text: ""
nicholas@2853 360 });
nicholas@2855 361 };
nicholas@2857 362
nicholas@2857 363 $s.addCondition = function () {
nicholas@2857 364 $s.opt.conditions.push({
nicholas@2857 365 check: "equals",
nicholas@2857 366 value: "",
nicholas@2857 367 jumpToOnPass: undefined,
nicholas@2857 368 jumpToOnFail: undefined
nicholas@2857 369 });
nicholas@2857 370 };
nicholas@2857 371
nicholas@2857 372 $s.removeCondition = function (condition) {
nicholas@2857 373 var index = $s.opt.conditions.findIndex(function (c) {
nicholas@2857 374 return c == condition;
nicholas@2857 375 });
nicholas@2857 376 if (index === -1) {
nicholas@2857 377 throw ("Invalid Condition");
nicholas@2857 378 }
nicholas@2857 379 $s.opt.conditions.splice(index, 1);
nicholas@2857 380 };
nicholas@2855 381 }]);
nicholas@2855 382
nicholas@2855 383 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2855 384 $s.$watch("interface.options.length", function () {
nicholas@2855 385 if (!$s.interface || !$s.interface.options) {
nicholas@2855 386 return;
nicholas@2855 387 }
nicholas@2855 388 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
nicholas@2855 389 options.forEach(function (option) {
nicholas@2855 390 var name = option.getAttribute("name");
nicholas@2855 391 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 392 return io.name == name;
nicholas@2855 393 });
nicholas@2855 394 option.querySelector("input").checked = (index >= 0);
nicholas@2855 395 if (name == "scalerange" && index >= 0) {
nicholas@2855 396 option.querySelector("[name=min]").value = $s.interface.options[index].min;
nicholas@2855 397 option.querySelector("[name=max]").value = $s.interface.options[index].max;
nicholas@2855 398 }
nicholas@2855 399 });
nicholas@2855 400 });
nicholas@2855 401 $s.enableInterfaceOption = function ($event) {
nicholas@2855 402 var name = $event.currentTarget.parentElement.getAttribute("name");
nicholas@2855 403 var type = $event.currentTarget.parentElement.getAttribute("type");
nicholas@2855 404 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 405 return io.name == name;
nicholas@2855 406 });
nicholas@2855 407 if (index == -1 && $event.currentTarget.checked) {
nicholas@2855 408 var obj = $s.interface.options.push({
nicholas@2855 409 name: name,
nicholas@2855 410 type: type
nicholas@2855 411 });
nicholas@2855 412 if (name == "scalerange") {
nicholas@2855 413 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
nicholas@2855 414 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
nicholas@2855 415 }
nicholas@2855 416 } else if (index >= 0 && !$event.currentTarget.checked) {
nicholas@2855 417 $s.interface.options.splice(index, 1);
nicholas@2855 418 }
nicholas@2857 419 };
nicholas@2886 420 $s.scales = [];
nicholas@2857 421 $s.removeScale = function (scale) {
nicholas@2857 422 var index = $s.interface.scales.findIndex(function (s) {
nicholas@2857 423 return s == scale;
nicholas@2857 424 });
nicholas@2857 425 if (index >= 0) {
nicholas@2857 426 $s.interface.scales.splice(index, 1);
nicholas@2857 427 }
nicholas@2857 428 };
nicholas@2857 429 $s.addScale = function () {
nicholas@2857 430 $s.interface.scales.push({
nicholas@2857 431 position: undefined,
nicholas@2857 432 text: undefined
nicholas@2857 433 });
nicholas@2857 434 };
nicholas@2864 435 $s.clearScales = function () {
nicholas@2864 436 $s.interface.scales = [];
nicholas@2864 437 };
nicholas@2876 438 $s.useScales = function (scale) {
nicholas@2864 439 $s.clearScales();
nicholas@2876 440 scale.scales.forEach(function (s) {
nicholas@2864 441 $s.interface.scales.push(s);
nicholas@2864 442 });
nicholas@2886 443 $s.selectedScale = scale.name;
nicholas@2864 444 };
nicholas@2886 445 $s.selectedScale = undefined;
nicholas@2886 446
nicholas@2886 447 $s.configure = function () {
nicholas@2886 448 if ($s.selectedTestPrototype === undefined) {
nicholas@2886 449 return;
nicholas@2886 450 }
nicholas@2886 451 if ($s.selectedTestPrototype.checks && $s.selectedTestPrototype.checks.length >= 1) {
nicholas@2886 452 $s.selectedTestPrototype.checks.forEach(function (entry) {
nicholas@2886 453 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 454 if (entry.support == "none") {
nicholas@2886 455 dom.checked = false;
nicholas@2886 456 dom.disabled = true;
nicholas@2886 457 }
nicholas@2886 458 });
nicholas@2886 459 }
nicholas@2886 460 if ($s.selectedTestPrototype.show && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 461 $s.selectedTestPrototype.show.forEach(function (entry) {
nicholas@2886 462 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 463 if (entry.support == "none") {
nicholas@2886 464 dom.checked = false;
nicholas@2886 465 dom.disabled = true;
nicholas@2886 466 }
nicholas@2886 467 });
nicholas@2886 468 }
nicholas@2886 469 if ($s.interface !== specification.interfaces) {
nicholas@2886 470 // Page specific interface nodes
nicholas@2886 471 if ($s.selectedTestPrototype.hasScales !== undefined && ($s.selectedTestPrototype.hasScales == "false" || $s.selectedTestPrototype.hasScales == false)) {
nicholas@2886 472 var elem = $e[0].querySelector("[name=\"scale-selection\"]")
nicholas@2886 473 elem.style.visibility = "hidden";
nicholas@2886 474 elem.style.height = "0px";
nicholas@2886 475 }
nicholas@2886 476 if ($s.selectedTestPrototype.scales && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 477 $s.scales = [];
nicholas@2886 478 $s.selectedTestPrototype.scales.forEach(function (scalename) {
nicholas@2886 479 var obj = $s.testSpecifications.scales.find(function (a) {
nicholas@2886 480 return a.name == scalename;
nicholas@2886 481 });
nicholas@2886 482 $s.scales.push(obj);
nicholas@2886 483 });
nicholas@2886 484 if ($s.selectedTestPrototype.scales.includes($s.selectedScale) == false) {
nicholas@2886 485 $s.clearScales();
nicholas@2886 486 }
nicholas@2886 487 if ($s.scales.length == 1) {
nicholas@2886 488 $s.clearScales();
nicholas@2886 489 $s.useScales($s.scales[0]);
nicholas@2886 490 }
nicholas@2886 491 } else {
nicholas@2886 492 $s.scales = $s.testSpecifications.scales;
nicholas@2886 493 }
nicholas@2886 494 }
nicholas@2886 495 };
nicholas@2886 496
nicholas@2886 497 $s.$watch("selectedTestPrototype", $s.configure);
nicholas@2886 498 $s.configure();
nicholas@2853 499 }]);
nicholas@2859 500 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
n@2907 501 $s.schema = $w.specification.schema.querySelector("element[name=\"page\"]");
n@2909 502 $s.page.label = $s.page.label || "default";
nicholas@2859 503 $s.addInterface = function () {
nicholas@2859 504 $s.page.addInterface();
nicholas@2859 505 };
nicholas@2859 506 $s.removeInterface = function (node) {
nicholas@2859 507 var index = $s.page.interfaces.findIndex(function (a) {
nicholas@2859 508 return a == node;
nicholas@2859 509 });
nicholas@2859 510 if (index === -1) {
nicholas@2859 511 throw ("Invalid node");
nicholas@2859 512 }
nicholas@2859 513 $s.page.interfaces.splice(index, 1);
nicholas@2859 514 };
nicholas@2859 515
nicholas@2859 516 $s.addCommentQuestion = function () {
nicholas@2859 517 $s.page.addCommentQuestion();
nicholas@2859 518 };
nicholas@2859 519 $s.removeCommentQuestion = function (node) {
nicholas@2859 520 var index = $s.page.commentQuestions.findIndex(function (a) {
nicholas@2859 521 return a == node;
nicholas@2859 522 });
nicholas@2859 523 if (index === -1) {
nicholas@2859 524 throw ("Invalid node");
nicholas@2859 525 }
nicholas@2859 526 $s.page.commentQuestions.splice(index, 1);
nicholas@2859 527 };
nicholas@2859 528 $s.addAudioElement = function () {
nicholas@2859 529 $s.page.addAudioElement();
nicholas@2859 530 };
nicholas@3097 531 $s.addAudioElementFromFile = function (filename) {
nicholas@3097 532 var fragment = $s.page.addAudioElement();
nicholas@3097 533 fragment.url = filename;
nicholas@3097 534 };
nicholas@2859 535 $s.removeAudioElement = function (element) {
nicholas@2859 536 var index = $s.page.audioElements.findIndex(function (a) {
nicholas@2859 537 return a == element;
nicholas@2859 538 });
nicholas@2859 539 if (index === -1) {
nicholas@2859 540 throw ("Invalid node");
nicholas@2859 541 }
nicholas@2859 542 $s.page.audioElements.splice(index, 1);
nicholas@2859 543 };
n@2907 544
n@2907 545 $s.placeholder = function (name) {
n@2907 546 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2907 547 var attr = spec.getAttribute("default");
n@2912 548 if (attr === null) {
n@2912 549 return "Not set";
n@2907 550 }
n@2907 551 return attr;
n@2907 552 }
nicholas@2859 553 }]);