annotate test_create/test_core.js @ 3098:348d59ab726e

Test creator uses Bootstrap modals
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 16 Jan 2018 15:23:45 +0000
parents c8707694f4e7
children fc9718756d55
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();
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@2851 210 $s.next = function () {
nicholas@2851 211 $s.state++;
nicholas@2861 212 if ($s.state > 1 || $s.file) {
nicholas@3098 213 $($e[0]).modal('hide')
n@2908 214 $s.initialise($s.selected);
nicholas@2851 215 }
nicholas@2851 216 };
nicholas@2851 217 $s.back = function () {
nicholas@2851 218 $s.state--;
nicholas@2851 219 };
nicholas@2851 220 $s.mouseover = function (name) {
nicholas@2864 221 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 222 return i.name == name;
nicholas@2851 223 });
nicholas@2851 224 if (obj) {
nicholas@2851 225 $s.description = obj.description.en;
nicholas@2851 226 }
nicholas@2851 227 };
nicholas@2851 228 $s.initialise = function (name) {
nicholas@2885 229 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 230 return i.name == name;
nicholas@2851 231 });
nicholas@2886 232 if (obj === undefined) {
nicholas@2886 233 throw ("Cannot find specification");
nicholas@2886 234 }
n@2908 235 if (typeof obj.template === "string") {
n@2908 236 get(obj.template).then(function (data) {
n@2908 237 $s.parseFile(data);
n@2908 238 }, function (err) {})
n@2908 239 } else {
n@2908 240 $s.setTestPrototype(obj);
n@2908 241 }
nicholas@2851 242 };
n@2908 243 $s.select = function (name) {
nicholas@3097 244 $s.selected = name;
nicholas@3097 245 }
nicholas@3097 246 // Get the test interface specifications
nicholas@2861 247 $s.file = undefined;
nicholas@2851 248 $s.description = "";
nicholas@2861 249
n@2908 250 $s.parseFile = function (f) {
n@2908 251 var p = new DOMParser();
n@2908 252 specification.decode(p.parseFromString(f, "text/xml"));
n@2908 253 $s.$apply();
n@2908 254 }
n@2908 255
nicholas@2861 256 $s.handleFiles = function ($event) {
nicholas@2861 257 $s.file = $event.currentTarget.files[0];
nicholas@2861 258 var r = new FileReader();
nicholas@2861 259 r.onload = function () {
n@2908 260 $s.parseFile(r.result);
nicholas@2862 261 };
nicholas@2861 262 r.readAsText($s.file);
nicholas@2861 263 };
nicholas@2851 264 }]);
nickjillings@1370 265
nicholas@2851 266 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 267 function initialise() {
nicholas@2851 268 if ($s.globalSchema) {
nicholas@2851 269 $s.schema = $s.globalSchema.querySelector("[name=setup]");
nickjillings@1385 270 }
nickjillings@1370 271 }
nicholas@2851 272 $s.schema = undefined;
nicholas@2851 273 $s.attributes = [];
nickjillings@1370 274
nicholas@2851 275 $s.$watch("globalSchema", initialise);
nicholas@2853 276 $s.$watch("specification.metrics.enabled.length", function () {
nicholas@2853 277 var metricsNode = document.getElementById("metricsNode");
nicholas@2853 278 if (!$s.specification.metrics) {
nicholas@2853 279 return;
nicholas@2853 280 }
nicholas@2853 281 metricsNode.querySelectorAll("input").forEach(function (DOM) {
nicholas@2853 282 DOM.checked = false;
nicholas@2853 283 });
nicholas@2853 284 $s.specification.metrics.enabled.forEach(function (metric) {
nicholas@2853 285 var DOM = metricsNode.querySelector("[value=" + metric + "]");
nicholas@2853 286 if (DOM) {
nicholas@2853 287 DOM.checked = true;
nicholas@2853 288 }
nicholas@2853 289 });
nicholas@2855 290 });
nicholas@2853 291
nicholas@2853 292 $s.enableMetric = function ($event) {
nicholas@2853 293 var metric = $event.currentTarget.value;
nicholas@2853 294 var index = specification.metrics.enabled.findIndex(function (a) {
nicholas@2853 295 return a == metric;
nicholas@2853 296 });
nicholas@2853 297 if ($event.currentTarget.checked) {
nicholas@2853 298 if (index == -1) {
nicholas@2853 299 specification.metrics.enabled.push(metric);
nicholas@2853 300 }
nicholas@2853 301 } else {
nicholas@2853 302 if (index >= 0) {
nicholas@2853 303 specification.metrics.enabled.splice(index, 1);
nicholas@2853 304 }
nicholas@2853 305 }
nicholas@2855 306 };
nicholas@2886 307
nicholas@2886 308 $s.configure = function () {}
nicholas@2886 309
nicholas@2886 310 $s.$watch("selectedTestPrototype", $s.configure);
n@2907 311
n@2907 312 $s.placeholder = function (name) {
n@2908 313 if ($s.schema) {
n@2908 314 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2908 315 var attr = spec.getAttribute("default");
n@2912 316 if (attr === null) {
n@2912 317 return "Not set";
n@2908 318 }
n@2908 319 return attr;
n@2907 320 }
n@2907 321 }
nicholas@2851 322 }]);
nicholas@2853 323
nicholas@2858 324 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2858 325 $s.addSurveyEntry = function () {
nicholas@2858 326 $s.survey.addOption();
nicholas@2858 327 };
nicholas@2858 328 $s.removeSurveyEntry = function (entry) {
nicholas@2858 329 var index = $s.survey.options.findIndex(function (a) {
nicholas@2858 330 return a == entry;
nicholas@2858 331 });
nicholas@2858 332 if (index === -1) {
nicholas@2858 333 throw ("Invalid Entry");
nicholas@2858 334 }
nicholas@2858 335 $s.survey.options.splice(index, 1);
nicholas@2858 336 };
nicholas@2858 337 }]);
nicholas@2858 338
nicholas@2853 339 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2853 340
nicholas@2853 341 $s.removeOption = function (option) {
nicholas@2853 342 var index = $s.opt.options.findIndex(function (a) {
nicholas@2853 343 return a == option;
nicholas@2853 344 });
nicholas@2853 345 if (index === -1) {
nicholas@2853 346 throw ("Invalid option");
nicholas@2853 347 }
nicholas@2853 348 $s.opt.options.splice(index, 1);
nicholas@2853 349 };
nicholas@2853 350 $s.addOption = function () {
nicholas@2853 351 $s.opt.options.push({
nicholas@2853 352 name: "",
nicholas@2853 353 text: ""
nicholas@2853 354 });
nicholas@2855 355 };
nicholas@2857 356
nicholas@2857 357 $s.addCondition = function () {
nicholas@2857 358 $s.opt.conditions.push({
nicholas@2857 359 check: "equals",
nicholas@2857 360 value: "",
nicholas@2857 361 jumpToOnPass: undefined,
nicholas@2857 362 jumpToOnFail: undefined
nicholas@2857 363 });
nicholas@2857 364 };
nicholas@2857 365
nicholas@2857 366 $s.removeCondition = function (condition) {
nicholas@2857 367 var index = $s.opt.conditions.findIndex(function (c) {
nicholas@2857 368 return c == condition;
nicholas@2857 369 });
nicholas@2857 370 if (index === -1) {
nicholas@2857 371 throw ("Invalid Condition");
nicholas@2857 372 }
nicholas@2857 373 $s.opt.conditions.splice(index, 1);
nicholas@2857 374 };
nicholas@2855 375 }]);
nicholas@2855 376
nicholas@2855 377 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2855 378 $s.$watch("interface.options.length", function () {
nicholas@2855 379 if (!$s.interface || !$s.interface.options) {
nicholas@2855 380 return;
nicholas@2855 381 }
nicholas@2855 382 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
nicholas@2855 383 options.forEach(function (option) {
nicholas@2855 384 var name = option.getAttribute("name");
nicholas@2855 385 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 386 return io.name == name;
nicholas@2855 387 });
nicholas@2855 388 option.querySelector("input").checked = (index >= 0);
nicholas@2855 389 if (name == "scalerange" && index >= 0) {
nicholas@2855 390 option.querySelector("[name=min]").value = $s.interface.options[index].min;
nicholas@2855 391 option.querySelector("[name=max]").value = $s.interface.options[index].max;
nicholas@2855 392 }
nicholas@2855 393 });
nicholas@2855 394 });
nicholas@2855 395 $s.enableInterfaceOption = function ($event) {
nicholas@2855 396 var name = $event.currentTarget.parentElement.getAttribute("name");
nicholas@2855 397 var type = $event.currentTarget.parentElement.getAttribute("type");
nicholas@2855 398 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 399 return io.name == name;
nicholas@2855 400 });
nicholas@2855 401 if (index == -1 && $event.currentTarget.checked) {
nicholas@2855 402 var obj = $s.interface.options.push({
nicholas@2855 403 name: name,
nicholas@2855 404 type: type
nicholas@2855 405 });
nicholas@2855 406 if (name == "scalerange") {
nicholas@2855 407 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
nicholas@2855 408 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
nicholas@2855 409 }
nicholas@2855 410 } else if (index >= 0 && !$event.currentTarget.checked) {
nicholas@2855 411 $s.interface.options.splice(index, 1);
nicholas@2855 412 }
nicholas@2857 413 };
nicholas@2886 414 $s.scales = [];
nicholas@2857 415 $s.removeScale = function (scale) {
nicholas@2857 416 var index = $s.interface.scales.findIndex(function (s) {
nicholas@2857 417 return s == scale;
nicholas@2857 418 });
nicholas@2857 419 if (index >= 0) {
nicholas@2857 420 $s.interface.scales.splice(index, 1);
nicholas@2857 421 }
nicholas@2857 422 };
nicholas@2857 423 $s.addScale = function () {
nicholas@2857 424 $s.interface.scales.push({
nicholas@2857 425 position: undefined,
nicholas@2857 426 text: undefined
nicholas@2857 427 });
nicholas@2857 428 };
nicholas@2864 429 $s.clearScales = function () {
nicholas@2864 430 $s.interface.scales = [];
nicholas@2864 431 };
nicholas@2876 432 $s.useScales = function (scale) {
nicholas@2864 433 $s.clearScales();
nicholas@2876 434 scale.scales.forEach(function (s) {
nicholas@2864 435 $s.interface.scales.push(s);
nicholas@2864 436 });
nicholas@2886 437 $s.selectedScale = scale.name;
nicholas@2864 438 };
nicholas@2886 439 $s.selectedScale = undefined;
nicholas@2886 440
nicholas@2886 441 $s.configure = function () {
nicholas@2886 442 if ($s.selectedTestPrototype === undefined) {
nicholas@2886 443 return;
nicholas@2886 444 }
nicholas@2886 445 if ($s.selectedTestPrototype.checks && $s.selectedTestPrototype.checks.length >= 1) {
nicholas@2886 446 $s.selectedTestPrototype.checks.forEach(function (entry) {
nicholas@2886 447 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 448 if (entry.support == "none") {
nicholas@2886 449 dom.checked = false;
nicholas@2886 450 dom.disabled = true;
nicholas@2886 451 }
nicholas@2886 452 });
nicholas@2886 453 }
nicholas@2886 454 if ($s.selectedTestPrototype.show && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 455 $s.selectedTestPrototype.show.forEach(function (entry) {
nicholas@2886 456 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 457 if (entry.support == "none") {
nicholas@2886 458 dom.checked = false;
nicholas@2886 459 dom.disabled = true;
nicholas@2886 460 }
nicholas@2886 461 });
nicholas@2886 462 }
nicholas@2886 463 if ($s.interface !== specification.interfaces) {
nicholas@2886 464 // Page specific interface nodes
nicholas@2886 465 if ($s.selectedTestPrototype.hasScales !== undefined && ($s.selectedTestPrototype.hasScales == "false" || $s.selectedTestPrototype.hasScales == false)) {
nicholas@2886 466 var elem = $e[0].querySelector("[name=\"scale-selection\"]")
nicholas@2886 467 elem.style.visibility = "hidden";
nicholas@2886 468 elem.style.height = "0px";
nicholas@2886 469 }
nicholas@2886 470 if ($s.selectedTestPrototype.scales && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 471 $s.scales = [];
nicholas@2886 472 $s.selectedTestPrototype.scales.forEach(function (scalename) {
nicholas@2886 473 var obj = $s.testSpecifications.scales.find(function (a) {
nicholas@2886 474 return a.name == scalename;
nicholas@2886 475 });
nicholas@2886 476 $s.scales.push(obj);
nicholas@2886 477 });
nicholas@2886 478 if ($s.selectedTestPrototype.scales.includes($s.selectedScale) == false) {
nicholas@2886 479 $s.clearScales();
nicholas@2886 480 }
nicholas@2886 481 if ($s.scales.length == 1) {
nicholas@2886 482 $s.clearScales();
nicholas@2886 483 $s.useScales($s.scales[0]);
nicholas@2886 484 }
nicholas@2886 485 } else {
nicholas@2886 486 $s.scales = $s.testSpecifications.scales;
nicholas@2886 487 }
nicholas@2886 488 }
nicholas@2886 489 };
nicholas@2886 490
nicholas@2886 491 $s.$watch("selectedTestPrototype", $s.configure);
nicholas@2886 492 $s.configure();
nicholas@2853 493 }]);
nicholas@2859 494 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
n@2907 495 $s.schema = $w.specification.schema.querySelector("element[name=\"page\"]");
n@2909 496 $s.page.label = $s.page.label || "default";
nicholas@2859 497 $s.addInterface = function () {
nicholas@2859 498 $s.page.addInterface();
nicholas@2859 499 };
nicholas@2859 500 $s.removeInterface = function (node) {
nicholas@2859 501 var index = $s.page.interfaces.findIndex(function (a) {
nicholas@2859 502 return a == node;
nicholas@2859 503 });
nicholas@2859 504 if (index === -1) {
nicholas@2859 505 throw ("Invalid node");
nicholas@2859 506 }
nicholas@2859 507 $s.page.interfaces.splice(index, 1);
nicholas@2859 508 };
nicholas@2859 509
nicholas@2859 510 $s.addCommentQuestion = function () {
nicholas@2859 511 $s.page.addCommentQuestion();
nicholas@2859 512 };
nicholas@2859 513 $s.removeCommentQuestion = function (node) {
nicholas@2859 514 var index = $s.page.commentQuestions.findIndex(function (a) {
nicholas@2859 515 return a == node;
nicholas@2859 516 });
nicholas@2859 517 if (index === -1) {
nicholas@2859 518 throw ("Invalid node");
nicholas@2859 519 }
nicholas@2859 520 $s.page.commentQuestions.splice(index, 1);
nicholas@2859 521 };
nicholas@2859 522 $s.addAudioElement = function () {
nicholas@2859 523 $s.page.addAudioElement();
nicholas@2859 524 };
nicholas@3097 525 $s.addAudioElementFromFile = function (filename) {
nicholas@3097 526 var fragment = $s.page.addAudioElement();
nicholas@3097 527 fragment.url = filename;
nicholas@3097 528 };
nicholas@2859 529 $s.removeAudioElement = function (element) {
nicholas@2859 530 var index = $s.page.audioElements.findIndex(function (a) {
nicholas@2859 531 return a == element;
nicholas@2859 532 });
nicholas@2859 533 if (index === -1) {
nicholas@2859 534 throw ("Invalid node");
nicholas@2859 535 }
nicholas@2859 536 $s.page.audioElements.splice(index, 1);
nicholas@2859 537 };
n@2907 538
n@2907 539 $s.placeholder = function (name) {
n@2907 540 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2907 541 var attr = spec.getAttribute("default");
n@2912 542 if (attr === null) {
n@2912 543 return "Not set";
n@2907 544 }
n@2907 545 return attr;
n@2907 546 }
nicholas@2859 547 }]);