annotate test_create/test_core.js @ 2549:c5fd47349a4f

#107. Added axis-name setting in test_create
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 14 Nov 2016 20:34:58 +0000
parents 527020a63203
children 13a0b65143a6
rev   line source
nickjillings@1370 1 var interfaceSpecs;
nickjillings@1370 2 var xmlHttp;
nickjillings@1370 3 var popupObject;
nickjillings@1370 4 var popupStateNodes;
nickjillings@1370 5 var specification;
nickjillings@1370 6 var convert;
nickjillings@1370 7 var attributeText;
nicholas@2355 8 var page_lang = "en";
nickjillings@1370 9
nickjillings@1370 10 // Firefox does not have an XMLDocument.prototype.getElementsByName
nickjillings@1370 11 // and there is no searchAll style command, this custom function will
nickjillings@1370 12 // search all children recusrively for the name. Used for XSD where all
nickjillings@1370 13 // element nodes must have a name and therefore can pull the schema node
nicholas@2535 14 XMLDocument.prototype.getAllElementsByName = function (name) {
nickjillings@1370 15 name = String(name);
nickjillings@1370 16 var selected = this.documentElement.getAllElementsByName(name);
nickjillings@1370 17 return selected;
nickjillings@1370 18 }
nickjillings@1370 19
nicholas@2535 20 Element.prototype.getAllElementsByName = function (name) {
nickjillings@1370 21 name = String(name);
nickjillings@1370 22 var selected = [];
nickjillings@1370 23 var node = this.firstElementChild;
nicholas@2535 24 while (node != null) {
nicholas@2535 25 if (node.getAttribute('name') == name) {
nickjillings@1370 26 selected.push(node);
nickjillings@1370 27 }
nicholas@2535 28 if (node.childElementCount > 0) {
nickjillings@1370 29 selected = selected.concat(node.getAllElementsByName(name));
nickjillings@1370 30 }
nickjillings@1370 31 node = node.nextElementSibling;
nickjillings@1370 32 }
nickjillings@1370 33 return selected;
nickjillings@1370 34 }
nickjillings@1370 35
nicholas@2535 36 XMLDocument.prototype.getAllElementsByTagName = function (name) {
nickjillings@1370 37 name = String(name);
nickjillings@1370 38 var selected = this.documentElement.getAllElementsByTagName(name);
nickjillings@1370 39 return selected;
nickjillings@1370 40 }
nickjillings@1370 41
nicholas@2535 42 Element.prototype.getAllElementsByTagName = function (name) {
nickjillings@1370 43 name = String(name);
nickjillings@1370 44 var selected = [];
nickjillings@1370 45 var node = this.firstElementChild;
nicholas@2535 46 while (node != null) {
nicholas@2535 47 if (node.nodeName == name) {
nickjillings@1370 48 selected.push(node);
nickjillings@1370 49 }
nicholas@2535 50 if (node.childElementCount > 0) {
nickjillings@1370 51 selected = selected.concat(node.getAllElementsByTagName(name));
nickjillings@1370 52 }
nickjillings@1370 53 node = node.nextElementSibling;
nickjillings@1370 54 }
nickjillings@1370 55 return selected;
nickjillings@1370 56 }
nickjillings@1370 57
nickjillings@1370 58 // Firefox does not have an XMLDocument.prototype.getElementsByName
nickjillings@1370 59 if (typeof XMLDocument.prototype.getElementsByName != "function") {
nicholas@2535 60 XMLDocument.prototype.getElementsByName = function (name) {
nickjillings@1370 61 name = String(name);
nickjillings@1370 62 var node = this.documentElement.firstElementChild;
nickjillings@1370 63 var selected = [];
nicholas@2535 64 while (node != null) {
nicholas@2535 65 if (node.getAttribute('name') == name) {
nickjillings@1370 66 selected.push(node);
nickjillings@1370 67 }
nickjillings@1370 68 node = node.nextElementSibling;
nickjillings@1370 69 }
nickjillings@1370 70 return selected;
nickjillings@1370 71 }
nickjillings@1370 72 }
nickjillings@1370 73
nicholas@2535 74 window.onload = function () {
nickjillings@1370 75 specification = new Specification();
nickjillings@1370 76 convert = new SpecificationToHTML();
nickjillings@1370 77 xmlHttp = new XMLHttpRequest();
nicholas@2535 78 xmlHttp.open("GET", "test_create/interface-specs.xml", true);
nicholas@2535 79 xmlHttp.onload = function () {
nickjillings@1370 80 var parse = new DOMParser();
nicholas@2535 81 interfaceSpecs = parse.parseFromString(xmlHttp.response, 'text/xml');
nickjillings@1370 82 buildPage();
nickjillings@1370 83 popupObject.postNode(popupStateNodes.state[0])
nickjillings@1370 84 }
nickjillings@1370 85 xmlHttp.send();
nicholas@2535 86
nickjillings@1370 87 var xsdGet = new XMLHttpRequest();
nicholas@2535 88 xsdGet.open("GET", "xml/test-schema.xsd", true);
nicholas@2535 89 xsdGet.onload = function () {
nickjillings@1370 90 var parse = new DOMParser();
nicholas@2535 91 specification.schema = parse.parseFromString(xsdGet.response, 'text/xml');;
nickjillings@1370 92 }
nickjillings@1370 93 xsdGet.send();
nicholas@2535 94
nickjillings@1370 95 var jsonAttribute = new XMLHttpRequest();
nicholas@2535 96 jsonAttribute.open("GET", "test_create/attributes.json", true);
nicholas@2535 97 jsonAttribute.onload = function () {
nickjillings@1370 98 attributeText = JSON.parse(jsonAttribute.response)
nickjillings@1370 99 }
nickjillings@1370 100 jsonAttribute.send();
nickjillings@1370 101 }
nickjillings@1370 102
nicholas@2535 103 function buildPage() {
nicholas@2535 104 popupObject = new function () {
nickjillings@1370 105 this.object = document.getElementById("popupHolder");
nickjillings@1370 106 this.blanket = document.getElementById("blanket");
nickjillings@1370 107
nickjillings@1370 108 this.popupTitle = document.createElement("div");
nickjillings@1370 109 this.popupTitle.id = "popup-title-holder";
nickjillings@1370 110 this.popupTitle.align = "center";
nickjillings@1370 111 this.titleDOM = document.createElement("span");
nickjillings@1370 112 this.titleDOM.id = "popup-title";
nickjillings@1370 113 this.popupTitle.appendChild(this.titleDOM);
nickjillings@1370 114 this.object.appendChild(this.popupTitle);
nickjillings@1370 115
nickjillings@1370 116 this.popupContent = document.createElement("div");
nickjillings@1370 117 this.popupContent.id = "popup-content";
nickjillings@1370 118 this.object.appendChild(this.popupContent);
nicholas@2535 119
nickjillings@1370 120 this.proceedButton = document.createElement("button");
nickjillings@1370 121 this.proceedButton.id = "popup-proceed";
nickjillings@2108 122 this.proceedButton.className = "popup-button";
nickjillings@1370 123 this.proceedButton.textContent = "Next";
nicholas@2535 124 this.proceedButton.onclick = function () {
nickjillings@1370 125 popupObject.popupContent.innerHTML = null;
nicholas@2535 126 if (typeof popupObject.shownObject.continue == "function") {
nickjillings@2110 127 popupObject.shownObject.continue();
nickjillings@2110 128 } else {
nickjillings@2110 129 popupObject.hide();
nickjillings@2110 130 }
nickjillings@1370 131 };
nickjillings@1370 132 this.object.appendChild(this.proceedButton);
nicholas@2535 133
nickjillings@2108 134 this.backButton = document.createElement("button");
nickjillings@2108 135 this.backButton.id = "popup-back";
nickjillings@2108 136 this.backButton.className = "popup-button";
nickjillings@2108 137 this.backButton.textContent = "Back";
nicholas@2535 138 this.backButton.onclick = function () {
nickjillings@2108 139 popupObject.popupContent.innerHTML = null;
nickjillings@2108 140 popupObject.shownObject.back();
nickjillings@2108 141 };
nickjillings@2108 142 this.object.appendChild(this.backButton);
nicholas@2535 143
nickjillings@1370 144 this.shownObject;
nickjillings@1370 145
nicholas@2535 146 this.resize = function () {
nickjillings@1370 147 var w = window.innerWidth;
nickjillings@1370 148 var h = window.innerHeight;
nicholas@2535 149 this.object.style.left = Math.floor((w - 750) / 2) + 'px';
nicholas@2535 150 this.object.style.top = Math.floor((h - 500) / 2) + 'px';
nickjillings@1370 151 }
nickjillings@1370 152
nicholas@2535 153 this.show = function () {
nickjillings@1370 154 this.object.style.visibility = "visible";
nickjillings@1370 155 this.blanket.style.visibility = "visible";
nickjillings@2108 156 if (typeof this.shownObject.back == "function") {
nickjillings@2108 157 this.backButton.style.visibility = "visible";
nickjillings@2108 158 } else {
nickjillings@2108 159 this.backButton.style.visibility = "hidden";
nickjillings@2108 160 }
nickjillings@1370 161 }
nickjillings@1370 162
nicholas@2535 163 this.hide = function () {
nickjillings@1370 164 this.object.style.visibility = "hidden";
nickjillings@1370 165 this.blanket.style.visibility = "hidden";
nickjillings@2108 166 this.backButton.style.visibility = "hidden";
nickjillings@1370 167 }
nickjillings@1370 168
nicholas@2535 169 this.postNode = function (postObject) {
nickjillings@1370 170 //Passed object must have the following:
nickjillings@1370 171 // Title: text to show in the title
nickjillings@1370 172 // Content: HTML DOM to show on the page
nickjillings@1370 173 // On complete this HTML DOM is destroyed so make sure it is referenced elsewhere for processing
nickjillings@1370 174 this.titleDOM.textContent = postObject.title;
nickjillings@1370 175 this.popupContent.appendChild(postObject.content);
nickjillings@1370 176 this.shownObject = postObject;
nickjillings@2108 177 if (typeof this.shownObject.back == "function") {
nickjillings@2108 178 this.backButton.style.visibility = "visible";
nickjillings@2108 179 } else {
nickjillings@2108 180 this.backButton.style.visibility = "hidden";
nickjillings@2108 181 }
nickjillings@2110 182 if (typeof this.shownObject.continue == "function") {
nickjillings@2110 183 this.proceedButton.textContent = "Next";
nickjillings@2110 184 } else {
nickjillings@2110 185 this.proceedButton.textContent = "Finish";
nickjillings@2110 186 }
nickjillings@2108 187 this.show();
nickjillings@1370 188 }
nickjillings@1370 189
nickjillings@1370 190 this.resize();
nickjillings@1370 191 this.hide();
nickjillings@1370 192 };
nicholas@2535 193
nicholas@2535 194 popupStateNodes = new function () {
nickjillings@1370 195 // This defines the several popup states wanted
nickjillings@1370 196 this.state = [];
nicholas@2535 197 this.state[0] = new function () {
nickjillings@1370 198 this.title = "Welcome";
nickjillings@1370 199 this.content = document.createElement("div");
nickjillings@1370 200 this.content.id = "state-0";
nickjillings@1370 201 var span = document.createElement("span");
nickjillings@1370 202 span.textContent = "Welcome to the WAET test creator tool. This will allow you to create a new test from scratch to suit your testing needs. If you wish to update a test file, please drag and drop the XML document into the area below for processing, otherwise press 'Next' to start a new test. This tool generates files for the WAET 1.2.0 version."
nickjillings@1370 203 this.content.appendChild(span);
nickjillings@1370 204 this.dragArea = document.createElement("div");
nickjillings@1373 205 this.dragArea.className = "drag-area";
nickjillings@1373 206 this.dragArea.id = "project-drop";
nickjillings@1370 207 this.content.appendChild(this.dragArea);
nicholas@2535 208
nicholas@2535 209 this.dragArea.addEventListener('dragover', function (e) {
nickjillings@1373 210 e.stopPropagation();
nickjillings@1373 211 e.preventDefault();
nickjillings@1373 212 e.dataTransfer.dropEffect = 'copy';
nickjillings@1373 213 e.currentTarget.className = "drag-area drag-over";
nickjillings@1373 214 });
nicholas@2535 215
nicholas@2535 216 this.dragArea.addEventListener('dragexit', function (e) {
nickjillings@1373 217 e.stopPropagation();
nickjillings@1373 218 e.preventDefault();
nickjillings@1373 219 e.dataTransfer.dropEffect = 'copy';
nickjillings@1373 220 e.currentTarget.className = "drag-area";
nickjillings@1373 221 });
nicholas@2535 222
nicholas@2535 223 this.dragArea.addEventListener('drop', function (e) {
nickjillings@1373 224 e.stopPropagation();
nickjillings@1373 225 e.preventDefault();
nickjillings@1373 226 e.currentTarget.className = "drag-area drag-dropped";
nickjillings@1373 227 var files = e.dataTransfer.files[0];
nickjillings@1374 228 var reader = new FileReader();
nicholas@2535 229 reader.onload = function (decoded) {
nickjillings@1374 230 var parse = new DOMParser();
nicholas@2535 231 specification.decode(parse.parseFromString(decoded.target.result, 'text/xml'));
nickjillings@1374 232 popupObject.hide();
nickjillings@1375 233 popupObject.popupContent.innerHTML = null;
nickjillings@1374 234 convert.convert(document.getElementById('content'));
nickjillings@1374 235 }
nickjillings@1374 236 reader.readAsText(files);
nickjillings@1373 237 });
nickjillings@1370 238
nicholas@2535 239
nicholas@2535 240 this.continue = function () {
nickjillings@1370 241 popupObject.postNode(popupStateNodes.state[1]);
nickjillings@1370 242 }
nickjillings@1370 243 }
nicholas@2535 244 this.state[1] = new function () {
nickjillings@1370 245 this.title = "Select your interface";
nickjillings@1370 246 this.content = document.createElement("div");
nickjillings@1370 247 this.content.id = "state-1";
nickjillings@1370 248 var spnH = document.createElement('div');
nickjillings@1370 249 var span = document.createElement("span");
nickjillings@1370 250 span.textContent = "Please select your interface from the list shown below. This will define the various options which are available. This can later be changed.";
nickjillings@1370 251 spnH.appendChild(span);
nickjillings@1370 252 this.content.appendChild(spnH);
nickjillings@1370 253 this.select = document.createElement("select");
nicholas@2355 254 this.content.appendChild(this.select);
nicholas@2355 255 this.description = document.createElement("p");
nicholas@2355 256 this.content.appendChild(this.description);
nicholas@2390 257 this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].getElementsByTagName('test');
nicholas@2535 258 for (var i = 0; i < this.testsXML.length; i++) {
nickjillings@1370 259 var option = document.createElement('option');
nickjillings@1370 260 option.value = this.testsXML[i].getAttribute('name');
nickjillings@1370 261 option.textContent = this.testsXML[i].getAttribute('name');
nickjillings@1370 262 this.select.appendChild(option);
nickjillings@1370 263 }
nicholas@2535 264 this.handleEvent = function (event) {
nicholas@2355 265 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
nicholas@2355 266 var descriptors = testXML.getAllElementsByTagName("description");
nicholas@2355 267 this.description.textContent = "";
nicholas@2535 268 for (var i = 0; i < descriptors.length; i++) {
nicholas@2355 269 if (descriptors[i].getAttribute("lang") == page_lang) {
nicholas@2355 270 this.description.textContent = descriptors[i].textContent;
nicholas@2355 271 }
nicholas@2355 272 }
nicholas@2355 273 }
nicholas@2535 274 this.select.addEventListener("change", this);
nicholas@2355 275 this.handleEvent();
nicholas@2535 276 this.continue = function () {
nickjillings@1370 277 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
nickjillings@1370 278 specification.interface = testXML.getAttribute("interface");
nicholas@2535 279 if (specification.interfaces == null) {
nickjillings@2194 280 specification.interfaces = new specification.interfaceNode(specification);
nickjillings@2108 281 }
nicholas@2535 282 if (specification.metrics == null) {
nickjillings@2108 283 specification.metrics = new specification.metricNode();
nickjillings@2108 284 }
nickjillings@1370 285 popupStateNodes.state[2].generate();
nickjillings@1370 286 popupObject.postNode(popupStateNodes.state[2]);
nickjillings@1370 287 }
nicholas@2535 288 this.back = function () {
nickjillings@2108 289 popupObject.postNode(popupStateNodes.state[0]);
nickjillings@2108 290 }
nickjillings@1370 291 }
nicholas@2535 292 this.state[2] = new function () {
nickjillings@1370 293 this.title = "Test Checks & Restrictions";
nickjillings@1370 294 this.content = document.createElement("div");
nickjillings@1370 295 this.content.id = "state-1";
nickjillings@1370 296 var spnH = document.createElement('div');
nickjillings@1370 297 var span = document.createElement("span");
nickjillings@1370 298 span.textContent = "Select your test checks and restrictions. Greyed out items are fixed by the test/interface and cannot be changed";
nickjillings@1370 299 spnH.appendChild(span);
nickjillings@1370 300 this.content.appendChild(spnH);
nickjillings@1370 301 var holder = document.createElement("div");
nickjillings@1370 302 this.options = [];
nickjillings@1370 303 this.testXML = null;
nickjillings@1370 304 this.interfaceXML = null;
nickjillings@2108 305 this.dynamicContent = document.createElement("div");
nickjillings@2108 306 this.content.appendChild(this.dynamicContent);
nicholas@2535 307 this.generate = function () {
nickjillings@2108 308 this.options = [];
nickjillings@2108 309 this.dynamicContent.innerHTML = null;
nickjillings@1370 310 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 311 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 312 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 313 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 314 this.testXML = this.testXML.getAllElementsByTagName("checks");
nicholas@2390 315 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 316 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 317 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 318 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 319 var testNode
nicholas@2535 320 if (this.testXML.length > 0) {
nickjillings@1370 321 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 322 if (testNode.length != 0) {
nicholas@2535 323 testNode = testNode[0];
nicholas@2535 324 } else {
nicholas@2535 325 testNode = undefined;
nicholas@2535 326 }
nickjillings@1370 327 } else {
nickjillings@1370 328 testNode = undefined;
nickjillings@1370 329 }
nickjillings@2108 330 var obj = {
nickjillings@2108 331 root: document.createElement("div"),
nickjillings@2109 332 text: document.createElement("label"),
nickjillings@2108 333 input: document.createElement("input"),
nickjillings@2108 334 parent: this,
nickjillings@2108 335 name: checkName,
nicholas@2535 336 handleEvent: function (event) {
nickjillings@2108 337 if (this.input.checked) {
nickjillings@2108 338 // Add to specification.interfaces.option
nicholas@2535 339 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 340 if (element.name == this.name) {
nicholas@2535 341 return true;
nicholas@2535 342 } else {
nicholas@2535 343 return false;
nicholas@2535 344 }
nicholas@2535 345 }, this);
nickjillings@2108 346 if (included == null) {
nicholas@2535 347 specification.interfaces.options.push({
nicholas@2535 348 type: "check",
nicholas@2535 349 name: this.name
nicholas@2535 350 });
nickjillings@2108 351 }
nickjillings@2108 352 } else {
nickjillings@2108 353 // Remove from specification.interfaces.option
nicholas@2535 354 var position = specification.interfaces.options.findIndex(function (element, index, array) {
nicholas@2535 355 if (element.name == this.name) {
nicholas@2535 356 return true;
nicholas@2535 357 } else {
nicholas@2535 358 return false;
nicholas@2535 359 }
nicholas@2535 360 }, this);
nickjillings@2108 361 if (position >= 0) {
nicholas@2535 362 specification.interfaces.options.splice(position, 1);
nickjillings@2108 363 }
nickjillings@2108 364 }
nickjillings@2108 365 }
nickjillings@1370 366 }
nicholas@2535 367
nicholas@2535 368 obj.input.addEventListener("click", obj);
nickjillings@2108 369 obj.root.className = "popup-checkbox";
nickjillings@2108 370 obj.input.type = "checkbox";
nicholas@2535 371 obj.input.setAttribute('id', checkName);
nicholas@2535 372 obj.text.setAttribute("for", checkName);
nickjillings@2108 373 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 374 obj.root.appendChild(obj.input);
nickjillings@2108 375 obj.root.appendChild(obj.text);
nicholas@2535 376 if (testNode != undefined) {
nicholas@2535 377 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 378 obj.input.checked = true;
nickjillings@1370 379 }
nicholas@2535 380 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 381 obj.input.disabled = true;
nickjillings@2108 382 obj.input.checked = false;
nickjillings@2108 383 obj.root.className = "popup-checkbox disabled";
nicholas@2535 384 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 385 obj.input.disabled = true;
nickjillings@2108 386 obj.input.checked = true;
nickjillings@2108 387 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 388 }
nickjillings@2108 389 } else {
nicholas@2535 390 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 391 obj.input.checked = true;
nickjillings@2108 392 }
nicholas@2535 393 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 394 obj.input.disabled = true;
nickjillings@2108 395 obj.input.checked = false;
nickjillings@2108 396 obj.root.className = "popup-checkbox disabled";
nicholas@2535 397 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 398 obj.input.disabled = true;
nickjillings@2108 399 obj.input.checked = true;
nickjillings@2108 400 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 401 }
nickjillings@1370 402 }
nicholas@2535 403 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 404 if (element.name == this.name) {
nicholas@2535 405 return true;
nicholas@2535 406 } else {
nicholas@2535 407 return false;
nicholas@2535 408 }
nicholas@2535 409 }, obj);
nickjillings@2108 410 if (included != undefined) {
nickjillings@2108 411 obj.input.checked = true;
nickjillings@2108 412 }
nickjillings@2108 413 obj.handleEvent();
nickjillings@2108 414 this.options.push(obj);
nickjillings@2108 415 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 416 }
nickjillings@1370 417 }
nicholas@2535 418 this.continue = function () {
nickjillings@1370 419 popupStateNodes.state[3].generate();
nickjillings@1370 420 popupObject.postNode(popupStateNodes.state[3]);
nickjillings@1370 421 }
nicholas@2535 422 this.back = function () {
nickjillings@2108 423 popupObject.postNode(popupStateNodes.state[1]);
nickjillings@2108 424 }
nickjillings@1370 425 }
nicholas@2535 426 this.state[3] = new function () {
nickjillings@1370 427 this.title = "Test Metrics";
nickjillings@1370 428 this.content = document.createElement("div");
nickjillings@1370 429 this.content.id = "state-1";
nickjillings@1370 430 var spnH = document.createElement('div');
nickjillings@1370 431 var span = document.createElement("span");
nickjillings@1370 432 span.textContent = "Select which data points to include in the exported results XML. Some of this is required for certain post script analysis. See the documentation for further details";
nickjillings@1370 433 spnH.appendChild(span);
nickjillings@1370 434 this.content.appendChild(spnH);
nickjillings@1370 435 this.options = [];
nickjillings@1370 436 this.checkText;
nickjillings@1370 437 this.testXML;
nickjillings@1370 438 this.interfaceXML;
nickjillings@2108 439 this.dynamicContent = document.createElement("div");
nickjillings@2108 440 this.content.appendChild(this.dynamicContent);
nicholas@2535 441 this.generate = function () {
nickjillings@2108 442 this.options = [];
nickjillings@2108 443 this.dynamicContent.innerHTML = null;
nickjillings@1370 444 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 445 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 446 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 447 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 448 this.testXML = this.testXML.getAllElementsByTagName("metrics");
nicholas@2390 449 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 450 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 451 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 452 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 453 var testNode
nicholas@2535 454 if (this.testXML.length > 0) {
nickjillings@1370 455 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 456 if (testNode.length != 0) {
nicholas@2535 457 testNode = testNode[0];
nicholas@2535 458 } else {
nicholas@2535 459 testNode = undefined;
nicholas@2535 460 }
nickjillings@1370 461 } else {
nickjillings@1370 462 testNode = undefined;
nickjillings@1370 463 }
nickjillings@2108 464 var obj = {
nickjillings@2108 465 root: document.createElement("div"),
nickjillings@2109 466 text: document.createElement("label"),
nickjillings@2108 467 input: document.createElement("input"),
nickjillings@2108 468 parent: this,
nickjillings@2108 469 name: checkName,
nicholas@2535 470 handleEvent: function (event) {
nickjillings@2108 471 if (this.input.checked) {
nickjillings@2108 472 // Add to specification.interfaces.option
nicholas@2535 473 var included = specification.metrics.enabled.find(function (element, index, array) {
nicholas@2535 474 if (element == this.name) {
nicholas@2535 475 return true;
nicholas@2535 476 } else {
nicholas@2535 477 return false;
nicholas@2535 478 }
nicholas@2535 479 }, this);
nickjillings@2108 480 if (included == null) {
nickjillings@2108 481 specification.metrics.enabled.push(this.name);
nickjillings@2108 482 }
nickjillings@2108 483 } else {
nickjillings@2108 484 // Remove from specification.interfaces.option
nicholas@2535 485 var position = specification.metrics.enabled.findIndex(function (element, index, array) {
nicholas@2535 486 if (element == this.name) {
nicholas@2535 487 return true;
nicholas@2535 488 } else {
nicholas@2535 489 return false;
nicholas@2535 490 }
nicholas@2535 491 }, this);
nickjillings@2108 492 if (position >= 0) {
nicholas@2535 493 specification.metrics.enabled.splice(position, 1);
nickjillings@2108 494 }
nickjillings@2108 495 }
nickjillings@2108 496 }
nickjillings@1370 497 }
nicholas@2535 498
nicholas@2535 499 obj.input.addEventListener("click", obj);
nickjillings@2108 500 obj.root.className = "popup-checkbox";
nickjillings@2108 501 obj.input.type = "checkbox";
nicholas@2535 502 obj.input.setAttribute('id', checkName);
nicholas@2535 503 obj.text.setAttribute("for", checkName);
nickjillings@2108 504 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 505 obj.root.appendChild(obj.input);
nickjillings@2108 506 obj.root.appendChild(obj.text);
nicholas@2535 507 if (testNode != undefined) {
nicholas@2535 508 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 509 obj.input.checked = true;
nickjillings@1370 510 }
nicholas@2535 511 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 512 obj.input.disabled = true;
nickjillings@2108 513 obj.input.checked = false;
nickjillings@2108 514 obj.root.className = "popup-checkbox disabled";
nicholas@2535 515 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 516 obj.input.disabled = true;
nickjillings@2108 517 obj.input.checked = true;
nickjillings@2108 518 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 519 }
nickjillings@2108 520 } else {
nicholas@2535 521 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 522 obj.input.checked = true;
nickjillings@2108 523 }
nicholas@2535 524 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 525 obj.input.disabled = true;
nickjillings@2108 526 obj.input.checked = false;
nickjillings@2108 527 obj.root.className = "popup-checkbox disabled";
nicholas@2535 528 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 529 obj.input.disabled = true;
nickjillings@2108 530 obj.input.checked = true;
nickjillings@2108 531 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 532 }
nickjillings@1370 533 }
nicholas@2535 534 var included = specification.metrics.enabled.find(function (element, index, array) {
nicholas@2535 535 if (element == this.name) {
nicholas@2535 536 return true;
nicholas@2535 537 } else {
nicholas@2535 538 return false;
nicholas@2535 539 }
nicholas@2535 540 }, obj);
nickjillings@2108 541 obj.handleEvent();
nickjillings@2108 542 if (included != undefined) {
nickjillings@2108 543 obj.input.checked = true;
nickjillings@2108 544 }
nickjillings@2108 545 this.options.push(obj);
nickjillings@2108 546 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 547 }
nickjillings@1370 548 }
nicholas@2535 549 this.continue = function () {
nickjillings@1370 550 popupStateNodes.state[4].generate();
nickjillings@1370 551 popupObject.postNode(popupStateNodes.state[4]);
nickjillings@1370 552 }
nicholas@2535 553 this.back = function () {
nickjillings@2108 554 popupObject.postNode(popupStateNodes.state[2]);
nickjillings@2108 555 }
nickjillings@1370 556 }
nicholas@2535 557 this.state[4] = new function () {
nickjillings@1370 558 this.title = "Test Visuals";
nickjillings@1370 559 this.content = document.createElement("div");
nickjillings@1370 560 this.content.id = "state-1";
nickjillings@1370 561 var spnH = document.createElement('div');
nickjillings@1370 562 var span = document.createElement("span");
nickjillings@1370 563 span.textContent = "You can display extra visual content with your interface for the test user to interact with. Select from the available options below. Greyed out options are unavailable for your selected interface";
nickjillings@1370 564 spnH.appendChild(span);
nickjillings@1370 565 this.content.appendChild(spnH);
nickjillings@1370 566 this.options = [];
nickjillings@1370 567 this.checkText;
nickjillings@1370 568 this.testXML;
nickjillings@1370 569 this.interfaceXML;
nickjillings@2108 570 this.dynamicContent = document.createElement("div");
nickjillings@2108 571 this.content.appendChild(this.dynamicContent);
nicholas@2535 572 this.generate = function () {
nickjillings@2108 573 this.options = [];
nickjillings@2108 574 this.dynamicContent.innerHTML = null;
nickjillings@1370 575 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 576 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
nickjillings@1370 577 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 578 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
nickjillings@2108 579 this.testXML = this.testXML.getAllElementsByTagName("show");
nicholas@2390 580 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 581 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 582 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 583 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 584 var testNode
nicholas@2535 585 if (this.testXML.length > 0) {
nickjillings@1370 586 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 587 if (testNode.length != 0) {
nicholas@2535 588 testNode = testNode[0];
nicholas@2535 589 } else {
nicholas@2535 590 testNode = undefined;
nicholas@2535 591 }
nickjillings@1370 592 } else {
nickjillings@1370 593 testNode = undefined;
nickjillings@1370 594 }
nickjillings@2108 595 var obj = {
nickjillings@2108 596 root: document.createElement("div"),
nickjillings@2109 597 text: document.createElement("label"),
nickjillings@2108 598 input: document.createElement("input"),
nickjillings@2108 599 parent: this,
nickjillings@2108 600 name: checkName,
nicholas@2535 601 handleEvent: function (event) {
nickjillings@2108 602 if (this.input.checked) {
nickjillings@2108 603 // Add to specification.interfaces.option
nicholas@2535 604 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 605 if (element.name == this.name) {
nicholas@2535 606 return true;
nicholas@2535 607 } else {
nicholas@2535 608 return false;
nicholas@2535 609 }
nicholas@2535 610 }, this);
nickjillings@2108 611 if (included == null) {
nicholas@2535 612 specification.interfaces.options.push({
nicholas@2535 613 type: "show",
nicholas@2535 614 name: this.name
nicholas@2535 615 });
nickjillings@2108 616 }
nickjillings@2108 617 } else {
nickjillings@2108 618 // Remove from specification.interfaces.option
nicholas@2535 619 var position = specification.interfaces.options.findIndex(function (element, index, array) {
nicholas@2535 620 if (element.name == this.name) {
nicholas@2535 621 return true;
nicholas@2535 622 } else {
nicholas@2535 623 return false;
nicholas@2535 624 }
nicholas@2535 625 }, this);
nickjillings@2108 626 if (position >= 0) {
nicholas@2535 627 specification.interfaces.options.splice(position, 1);
nickjillings@2108 628 }
nickjillings@2108 629 }
nickjillings@2108 630 }
nickjillings@1370 631 }
nicholas@2535 632
nicholas@2535 633 obj.input.addEventListener("click", obj);
nickjillings@2108 634 obj.root.className = "popup-checkbox";
nickjillings@2108 635 obj.input.type = "checkbox";
nicholas@2535 636 obj.input.setAttribute('id', checkName);
nicholas@2535 637 obj.text.setAttribute("for", checkName);
nickjillings@2108 638 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 639 obj.root.appendChild(obj.input);
nickjillings@2108 640 obj.root.appendChild(obj.text);
nicholas@2535 641 if (testNode != undefined) {
nicholas@2535 642 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 643 obj.input.checked = true;
nickjillings@1370 644 }
nicholas@2535 645 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 646 obj.input.disabled = true;
nickjillings@2108 647 obj.input.checked = false;
nickjillings@2108 648 obj.root.className = "popup-checkbox disabled";
nicholas@2535 649 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 650 obj.input.disabled = true;
nickjillings@2108 651 obj.input.checked = true;
nickjillings@2108 652 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 653 }
nickjillings@2108 654 } else {
nicholas@2535 655 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 656 obj.input.checked = true;
nickjillings@2108 657 }
nicholas@2535 658 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 659 obj.input.disabled = true;
nickjillings@2108 660 obj.input.checked = false;
nickjillings@2108 661 obj.root.className = "popup-checkbox disabled";
nicholas@2535 662 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 663 obj.input.disabled = true;
nickjillings@2108 664 obj.input.checked = true;
nickjillings@2108 665 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 666 }
nickjillings@1370 667 }
nicholas@2535 668 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 669 if (element.name == this.name) {
nicholas@2535 670 return true;
nicholas@2535 671 } else {
nicholas@2535 672 return false;
nicholas@2535 673 }
nicholas@2535 674 }, obj);
nickjillings@2108 675 if (included != undefined) {
nickjillings@2108 676 obj.input.checked = true;
nickjillings@2108 677 }
nickjillings@2108 678 obj.handleEvent();
nickjillings@2108 679 this.options.push(obj);
nickjillings@2108 680 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 681 }
nickjillings@1370 682 }
nicholas@2535 683 this.continue = function () {
nickjillings@1370 684 popupObject.hide();
nickjillings@1370 685 convert.convert(document.getElementById('content'));
nickjillings@1370 686 }
nicholas@2535 687 this.back = function () {
nickjillings@2108 688 popupObject.postNode(popupStateNodes.state[3]);
nickjillings@2108 689 }
nickjillings@1370 690 }
nicholas@2535 691 this.state[5] = new function () {
nickjillings@1370 692 this.title = "Add/Edit Survey Element";
nickjillings@1370 693 this.content = document.createElement("div");
nickjillings@1370 694 this.content.id = "state-1";
nickjillings@1370 695 var spnH = document.createElement('div');
nickjillings@1370 696 var span = document.createElement("span");
nickjillings@1370 697 span.textContent = "You can configure your survey element here. Press 'Continue' to complete your changes.";
nickjillings@1370 698 spnH.appendChild(span);
nickjillings@1370 699 this.content.appendChild(spnH);
nickjillings@1370 700 this.dynamic = document.createElement("div");
nickjillings@1370 701 this.option = null;
nickjillings@1370 702 this.parent = null;
nickjillings@1375 703 this.optionLists = [];
nickjillings@2158 704 this.select = document.createElement("select");
nicholas@2535 705 this.select.setAttribute("name", "type");
nicholas@2535 706 this.select.addEventListener("change", this, false);
nickjillings@2158 707 this.content.appendChild(this.select);
nickjillings@1370 708 this.content.appendChild(this.dynamic);
nicholas@2535 709 this.generate = function (option, parent) {
nickjillings@1370 710 this.option = option;
nickjillings@1370 711 this.parent = parent;
nickjillings@2158 712 if (this.select.childElementCount == 0) {
nickjillings@2158 713 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("type")[0].getAllElementsByTagName("xs:enumeration");
nicholas@2535 714 for (var i = 0; i < optionList.length; i++) {
nickjillings@2158 715 var selectOption = document.createElement("option");
nickjillings@2158 716 selectOption.value = optionList[i].getAttribute("value");
nickjillings@2158 717 selectOption.textContent = selectOption.value;
nickjillings@2158 718 this.select.appendChild(selectOption);
nickjillings@2158 719 }
nickjillings@1370 720 }
nicholas@2535 721 if (this.option.type != undefined) {
nickjillings@2158 722 this.select.value = this.option.type
nickjillings@1370 723 } else {
nickjillings@2158 724 this.select.value = "statement";
nickjillings@1370 725 this.option.type = "statement";
nickjillings@1370 726 }
nicholas@2535 727
nickjillings@1370 728 this.dynamic.innerHTML = null;
nickjillings@1370 729 var statement = document.createElement("div");
nickjillings@1370 730 var statementText = document.createElement("span");
nickjillings@2159 731 var statementEntry = document.createElement("input");
nickjillings@1370 732 statement.appendChild(statementText);
nickjillings@1370 733 statement.appendChild(statementEntry);
nickjillings@2159 734 statement.className = "survey-entry-attribute";
nickjillings@1370 735 statementText.textContent = "Statement/Question";
nickjillings@2159 736 statementEntry.style.width = "500px";
nicholas@2535 737 statementEntry.addEventListener("change", this, false);
nicholas@2535 738 statementEntry.setAttribute("name", "statement");
nickjillings@1370 739 statementEntry.value = this.option.statement;
nickjillings@1370 740 this.dynamic.appendChild(statement);
nicholas@2535 741
nickjillings@1375 742 var id = document.createElement("div");
nickjillings@1375 743 var idText = document.createElement("span");
nickjillings@1375 744 var idEntry = document.createElement("input");
nickjillings@1375 745 id.appendChild(idText);
nickjillings@1375 746 id.appendChild(idEntry);
nickjillings@2159 747 id.className = "survey-entry-attribute";
nickjillings@1375 748 idText.textContent = "ID: ";
nicholas@2535 749 idEntry.addEventListener("change", this, false);
nicholas@2535 750 idEntry.setAttribute("name", "id");
nickjillings@1375 751 idEntry.value = this.option.id;
nicholas@2535 752
nickjillings@2158 753 this.dynamic.appendChild(id);
nicholas@2535 754
nicholas@2535 755 switch (this.option.type) {
nickjillings@1370 756 case "statement":
nickjillings@1370 757 break;
nickjillings@1370 758 case "question":
nickjillings@1370 759 var boxsizeSelect = document.createElement("select");
nickjillings@1370 760 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration");
nicholas@2535 761 for (var i = 0; i < optionList.length; i++) {
nickjillings@1370 762 var selectOption = document.createElement("option");
nickjillings@1370 763 selectOption.value = optionList[i].getAttribute("value");
nickjillings@1370 764 selectOption.textContent = selectOption.value;
nickjillings@1370 765 boxsizeSelect.appendChild(selectOption);
nickjillings@1370 766 }
nicholas@2535 767 if (this.option.boxsize != undefined) {
nickjillings@1370 768 boxsizeSelect.value = this.option.boxsize;
nickjillings@1370 769 } else {
nickjillings@1370 770 boxsizeSelect.value = "normal";
nickjillings@1370 771 this.option.boxsize = "normal";
nickjillings@1370 772 }
nicholas@2535 773 boxsizeSelect.setAttribute("name", "boxsize");
nicholas@2535 774 boxsizeSelect.addEventListener("change", this, false);
nickjillings@1370 775 var boxsize = document.createElement("div");
nickjillings@1370 776 var boxsizeText = document.createElement("span");
nickjillings@1370 777 boxsizeText.textContent = "Entry Size: ";
nickjillings@1370 778 boxsize.appendChild(boxsizeText);
nickjillings@1370 779 boxsize.appendChild(boxsizeSelect);
nickjillings@2159 780 boxsize.className = "survey-entry-attribute";
nickjillings@1370 781 this.dynamic.appendChild(boxsize);
nicholas@2535 782
nickjillings@1370 783 var mandatory = document.createElement("div");
nickjillings@1370 784 var mandatoryInput = document.createElement("input");
nickjillings@1370 785 var mandatoryText = document.createElement("span");
nickjillings@1370 786 mandatoryText.textContent = "Mandatory: ";
nickjillings@1370 787 mandatory.appendChild(mandatoryText);
nickjillings@1370 788 mandatory.appendChild(mandatoryInput);
nickjillings@2159 789 mandatory.className = "survey-entry-attribute";
nickjillings@1370 790 mandatoryInput.type = "checkbox";
nicholas@2535 791 if (this.option.mandatory) {
nicholas@2535 792 mandatoryInput.checked = true;
nicholas@2535 793 } else {
nicholas@2535 794 mandatoryInput.checked = false;
nicholas@2535 795 }
nicholas@2535 796 mandatoryInput.setAttribute("name", "mandatory");
nicholas@2535 797 mandatoryInput.addEventListener("change", this, false);
nickjillings@1375 798 this.dynamic.appendChild(mandatory);
nickjillings@1375 799 break;
nickjillings@1375 800 case "number":
nickjillings@1375 801 this.dynamic.appendChild(id);
nicholas@2535 802
nickjillings@1375 803 var mandatory = document.createElement("div");
nickjillings@1375 804 var mandatoryInput = document.createElement("input");
nickjillings@1375 805 var mandatoryText = document.createElement("span");
nickjillings@1375 806 mandatoryText.textContent = "Mandatory: ";
nickjillings@1370 807 mandatory.appendChild(mandatoryText);
nickjillings@1370 808 mandatory.appendChild(mandatoryInput);
nickjillings@2159 809 mandatory.className = "survey-entry-attribute";
nickjillings@1375 810 mandatoryInput.type = "checkbox";
nicholas@2535 811 if (this.option.mandatory) {
nicholas@2535 812 mandatoryInput.checked = true;
nicholas@2535 813 } else {
nicholas@2535 814 mandatoryInput.checked = false;
nicholas@2535 815 }
nicholas@2535 816 mandatoryInput.setAttribute("name", "mandatory");
nicholas@2535 817 mandatoryInput.addEventListener("change", this, false);
nickjillings@1370 818 this.dynamic.appendChild(mandatory);
nicholas@2535 819
nickjillings@1375 820 var minimum = document.createElement("div");
nickjillings@1375 821 var minimumEntry = document.createElement("input");
nickjillings@1375 822 var minimumText = document.createElement("span");
nickjillings@1375 823 minimumText.textContent = "Minimum: ";
nickjillings@1375 824 minimum.appendChild(minimumText);
nickjillings@1375 825 minimum.appendChild(minimumEntry);
nickjillings@2159 826 minimum.className = "survey-entry-attribute";
nickjillings@1375 827 minimumEntry.type = "number";
nicholas@2535 828 minimumEntry.setAttribute("name", "min");
nicholas@2535 829 minimumEntry.addEventListener("change", this, false);
nickjillings@1375 830 minimumEntry.value = this.option.min;
nickjillings@1375 831 this.dynamic.appendChild(minimum);
nicholas@2535 832
nickjillings@1375 833 var maximum = document.createElement("div");
nickjillings@1375 834 var maximumEntry = document.createElement("input");
nickjillings@1375 835 var maximumText = document.createElement("span");
nickjillings@1375 836 maximumText.textContent = "Maximum: ";
nickjillings@1375 837 maximum.appendChild(maximumText);
nickjillings@1375 838 maximum.appendChild(maximumEntry);
nickjillings@2159 839 maximum.className = "survey-entry-attribute";
nickjillings@1375 840 maximumEntry.type = "number";
nicholas@2535 841 maximumEntry.setAttribute("name", "max");
nicholas@2535 842 maximumEntry.addEventListener("change", this, false);
nickjillings@1375 843 maximumEntry.value = this.option.max;
nickjillings@1375 844 this.dynamic.appendChild(maximum);
nickjillings@1370 845 break;
nickjillings@1375 846 case "checkbox":
nickjillings@1375 847 case "radio":
nickjillings@1375 848 this.dynamic.appendChild(id);
nickjillings@1375 849 var optionHolder = document.createElement("div");
nickjillings@1375 850 optionHolder.className = 'node';
nickjillings@1375 851 optionHolder.id = 'popup-option-holder';
nicholas@2535 852 var optionObject = function (parent, option) {
nickjillings@1375 853 this.rootDOM = document.createElement("div");
nickjillings@1375 854 this.rootDOM.className = "popup-option-entry";
nickjillings@1375 855 this.inputName = document.createElement("input");
nicholas@2535 856 this.inputName.setAttribute("name", "name");
nickjillings@1375 857 this.inputLabel = document.createElement("input");
nicholas@2535 858 this.inputLabel.setAttribute("name", "text");
nickjillings@1375 859 this.specification = option;
nickjillings@1375 860 this.parent = parent;
nicholas@2535 861 this.handleEvent = function () {
nickjillings@1375 862 var target = event.currentTarget.getAttribute("name");
nicholas@2535 863 eval("this.specification." + target + " = event.currentTarget.value");
nickjillings@1375 864 };
nicholas@2535 865
nickjillings@1375 866 var nameText = document.createElement("span");
nickjillings@1375 867 nameText.textContent = "Name: ";
nickjillings@1375 868 var labelText = document.createElement("span");
nickjillings@1375 869 labelText.textContent = "Label: ";
nickjillings@1375 870 this.rootDOM.appendChild(nameText);
nickjillings@1375 871 this.rootDOM.appendChild(this.inputName);
nickjillings@1375 872 this.rootDOM.appendChild(labelText);
nickjillings@1375 873 this.rootDOM.appendChild(this.inputLabel);
nicholas@2535 874 this.inputName.addEventListener("change", this, false);
nicholas@2535 875 this.inputLabel.addEventListener("change", this, false);
nickjillings@1375 876 this.inputName.value = this.specification.name;
nickjillings@1375 877 this.inputLabel.value = this.specification.text;
nickjillings@2180 878 this.inputLabel.style.width = "350px";
nicholas@2535 879
nickjillings@1375 880 this.deleteEntry = {
nickjillings@1375 881 root: document.createElement("button"),
nickjillings@1375 882 parent: this,
nicholas@2535 883 handleEvent: function () {
nickjillings@1375 884 document.getElementById("popup-option-holder").removeChild(this.parent.rootDOM);
nicholas@2535 885 var index = this.parent.parent.option.options.findIndex(function (element, index, array) {
nickjillings@1375 886 if (element == this.parent.specification)
nickjillings@1375 887 return true;
nickjillings@1375 888 else
nickjillings@1375 889 return false;
nicholas@2535 890 }, this);
nickjillings@1375 891 var optionList = this.parent.parent.option.options;
nicholas@2535 892 if (index == optionList.length - 1) {
nicholas@2535 893 optionList = optionList.slice(0, index);
nickjillings@1375 894 } else {
nicholas@2535 895 optionList = optionList.slice(0, index).concat(optionList.slice(index + 1));
nickjillings@1375 896 }
nickjillings@1375 897 this.parent.parent.option.options = optionList;
nickjillings@1375 898 }
nickjillings@1375 899 };
nickjillings@1375 900 this.deleteEntry.root.textContent = "Delete Option";
nicholas@2535 901 this.deleteEntry.root.addEventListener("click", this.deleteEntry, false);
nickjillings@1375 902 this.rootDOM.appendChild(this.deleteEntry.root);
nickjillings@1375 903 }
nickjillings@2158 904 this.addEntry = {
nickjillings@2158 905 parent: this,
nickjillings@2158 906 root: document.createElement("button"),
nicholas@2535 907 handleEvent: function () {
nicholas@2535 908 var node = {
nicholas@2535 909 name: "name",
nicholas@2535 910 text: "text"
nicholas@2535 911 };
nickjillings@2158 912 var optionsList = this.parent.option.options;
nickjillings@2158 913 optionsList.push(node);
nicholas@2535 914 var obj = new optionObject(this.parent, optionsList[optionsList.length - 1]);
nickjillings@2158 915 this.parent.optionLists.push(obj);
nickjillings@2158 916 document.getElementById("popup-option-holder").appendChild(obj.rootDOM);
nickjillings@2158 917 }
nickjillings@2158 918 }
nickjillings@2158 919 this.addEntry.root.textContent = "Add Option";
nicholas@2535 920 this.addEntry.root.addEventListener("click", this.addEntry);
nickjillings@2158 921 this.dynamic.appendChild(this.addEntry.root);
nicholas@2535 922 for (var i = 0; i < this.option.options.length; i++) {
nicholas@2535 923 var obj = new optionObject(this, this.option.options[i]);
nickjillings@1375 924 this.optionLists.push(obj);
nickjillings@1375 925 optionHolder.appendChild(obj.rootDOM);
nickjillings@1375 926 }
nickjillings@1375 927 this.dynamic.appendChild(optionHolder);
nickjillings@1370 928 }
nickjillings@1370 929 }
nicholas@2536 930 this.handleEvent = function (event) {
nickjillings@1370 931 var name = event.currentTarget.getAttribute("name");
nickjillings@2159 932 var nodeName = event.currentTarget.nodeName;
nickjillings@2159 933 if (name == "type" && nodeName == "SELECT") {
nickjillings@2159 934 // If type has changed, we may need to rebuild the entire state node
nicholas@2535 935 if (event.currentTarget.value != this.option.name) {
nickjillings@2159 936 this.option.type = event.currentTarget.value;
nicholas@2535 937 this.generate(this.option, this.parent);
nickjillings@2159 938 }
nickjillings@2159 939 return;
nickjillings@2159 940 }
nicholas@2535 941 switch (event.currentTarget.getAttribute("type")) {
nickjillings@2159 942 case "checkbox":
nicholas@2535 943 eval("this.option." + name + " = event.currentTarget.checked");
nickjillings@1370 944 break;
nickjillings@2159 945 default:
nicholas@2535 946 eval("this.option." + name + " = event.currentTarget.value");
nickjillings@1370 947 break;
nickjillings@1370 948 }
nickjillings@1370 949 }
nicholas@2535 950 this.continue = function () {
nicholas@2535 951 if (this.parent.type == "surveyNode") {
nicholas@2535 952 var newNode = new this.parent.surveyEntryNode(this.parent, this.option);
nickjillings@1375 953 this.parent.children.push(newNode);
nickjillings@1375 954 this.parent.childrenDOM.appendChild(newNode.rootDOM);
nickjillings@1375 955 } else if (this.parent.type == "surveyEntryNode") {
nickjillings@1375 956 this.parent.build();
nickjillings@1375 957 }
nickjillings@1370 958 popupObject.hide();
nickjillings@1370 959 }
nickjillings@1370 960 }
nicholas@2535 961 this.state[6] = new function () {
nickjillings@1385 962 this.title = "Edit Scale Markers";
nickjillings@1385 963 this.content = document.createElement("div");
nickjillings@1385 964 this.content.id = "state-6";
nickjillings@1385 965 var spnH = document.createElement('div');
nickjillings@1385 966 var span = document.createElement("span");
nickjillings@1385 967 span.textContent = "You can edit your scale markers here for the selected interface.";
nickjillings@1385 968 spnH.appendChild(span);
nickjillings@1385 969 this.scaleRoot;
nickjillings@1385 970 this.parent;
nicholas@2535 971 this.markerNodes = [];
nickjillings@1385 972 this.preset = {
nickjillings@1385 973 input: document.createElement("select"),
nickjillings@1385 974 parent: this,
nicholas@2535 975 handleEvent: function (event) {
nickjillings@1385 976 this.parent.scaleRoot.scales = [];
nickjillings@1385 977 var protoScale = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getAllElementsByName(event.currentTarget.value)[0];
nicholas@2390 978 var protoMarkers = protoScale.getElementsByTagName("scale");
nicholas@2535 979 for (var i = 0; i < protoMarkers.length; i++) {
nickjillings@1385 980 var marker = {
nickjillings@1385 981 position: protoMarkers[i].getAttribute("position"),
nickjillings@1385 982 text: protoMarkers[i].textContent
nickjillings@1385 983 }
nickjillings@1385 984 this.parent.scaleRoot.scales.push(marker);
nickjillings@1385 985 }
nickjillings@1385 986 this.parent.buildMarkerList();
nickjillings@1385 987 }
nickjillings@1385 988 }
nicholas@2535 989 this.preset.input.addEventListener("change", this.preset);
nickjillings@1385 990 this.content.appendChild(this.preset.input);
nickjillings@1385 991 var optionHolder = document.createElement("div");
nickjillings@1385 992 optionHolder.className = 'node';
nickjillings@1385 993 optionHolder.id = 'popup-option-holder';
nickjillings@1385 994 this.content.appendChild(optionHolder);
nicholas@2535 995 this.generate = function (scaleRoot, parent) {
nickjillings@1385 996 this.scaleRoot = scaleRoot;
nickjillings@1385 997 this.parent = parent;
nicholas@2535 998
nickjillings@1385 999 // Generate Pre-Set dropdown
nicholas@2390 1000 var protoScales = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getElementsByTagName("scale");
nickjillings@1385 1001 this.preset.input.innerHTML = "";
nicholas@2535 1002
nicholas@2535 1003 for (var i = 0; i < protoScales.length; i++) {
nickjillings@1385 1004 var selectOption = document.createElement("option");
nickjillings@1385 1005 var scaleName = protoScales[i].getAttribute("name");
nicholas@2535 1006 selectOption.setAttribute("name", scaleName);
nickjillings@1385 1007 selectOption.textContent = scaleName;
nickjillings@1385 1008 this.preset.input.appendChild(selectOption);
nickjillings@1385 1009 }
nicholas@2535 1010
nickjillings@2115 1011 this.addMarker = {
nickjillings@2115 1012 root: document.createElement("button"),
nickjillings@2115 1013 parent: this,
nicholas@2535 1014 handleEvent: function () {
nickjillings@2115 1015 var marker = {
nickjillings@2115 1016 position: 0,
nickjillings@2115 1017 text: "text"
nickjillings@2115 1018 };
nickjillings@2115 1019 this.parent.scaleRoot.scales.push(marker);
nicholas@2535 1020 var markerNode = new this.parent.buildMarkerNode(this.parent, marker);
nickjillings@2115 1021 document.getElementById("popup-option-holder").appendChild(markerNode.root);
nickjillings@2115 1022 this.parent.markerNodes.push(markerNode);
nickjillings@2115 1023 }
nickjillings@2115 1024 };
nickjillings@2115 1025 this.addMarker.root.textContent = "Add Marker";
nicholas@2535 1026 this.addMarker.root.addEventListener("click", this.addMarker);
nickjillings@2115 1027 this.content.appendChild(this.addMarker.root);
nicholas@2535 1028
nickjillings@1385 1029 // Create Marker List
nickjillings@1385 1030 this.buildMarkerList();
nickjillings@1385 1031 }
nicholas@2535 1032 this.buildMarkerList = function () {
nickjillings@1385 1033 var markerInject = document.getElementById("popup-option-holder");
nickjillings@1385 1034 markerInject.innerHTML = "";
nickjillings@1385 1035 this.markerNodes = [];
nicholas@2535 1036 for (var i = 0; i < this.scaleRoot.scales.length; i++) {
nicholas@2535 1037 var markerNode = new this.buildMarkerNode(this, this.scaleRoot.scales[i]);
nickjillings@1385 1038 markerInject.appendChild(markerNode.root);
nickjillings@1385 1039 this.markerNodes.push(markerNode);
nicholas@2535 1040
nickjillings@1385 1041 }
nickjillings@1385 1042 }
nicholas@2535 1043
nicholas@2535 1044 this.buildMarkerNode = function (parent, specification) {
nickjillings@2115 1045 this.root = document.createElement("div");
nickjillings@2115 1046 this.root.className = "popup-option-entry";
nickjillings@2115 1047 this.positionInput = document.createElement("input");
nickjillings@2115 1048 this.positionInput.min = 0;
nickjillings@2115 1049 this.positionInput.max = 100;
nickjillings@2115 1050 this.positionInput.value = specification.position;
nicholas@2535 1051 this.positionInput.setAttribute("name", "position");
nickjillings@2115 1052 this.textInput = document.createElement("input");
nicholas@2535 1053 this.textInput.setAttribute("name", "text");
nickjillings@2180 1054 this.textInput.style.width = "300px";
nickjillings@2115 1055 this.textInput.value = specification.text;
nickjillings@2115 1056 this.specification = specification;
nickjillings@2115 1057 this.parent = parent;
nicholas@2535 1058 this.handleEvent = function (event) {
nicholas@2535 1059 switch (event.currentTarget.getAttribute("name")) {
nickjillings@2115 1060 case "position":
nickjillings@2115 1061 this.specification.position = Number(event.currentTarget.value);
nickjillings@2115 1062 break;
nickjillings@2115 1063 case "text":
nickjillings@2115 1064 this.specification.text = event.currentTarget.value;
nickjillings@2115 1065 break;
nickjillings@2115 1066 }
nickjillings@2115 1067 }
nicholas@2535 1068 this.positionInput.addEventListener("change", this, false);
nicholas@2535 1069 this.textInput.addEventListener("change", this, false);
nickjillings@2115 1070
nickjillings@2115 1071 var posText = document.createElement("span");
nickjillings@2115 1072 posText.textContent = "Position: ";
nickjillings@2115 1073 var textText = document.createElement("span");
nickjillings@2115 1074 textText.textContent = "Text: ";
nickjillings@2115 1075 this.root.appendChild(posText);
nickjillings@2115 1076 this.root.appendChild(this.positionInput);
nickjillings@2115 1077 this.root.appendChild(textText);
nickjillings@2115 1078 this.root.appendChild(this.textInput);
nickjillings@2115 1079
nickjillings@2115 1080 this.deleteMarker = {
nickjillings@2115 1081 root: document.createElement("button"),
nickjillings@2115 1082 parent: this,
nicholas@2535 1083 handleEvent: function () {
nicholas@2535 1084 var index = this.parent.parent.scaleRoot.scales.findIndex(function (element, index, array) {
nicholas@2535 1085 if (element == this) {
nicholas@2535 1086 return true;
nicholas@2535 1087 } else {
nicholas@2535 1088 return false;
nicholas@2535 1089 }
nicholas@2535 1090 }, this.parent.specification)
nickjillings@2115 1091 if (index >= 0) {
nicholas@2535 1092 this.parent.parent.scaleRoot.scales.splice(index, 1);
nickjillings@2115 1093 }
nickjillings@2115 1094 document.getElementById("popup-option-holder").removeChild(this.parent.root);
nickjillings@2115 1095 }
nickjillings@2115 1096 }
nicholas@2535 1097 this.deleteMarker.root.addEventListener("click", this.deleteMarker);
nickjillings@2115 1098 this.deleteMarker.root.textContent = "Delete Marker"
nickjillings@2115 1099 this.root.appendChild(this.deleteMarker.root);
nickjillings@2115 1100 }
nickjillings@1385 1101 }
nickjillings@1370 1102 }
nickjillings@1370 1103 }
nickjillings@1370 1104
nicholas@2535 1105 function SpecificationToHTML() {
nickjillings@1370 1106 // This takes the specification node and converts it to an on-page HTML object
nickjillings@1370 1107 // Each Specification Node is given its own JS object which listens to the XSD for instant verification
nickjillings@1370 1108 // Once generated, it directly binds into the specification object to update with changes
nickjillings@1370 1109 // Fixed DOM entries
nickjillings@1370 1110 this.injectDOM;
nickjillings@1370 1111 this.setupDOM;
nickjillings@1370 1112 this.pages = [];
nicholas@2535 1113
nickjillings@1370 1114 // Self-contained generators
nicholas@2535 1115 this.createGeneralNodeDOM = function (name, id, parent) {
nickjillings@1375 1116 this.type = name;
nickjillings@1370 1117 var root = document.createElement('div');
nickjillings@1370 1118 root.id = id;
nickjillings@1370 1119 root.className = "node";
nickjillings@1370 1120
nickjillings@1370 1121 var titleDiv = document.createElement('div');
nickjillings@1370 1122 titleDiv.className = "node-title";
nickjillings@1370 1123 var title = document.createElement('span');
nickjillings@1370 1124 title.className = "node-title";
nickjillings@1370 1125 title.textContent = name;
nickjillings@1370 1126 titleDiv.appendChild(title);
nickjillings@1370 1127
nickjillings@1370 1128 var attributeDiv = document.createElement('div');
nickjillings@1370 1129 attributeDiv.className = "node-attributes";
nickjillings@1370 1130
nickjillings@1370 1131 var childrenDiv = document.createElement('div');
nickjillings@1370 1132 childrenDiv.className = "node-children";
nickjillings@1370 1133
nickjillings@1370 1134 var buttonsDiv = document.createElement('div');
nickjillings@1370 1135 buttonsDiv.className = "node-buttons";
nickjillings@1370 1136
nickjillings@1370 1137 root.appendChild(titleDiv);
nickjillings@1370 1138 root.appendChild(attributeDiv);
nickjillings@1370 1139 root.appendChild(childrenDiv);
nickjillings@1370 1140 root.appendChild(buttonsDiv);
nickjillings@1370 1141
nickjillings@1370 1142 var obj = {
nickjillings@1370 1143 rootDOM: root,
nickjillings@1370 1144 titleDOM: title,
nickjillings@1370 1145 attributeDOM: attributeDiv,
nickjillings@1370 1146 attributes: [],
nickjillings@1370 1147 childrenDOM: childrenDiv,
nickjillings@1370 1148 children: [],
nickjillings@1370 1149 buttonDOM: buttonsDiv,
nickjillings@1370 1150 parent: parent
nickjillings@1370 1151 }
nickjillings@1370 1152 return obj;
nickjillings@1370 1153 }
nicholas@2535 1154
nicholas@2535 1155 this.convertAttributeToDOM = function (node, schema) {
nickjillings@1370 1156 // This takes an attribute schema node and returns an object with the input node and any bindings
nicholas@2535 1157 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) {
nicholas@2535 1158 schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
nicholas@2535 1159 }
nicholas@2535 1160 var obj = new function () {
nickjillings@1370 1161 this.input;
nickjillings@1370 1162 this.name;
nickjillings@1370 1163 this.owner;
nickjillings@1370 1164 this.holder;
nicholas@2535 1165
nickjillings@1370 1166 this.name = schema.getAttribute('name');
nickjillings@1370 1167 this.default = schema.getAttribute('default');
nickjillings@1370 1168 this.dataType = schema.getAttribute('type');
nickjillings@2158 1169 if (this.dataType == undefined) {
nickjillings@2158 1170 if (schema.childElementCount > 0) {
nicholas@2390 1171 if (schema.firstElementChild.nodeName == "xs:simpleType") {
nickjillings@2158 1172 this.dataType = schema.getAllElementsByTagName("xs:restriction")[0].getAttribute("base");
nickjillings@2158 1173 }
nickjillings@2158 1174 }
nickjillings@2158 1175 }
nicholas@2535 1176 if (typeof this.dataType == "string") {
nicholas@2535 1177 this.dataType = this.dataType.substr(3);
nicholas@2535 1178 } else {
nicholas@2535 1179 this.dataType = "string";
nicholas@2535 1180 }
nickjillings@1370 1181 var minVar = undefined;
nickjillings@1370 1182 var maxVar = undefined;
nicholas@2535 1183 switch (this.dataType) {
nickjillings@1370 1184 case "negativeInteger":
nickjillings@1370 1185 maxVar = -1;
nickjillings@1370 1186 break;
nickjillings@1370 1187 case "positiveInteger":
nickjillings@1370 1188 minVar = 1;
nickjillings@1370 1189 break;
nickjillings@1370 1190 case "nonNegativeInteger":
nickjillings@1370 1191 minVar = 0;
nickjillings@1370 1192 break;
nickjillings@1370 1193 case "nonPositiveInteger":
nickjillings@1370 1194 maxVar = 0;
nickjillings@1370 1195 break;
nickjillings@1370 1196 case "byte":
nickjillings@1370 1197 minVar = 0;
nickjillings@1370 1198 maxVar = 256;
nickjillings@1370 1199 break;
nickjillings@1370 1200 case "short":
nickjillings@1370 1201 minVar = 0;
nickjillings@1370 1202 maxVar = 65536;
nickjillings@1370 1203 break;
nickjillings@1370 1204 default:
nickjillings@1370 1205 break;
nickjillings@1370 1206 }
nicholas@2535 1207
nickjillings@2174 1208 this.enumeration = schema.getAllElementsByTagName("xs:enumeration");
nickjillings@2174 1209 if (this.enumeration.length == 0) {
nickjillings@2174 1210 this.input = document.createElement('input');
nicholas@2535 1211 switch (this.dataType) {
nickjillings@2174 1212 case "boolean":
nickjillings@2174 1213 this.input.type = "checkbox";
nickjillings@2174 1214 break;
nickjillings@2174 1215 case "negativeInteger":
nickjillings@2174 1216 case "positiveInteger":
nickjillings@2174 1217 case "nonNegativeInteger":
nickjillings@2174 1218 case "nonPositiveInteger":
nickjillings@2174 1219 case "integer":
nickjillings@2174 1220 case "short":
nickjillings@2174 1221 case "byte":
nickjillings@2174 1222 this.input.step = 1;
nickjillings@2174 1223 case "decimal":
nickjillings@2174 1224 this.input.type = "number";
nickjillings@2174 1225 this.input.min = minVar;
nickjillings@2174 1226 this.input.max = maxVar;
nickjillings@2174 1227 break;
nickjillings@2174 1228 default:
nickjillings@2174 1229 break;
nickjillings@2174 1230 }
nickjillings@2174 1231 } else {
nickjillings@2174 1232 this.input = document.createElement("select");
nicholas@2535 1233 for (var i = 0; i < this.enumeration.length; i++) {
nickjillings@2174 1234 var option = document.createElement("option");
nickjillings@2174 1235 var value = this.enumeration[i].getAttribute("value");
nicholas@2535 1236 option.setAttribute("value", value);
nickjillings@2174 1237 option.textContent = value;
nickjillings@2174 1238 this.input.appendChild(option);
nickjillings@2174 1239 }
nickjillings@1370 1240 }
nickjillings@1370 1241 var value;
nicholas@2535 1242 eval("value = node." + this.name)
nicholas@2535 1243 if (this.default != undefined && value == undefined) {
nickjillings@2174 1244 value = this.default;
nickjillings@2174 1245 }
nickjillings@2174 1246 if (this.input.type == "checkbox") {
nicholas@2535 1247 if (value == "true" || value == "True") {
nicholas@2535 1248 this.input.checked = false;
nicholas@2535 1249 } else {
nicholas@2535 1250 this.input.checked = false;
nicholas@2535 1251 }
nickjillings@2174 1252 } else {
nickjillings@1370 1253 this.input.value = value;
nickjillings@1370 1254 }
nicholas@2535 1255 this.handleEvent = function (event) {
nickjillings@1370 1256 var value;
nicholas@2535 1257 if (this.input.nodeName == "INPUT") {
nicholas@2535 1258 switch (this.input.type) {
nickjillings@2174 1259 case "checkbox":
nickjillings@2174 1260 value = event.currentTarget.checked;
nickjillings@2174 1261 break;
nickjillings@2174 1262 case "number":
n@2423 1263 if (event.currentTarget.value != "") {
n@2423 1264 value = Number(event.currentTarget.value);
n@2423 1265 } else {
n@2423 1266 value = undefined;
n@2423 1267 }
nickjillings@2174 1268 break;
nickjillings@2174 1269 default:
n@2423 1270 if (event.currentTarget.value != "") {
n@2423 1271 value = event.currentTarget.value;
n@2423 1272 } else {
n@2423 1273 value = undefined;
n@2423 1274 }
nicholas@2535 1275 break;
nickjillings@2174 1276 }
nickjillings@2174 1277 } else if (this.input.nodeName == "SELECT") {
nickjillings@2174 1278 value = event.currentTarget.value;
nickjillings@1370 1279 }
nicholas@2535 1280 eval("this.owner." + this.name + " = value");
nickjillings@1370 1281 }
nickjillings@1370 1282 this.holder = document.createElement('div');
nickjillings@1370 1283 this.holder.className = "attribute";
nicholas@2535 1284 this.holder.setAttribute('name', this.name);
nickjillings@1370 1285 var text = document.createElement('span');
nicholas@2535 1286 eval("text.textContent = attributeText." + this.name + "+': '");
nickjillings@1370 1287 this.holder.appendChild(text);
nickjillings@1370 1288 this.holder.appendChild(this.input);
nickjillings@1370 1289 this.owner = node;
nicholas@2535 1290 this.input.addEventListener("change", this, false);
nickjillings@1370 1291 }
nicholas@2535 1292 if (obj.attribute != null) {
nickjillings@1370 1293 obj.input.value = obj.attribute;
nickjillings@1370 1294 }
nickjillings@1370 1295 return obj;
nickjillings@1370 1296 }
nicholas@2535 1297
nicholas@2535 1298 this.convert = function (root) {
nickjillings@1370 1299 //Performs the actual conversion using the given root DOM as the root
nickjillings@1370 1300 this.injectDOM = root;
nicholas@2535 1301
nickjillings@1373 1302 // Build the export button
nickjillings@1373 1303 var exportButton = document.createElement("button");
nickjillings@1373 1304 exportButton.textContent = "Export to XML";
nicholas@2535 1305 exportButton.onclick = function () {
nickjillings@1373 1306 var doc = specification.encode();
nickjillings@1373 1307 var obj = {};
nickjillings@1373 1308 obj.title = "Export";
nickjillings@1373 1309 obj.content = document.createElement("div");
nickjillings@1373 1310 obj.content.id = "finish";
nickjillings@1373 1311 var span = document.createElement("span");
n@2405 1312 span.textContent = "Your XML document is linked below. On most browsers, simply right click on the link and select 'Save As'. Or clicking on the link may download the file directly."
n@2405 1313 obj.content.appendChild(span);
n@2405 1314 span = document.createElement("p");
n@2405 1315 span.textContent = "NOTE FOR SAFARI! You cannot right click on the below link and save it as a file, Safari does not like that at all. Instead click on it to open the XML, the Press Cmd+S to open the save dialogue. Make sure you have 'save as Page Source' selected on the bottom of the window. Currently Safari has no plans to support the HTML 'download' attribute which causes this problem";
nickjillings@1373 1316 obj.content.appendChild(span);
nickjillings@1373 1317 var link = document.createElement("div");
n@2412 1318 link.appendChild(doc.firstChild);
nickjillings@1373 1319 var file = [link.innerHTML];
nicholas@2535 1320 var bb = new Blob(file, {
nicholas@2535 1321 type: 'application/xml'
nicholas@2535 1322 });
nickjillings@1373 1323 var dnlk = window.URL.createObjectURL(bb);
nickjillings@1373 1324 var a = document.createElement("a");
nickjillings@1373 1325 a.hidden = '';
nickjillings@1373 1326 a.href = dnlk;
nickjillings@1373 1327 a.download = "project-specification.xml";
nickjillings@1373 1328 a.textContent = "Save File";
nickjillings@1373 1329 obj.content.appendChild(a);
nickjillings@1373 1330 popupObject.show();
nickjillings@1373 1331 popupObject.postNode(obj);
nickjillings@1373 1332 }
nickjillings@1373 1333 this.injectDOM.appendChild(exportButton);
nicholas@2535 1334
nickjillings@1370 1335 // First perform the setupNode;
nickjillings@1370 1336 var setupSchema = specification.schema.getAllElementsByName('setup')[0];
nicholas@2535 1337 this.setupDOM = new this.createGeneralNodeDOM('Global Configuration', 'setup', null);
nickjillings@1370 1338 this.injectDOM.appendChild(this.setupDOM.rootDOM);
nickjillings@1370 1339 var setupAttributes = setupSchema.getAllElementsByTagName('xs:attribute');
nicholas@2535 1340 for (var i = 0; i < setupAttributes.length; i++) {
nickjillings@1370 1341 var attributeName = setupAttributes[i].getAttribute('name');
nicholas@2535 1342 var attrObject = this.convertAttributeToDOM(specification, setupAttributes[i]);
nickjillings@1370 1343 this.setupDOM.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 1344 this.setupDOM.attributes.push(attrObject);
nickjillings@1370 1345 }
nicholas@2535 1346
nickjillings@2179 1347 // Build the exit Text node
nicholas@2535 1348 var exitText = new this.createGeneralNodeDOM("Exit Text", "exit-test", this.setupDOM);
nickjillings@2179 1349 exitText.rootDOM.removeChild(exitText.attributeDOM);
nickjillings@2179 1350 this.setupDOM.children.push(exitText);
nickjillings@2179 1351 this.setupDOM.childrenDOM.appendChild(exitText.rootDOM);
nickjillings@2179 1352 var obj = {
nickjillings@2179 1353 rootDOM: document.createElement("div"),
nickjillings@2179 1354 labelDOM: document.createElement("label"),
nickjillings@2179 1355 inputDOM: document.createElement("textarea"),
nickjillings@2179 1356 parent: exitText,
nickjillings@2179 1357 specification: specification,
nicholas@2535 1358 handleEvent: function (event) {
nickjillings@2179 1359 this.specification.exitText = this.inputDOM.value;
nickjillings@2179 1360 }
nickjillings@2179 1361 }
b@2367 1362 var exitWarning = document.createElement("div");
b@2367 1363 obj.rootDOM.appendChild(exitWarning);
b@2367 1364 exitWarning.textContent = "Only visible when the above 'On complete redirect URL' field is empty.";
nickjillings@2179 1365 obj.rootDOM.appendChild(obj.labelDOM);
nickjillings@2179 1366 obj.rootDOM.appendChild(obj.inputDOM);
nickjillings@2179 1367 obj.labelDOM.textContent = "Text: ";
nickjillings@2179 1368 obj.inputDOM.value = obj.specification.exitText;
nicholas@2535 1369 obj.inputDOM.addEventListener("change", obj);
nickjillings@2179 1370 exitText.children.push(obj);
nickjillings@2179 1371 exitText.childrenDOM.appendChild(obj.rootDOM);
nicholas@2535 1372
nickjillings@1370 1373 // Now we must build the interface Node
nicholas@2535 1374 this.interfaceDOM = new this.interfaceNode(this, specification.interfaces);
nicholas@2535 1375 this.interfaceDOM.build("Interface", "setup-interface", this.setupDOM.rootDOM);
nicholas@2535 1376
nickjillings@1370 1377 // Now build the Metrics selection node
nicholas@2535 1378 var metric = this.createGeneralNodeDOM("Session Metrics", "setup-metric", this.setupDOM);
nickjillings@1370 1379 metric.rootDOM.removeChild(metric.attributeDOM);
nickjillings@1370 1380 this.setupDOM.children.push(metric);
nickjillings@1370 1381 this.setupDOM.childrenDOM.appendChild(metric.rootDOM);
nickjillings@1370 1382 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1383 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 1384 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1385 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 1386 testXML = testXML.getAllElementsByTagName("metrics");
nicholas@2390 1387 var interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1388 while (interfaceXMLChild) {
nickjillings@1370 1389 var obj = {
nickjillings@1370 1390 input: document.createElement('input'),
nickjillings@1370 1391 root: document.createElement('div'),
nickjillings@1370 1392 text: document.createElement('span'),
nickjillings@1370 1393 specification: specification.metrics.enabled,
nicholas@2390 1394 name: interfaceXMLChild.getAttribute("name"),
nicholas@2535 1395 handleEvent: function () {
nicholas@2535 1396 for (var i = 0; i < this.specification.length; i++) {
nicholas@2535 1397 if (this.specification[i] == this.name) {
nickjillings@1370 1398 var options = this.specification;
nickjillings@1370 1399 if (this.input.checked == false) {
nicholas@2535 1400 if (i == options.length) {
nicholas@2535 1401 options = options.slice(0, i);
nicholas@2535 1402 } else {
nicholas@2535 1403 options = options.slice(0, i).concat(options.slice(i + 1));
nickjillings@1370 1404 }
nickjillings@1370 1405 } else {
nickjillings@1370 1406 return;
nickjillings@1370 1407 }
nickjillings@1370 1408 this.specification = options;
nickjillings@1370 1409 break;
nickjillings@1370 1410 }
nickjillings@1370 1411 }
nickjillings@1370 1412 if (this.input.checked) {
nickjillings@1370 1413 this.specification.push(this.name);
nickjillings@1370 1414 }
nickjillings@1370 1415 }
nickjillings@1370 1416 };
nickjillings@1370 1417 obj.root.className = "attribute";
nickjillings@1370 1418 obj.input.type = "checkbox";
nickjillings@1370 1419 obj.root.appendChild(obj.text);
nickjillings@1370 1420 obj.root.appendChild(obj.input);
nicholas@2390 1421 obj.text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1422 metric.children.push(obj);
nickjillings@1370 1423 metric.childrenDOM.appendChild(obj.root);
nicholas@2535 1424 for (var j = 0; j < specification.metrics.enabled.length; j++) {
nicholas@2535 1425 if (specification.metrics.enabled[j] == obj.name) {
nickjillings@1370 1426 obj.input.checked = true;
nickjillings@1370 1427 break;
nickjillings@1370 1428 }
nickjillings@1370 1429 }
nicholas@2390 1430 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1431 }
nicholas@2535 1432
nickjillings@1370 1433 // Now both before and after surveys
nicholas@2535 1434 if (specification.preTest == undefined) {
nickjillings@2194 1435 specification.preTest = new specification.surveyNode(specification);
nickjillings@1370 1436 specification.preTest.location = "pre";
nickjillings@1370 1437 }
nicholas@2535 1438 if (specification.postTest == undefined) {
nickjillings@2194 1439 specification.postTest = new specification.surveyNode(specification);
nickjillings@1370 1440 specification.postTest.location = "post";
nickjillings@1370 1441 }
nicholas@2535 1442 var surveyBefore = new this.surveyNode(this, specification.preTest, "Pre");
nicholas@2535 1443 var surveyAfter = new this.surveyNode(this, specification.postTest, "Post");
nickjillings@1370 1444 this.setupDOM.children.push(surveyBefore);
nickjillings@1370 1445 this.setupDOM.children.push(surveyAfter);
nickjillings@1370 1446 this.setupDOM.childrenDOM.appendChild(surveyBefore.rootDOM);
nickjillings@1370 1447 this.setupDOM.childrenDOM.appendChild(surveyAfter.rootDOM);
nicholas@2535 1448
nickjillings@1370 1449 // Add in the page creator button
nickjillings@1370 1450 this.addPage = {
nickjillings@1370 1451 root: document.createElement("button"),
nickjillings@1370 1452 parent: this,
nicholas@2535 1453 handleEvent: function () {
nickjillings@2194 1454 var pageObj = new specification.page(specification);
nickjillings@1370 1455 specification.pages.push(pageObj);
nicholas@2535 1456 var newPage = new this.parent.pageNode(this.parent, pageObj);
nicholas@2315 1457 document.getElementById("page-holder").appendChild(newPage.rootDOM);
nickjillings@1370 1458 this.parent.pages.push(newPage);
nickjillings@1370 1459 }
nickjillings@1370 1460 }
nickjillings@1370 1461 this.addPage.root.textContent = "Add Page";
nicholas@2315 1462 this.addPage.root.id = "new-page-button";
nicholas@2315 1463 this.addPage.root.style.float = "left";
nicholas@2535 1464 this.addPage.root.addEventListener("click", this.addPage, false);
nicholas@2535 1465
nicholas@2315 1466 var pageHolder = document.createElement("div");
nicholas@2535 1467 pageHolder.id = "page-holder";
nicholas@2315 1468 this.injectDOM.appendChild(pageHolder);
nicholas@2535 1469
nickjillings@1374 1470 // Build each page
nicholas@2535 1471 for (var page of specification.pages) {
nicholas@2535 1472 var newPage = new this.pageNode(this, page);
nicholas@2315 1473 pageHolder.appendChild(newPage.rootDOM);
nickjillings@1374 1474 this.pages.push(newPage);
nickjillings@1374 1475 }
nicholas@2535 1476
nicholas@2315 1477 this.injectDOM.appendChild(this.addPage.root);
nickjillings@1370 1478 }
nicholas@2535 1479
nicholas@2535 1480 this.interfaceNode = function (parent, rootObject) {
nickjillings@1375 1481 this.type = "interfaceNode";
nickjillings@1370 1482 this.rootDOM;
nickjillings@1370 1483 this.titleDOM;
nickjillings@1370 1484 this.attributeDOM;
nickjillings@1370 1485 this.attributes = [];
nickjillings@1370 1486 this.childrenDOM;
nickjillings@1370 1487 this.children = [];
nickjillings@1370 1488 this.buttonDOM;
nickjillings@1370 1489 this.parent = parent;
nickjillings@1370 1490 this.HTMLPoint;
nickjillings@1370 1491 this.specification = rootObject;
nickjillings@1370 1492 this.schema = specification.schema.getAllElementsByName("interface")[1];
nicholas@2535 1493
nicholas@2535 1494 this.createIOasAttr = function (name, specification, parent, type) {
nickjillings@1370 1495 this.root = document.createElement('div');
nickjillings@1370 1496 this.input = document.createElement("input");
nickjillings@1370 1497 this.name = name;
nickjillings@1370 1498 this.type = type;
nickjillings@1370 1499 this.parent = parent;
nickjillings@1370 1500 this.specification = specification;
nicholas@2535 1501 this.handleEvent = function (event) {
nicholas@2535 1502 for (var i = 0; i < this.specification.options.length; i++) {
nicholas@2535 1503 if (this.specification.options[i].name == this.name) {
nickjillings@1370 1504 var options = this.specification.options;
nickjillings@1370 1505 if (this.input.checked == false) {
nicholas@2535 1506 if (i == options.length) {
nicholas@2535 1507 options = options.slice(0, i);
nicholas@2535 1508 } else {
nicholas@2535 1509 options = options.slice(0, i).concat(options.slice(i + 1));
nickjillings@1370 1510 }
nickjillings@1370 1511 } else {
nickjillings@1370 1512 return;
nickjillings@1370 1513 }
nickjillings@1370 1514 this.specification.options = options;
nickjillings@1370 1515 break;
nickjillings@1370 1516 }
nickjillings@1370 1517 }
nickjillings@1370 1518 if (this.input.checked) {
nickjillings@1370 1519 var obj = {
nickjillings@1370 1520 name: this.name,
nickjillings@1370 1521 type: this.type
nickjillings@1370 1522 };
nickjillings@1370 1523 this.specification.options.push(obj);
nickjillings@1370 1524 }
nicholas@2535 1525 if (this.parent.HTMLPoint.id == "setup") {
nickjillings@1370 1526 // We've changed a global setting, must update all child 'interfaces' and disable them
nicholas@2535 1527 for (pages of convert.pages) {
nicholas@2535 1528 for (interface of pages.interfaces) {
nicholas@2535 1529 if (this.type == "check") {
nicholas@2535 1530 for (node of interface.children[0].attributes) {
nickjillings@1370 1531 if (node.name == this.name) {
nickjillings@1370 1532 if (this.input.checked) {
nickjillings@1370 1533 node.input.disabled = true;
nickjillings@1370 1534 node.input.checked = false;
nickjillings@1370 1535 } else {
nickjillings@1370 1536 node.input.disabled = false;
nickjillings@1370 1537 }
nickjillings@1370 1538 break;
nickjillings@1370 1539 }
nickjillings@1370 1540 }
nicholas@2535 1541 } else if (this.type == "show") {
nicholas@2535 1542 for (node of interface.children[1].attributes) {
nickjillings@1370 1543 if (node.name == this.name) {
nickjillings@1370 1544 if (this.input.checked) {
nickjillings@1370 1545 node.input.disabled = true;
nickjillings@1370 1546 } else {
nickjillings@1370 1547 node.input.disabled = false;
nickjillings@1370 1548 }
nickjillings@1370 1549 break;
nickjillings@1370 1550 }
nickjillings@1370 1551 }
nickjillings@1370 1552 }
nickjillings@1370 1553 }
nickjillings@1370 1554 }
nickjillings@1370 1555 }
nickjillings@1370 1556 };
nicholas@2535 1557 this.findIndex = function (element, index, array) {
nickjillings@1370 1558 if (element.name == this.name)
nickjillings@1370 1559 return true;
nickjillings@1370 1560 else
nickjillings@1370 1561 return false;
nickjillings@1370 1562 };
nicholas@2535 1563 this.findNode = function (element, index, array) {
nickjillings@1370 1564 if (element.name == this.name)
nickjillings@1370 1565 return true;
nickjillings@1370 1566 else
nickjillings@1370 1567 return false;
nickjillings@1370 1568 };
nickjillings@1370 1569 this.input.type = "checkbox";
nicholas@2535 1570 this.input.setAttribute("name", name);
nicholas@2535 1571 this.input.addEventListener("change", this, false);
nickjillings@1370 1572 this.root.appendChild(this.input);
nickjillings@1370 1573 this.root.className = "attribute";
nickjillings@1370 1574 return this;
nickjillings@1370 1575 }
nicholas@2535 1576
nicholas@2535 1577 this.build = function (name, id, parent) {
nicholas@2535 1578 var obj = this.parent.createGeneralNodeDOM(name, id, parent);
nicholas@2535 1579
nickjillings@1370 1580 this.rootDOM = obj.rootDOM;
nickjillings@1370 1581 this.titleDOM = obj.titleDOM;
nickjillings@1370 1582 this.attributeDOM = obj.attributeDOM;
nickjillings@1370 1583 this.childrenDOM = obj.childrenDOM;
nickjillings@1370 1584 this.buttonDOM = obj.buttonsDOM;
nickjillings@1370 1585 this.HTMLPoint = parent;
nickjillings@1370 1586 this.rootDOM.removeChild(this.attributeDOM);
nicholas@2243 1587 if (parent.id != "setup") {
nicholas@2243 1588 // Put in the <title> node:
nicholas@2243 1589 this.titleNode = {
nicholas@2243 1590 root: document.createElement("div"),
nicholas@2243 1591 label: document.createElement("span"),
nicholas@2243 1592 input: document.createElement("input"),
nicholas@2243 1593 parent: this,
nicholas@2535 1594 handleEvent: function (event) {
nicholas@2243 1595 this.parent.specification.title = event.currentTarget.value;
nicholas@2243 1596 }
nicholas@2243 1597 }
nicholas@2549 1598 this.titleNode.label.textContent = "Presented Axis Title:";
nicholas@2243 1599 this.titleNode.root.className = "node-children";
nicholas@2243 1600 this.titleNode.root.appendChild(this.titleNode.label);
nicholas@2243 1601 this.titleNode.root.appendChild(this.titleNode.input);
nicholas@2535 1602 this.titleNode.input.addEventListener("change", this.titleNode, false);
nicholas@2243 1603 this.titleNode.input.value = this.specification.title;
nicholas@2243 1604 this.children.push(this.titleNode);
nicholas@2243 1605 this.childrenDOM.appendChild(this.titleNode.root);
nicholas@2549 1606 // Set the interface-name attribute
nicholas@2549 1607 this.axisName = {
nicholas@2549 1608 root: document.createElement("div"),
nicholas@2549 1609 label: document.createElement("span"),
nicholas@2549 1610 input: document.createElement("input"),
nicholas@2549 1611 parent: this,
nicholas@2549 1612 handleEvent: function (event) {
nicholas@2549 1613 this.parent.specification.name = event.currentTarget.value;
nicholas@2549 1614 }
nicholas@2549 1615 }
nicholas@2549 1616 this.axisName.label.textContent = "Saved Axis Name (no spaces):";
nicholas@2549 1617 this.axisName.root.className = "node-children";
nicholas@2549 1618 this.axisName.root.appendChild(this.axisName.label);
nicholas@2549 1619 this.axisName.root.appendChild(this.axisName.input);
nicholas@2549 1620 this.axisName.input.addEventListener("change", this.axisName, false);
nicholas@2549 1621 this.axisName.input.value = this.specification.name;
nicholas@2549 1622 this.children.push(this.axisName);
nicholas@2549 1623 this.childrenDOM.appendChild(this.axisName.root);
nicholas@2243 1624 }
nicholas@2535 1625
nickjillings@1370 1626 // Put in the check / show options as individual children
nicholas@2535 1627 var checks = this.parent.createGeneralNodeDOM("Checks", "setup-interface-checks", this);
nickjillings@1370 1628
nickjillings@1370 1629 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1630 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1631 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1632 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1633 testXML = testXML.getAllElementsByTagName("checks");
nicholas@2390 1634 var interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1635 while (interfaceXMLChild) {
nicholas@2535 1636 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "check");
nicholas@2535 1637 for (var option of this.specification.options) {
nicholas@2535 1638 if (option.name == obj.name) {
nickjillings@1370 1639 obj.input.checked = true;
nickjillings@1370 1640 break;
nickjillings@1370 1641 }
nickjillings@1370 1642 }
nickjillings@1370 1643 if (parent.id != "setup") {
nicholas@2535 1644 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1645 if (node != undefined) {
nickjillings@1381 1646 if (node.input.checked) {
nickjillings@1381 1647 obj.input.checked = false;
nickjillings@1381 1648 obj.input.disabled = true;
nickjillings@1381 1649 }
nickjillings@1370 1650 }
nickjillings@1370 1651 }
nickjillings@1370 1652 var text = document.createElement('span');
nicholas@2390 1653 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1654 obj.root.appendChild(text);
nickjillings@1370 1655 checks.attributeDOM.appendChild(obj.root);
nickjillings@1370 1656 checks.attributes.push(obj);
nicholas@2390 1657 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1658 }
nickjillings@1370 1659 this.children.push(checks);
nickjillings@1370 1660 this.childrenDOM.appendChild(checks.rootDOM);
nickjillings@1370 1661
nicholas@2535 1662 var show = this.parent.createGeneralNodeDOM("Show", "setup-interface-show", this);
nickjillings@1370 1663 interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1664 checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1665 testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1666 interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1667 testXML = testXML.getAllElementsByTagName("show");
nicholas@2390 1668 interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1669 while (interfaceXMLChild) {
nicholas@2535 1670 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "show");
nicholas@2535 1671 for (var option of this.specification.options) {
nicholas@2535 1672 if (option.name == obj.name) {
nickjillings@1370 1673 obj.input.checked = true;
nickjillings@1370 1674 break;
nickjillings@1370 1675 }
nickjillings@1370 1676 }
nickjillings@1370 1677 if (parent.id != "setup") {
nicholas@2535 1678 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1679 if (node != undefined) {
nickjillings@1381 1680 if (node.input.checked) {
nickjillings@1381 1681 obj.input.checked = false;
nickjillings@1381 1682 obj.input.disabled = true;
nickjillings@1381 1683 }
nickjillings@1370 1684 }
nickjillings@1370 1685 }
nickjillings@1370 1686 var text = document.createElement('span');
nicholas@2390 1687 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1688 obj.root.appendChild(text);
nickjillings@1370 1689 show.attributeDOM.appendChild(obj.root);
nickjillings@1370 1690 show.attributes.push(obj);
nicholas@2390 1691 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1692 }
nickjillings@1370 1693 this.children.push(show);
nickjillings@1370 1694 this.childrenDOM.appendChild(show.rootDOM);
nicholas@2535 1695
nicholas@2535 1696 if (parent.id == "setup") {} else {
nicholas@2535 1697 var nameAttr = this.parent.convertAttributeToDOM(this, specification.schema.getAllElementsByName("name")[0]);
nickjillings@1370 1698 this.attributeDOM.appendChild(nameAttr.holder);
nickjillings@1370 1699 this.attributes.push(nameAttr);
nicholas@2535 1700 var scales = new this.scalesNode(this, this.specification);
nickjillings@1385 1701 this.children.push(scales);
nickjillings@1385 1702 this.childrenDOM.appendChild(scales.rootDOM);
nickjillings@1370 1703 }
nicholas@2535 1704 if (parent != undefined) {
nickjillings@1370 1705 parent.appendChild(this.rootDOM);
nickjillings@1370 1706 }
nickjillings@1370 1707 }
nicholas@2535 1708
nicholas@2535 1709 this.scalesNode = function (parent, rootObject) {
nickjillings@1385 1710 this.type = "scalesNode";
nickjillings@1385 1711 this.rootDOM = document.createElement("div");
nickjillings@1385 1712 this.titleDOM = document.createElement("span");
nickjillings@1385 1713 this.attributeDOM = document.createElement("div");
nickjillings@1385 1714 this.attributes = [];
nickjillings@1385 1715 this.childrenDOM = document.createElement("div");
nickjillings@1385 1716 this.children = [];
nickjillings@1385 1717 this.buttonDOM = document.createElement("div");
nickjillings@1385 1718 this.parent = parent;
nickjillings@1385 1719 this.specification = rootObject;
nickjillings@1385 1720 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1385 1721 this.rootDOM.className = "node";
nickjillings@1385 1722
nickjillings@1385 1723 var titleDiv = document.createElement('div');
nickjillings@1385 1724 titleDiv.className = "node-title";
nickjillings@1385 1725 this.titleDOM.className = "node-title";
nickjillings@1385 1726 this.titleDOM.textContent = "Interface Scales";
nickjillings@1385 1727 titleDiv.appendChild(this.titleDOM);
nickjillings@1385 1728
nickjillings@1385 1729 this.attributeDOM.className = "node-attributes";
nickjillings@1385 1730 this.childrenDOM.className = "node-children";
nickjillings@1385 1731 this.buttonDOM.className = "node-buttons";
nickjillings@1385 1732
nickjillings@1385 1733 this.rootDOM.appendChild(titleDiv);
nickjillings@1385 1734 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1385 1735 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1385 1736 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1737
nickjillings@1385 1738 this.editButton = {
nickjillings@1385 1739 button: document.createElement("button"),
nickjillings@1385 1740 parent: this,
nicholas@2535 1741 handleEvent: function (event) {
nickjillings@1385 1742 popupObject.show();
nickjillings@1385 1743 popupObject.postNode(popupStateNodes.state[6]);
nicholas@2535 1744 popupStateNodes.state[6].generate(this.parent.specification, this.parent);
nickjillings@1385 1745 }
nickjillings@1385 1746 };
nickjillings@1385 1747 this.editButton.button.textContent = "Edit Scales/Markers";
nicholas@2535 1748 this.editButton.button.addEventListener("click", this.editButton, false);
nickjillings@1385 1749 this.buttonDOM.appendChild(this.editButton.button);
nickjillings@1385 1750 }
nickjillings@1370 1751 }
nicholas@2535 1752
nicholas@2535 1753 this.surveyNode = function (parent, rootObject, location) {
nickjillings@1375 1754 this.type = "surveyNode";
nickjillings@1370 1755 this.rootDOM = document.createElement("div");
nickjillings@1370 1756 this.titleDOM = document.createElement("span");
nickjillings@1370 1757 this.attributeDOM = document.createElement("div");
nickjillings@1370 1758 this.attributes = [];
nickjillings@1370 1759 this.childrenDOM = document.createElement("div");
nickjillings@1370 1760 this.children = [];
nickjillings@1370 1761 this.buttonDOM = document.createElement("div");
nickjillings@1370 1762 this.parent = parent;
nickjillings@1370 1763 this.specification = rootObject;
nickjillings@1370 1764 this.schema = specification.schema.getAllElementsByName("survey")[1];
nickjillings@1370 1765 this.rootDOM.className = "node";
nickjillings@1370 1766
nickjillings@1370 1767 var titleDiv = document.createElement('div');
nickjillings@1370 1768 titleDiv.className = "node-title";
nickjillings@1370 1769 this.titleDOM.className = "node-title";
nickjillings@1370 1770 this.titleDOM.textContent = "Survey";
nickjillings@1370 1771 titleDiv.appendChild(this.titleDOM);
nicholas@2535 1772
nickjillings@1370 1773 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1774 var locationAttr = document.createElement("span");
nickjillings@1370 1775 this.attributeDOM.appendChild(locationAttr);
nickjillings@1370 1776 if (location == "Pre" || location == "pre") {
nickjillings@1370 1777 locationAttr.textContent = "Location: Before";
nickjillings@1370 1778 } else {
nickjillings@1370 1779 locationAttr.textContent = "Location: After";
nickjillings@1370 1780 }
nickjillings@1370 1781 this.childrenDOM.className = "node-children";
nickjillings@1370 1782 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1783
nickjillings@1370 1784 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1785 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1786 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1787 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1788
nicholas@2535 1789 this.surveyEntryNode = function (parent, rootObject) {
nickjillings@1375 1790 this.type = "surveyEntryNode";
nickjillings@1370 1791 this.rootDOM = document.createElement("div");
nickjillings@1370 1792 this.titleDOM = document.createElement("span");
nickjillings@1370 1793 this.attributeDOM = document.createElement("div");
nickjillings@1370 1794 this.attributes = [];
nickjillings@1370 1795 this.childrenDOM = document.createElement("div");
nickjillings@1370 1796 this.children = [];
nickjillings@1370 1797 this.buttonDOM = document.createElement("div");
nickjillings@1370 1798 this.parent = parent;
nickjillings@1370 1799 this.specification = rootObject;
nickjillings@1370 1800 this.schema = specification.schema.getAllElementsByName("surveyentry")[1];
nickjillings@1370 1801
nickjillings@1370 1802 this.rootDOM.className = "node";
nickjillings@1370 1803 this.rootDOM.style.minWidth = "50%";
nickjillings@1370 1804
nickjillings@1370 1805 var titleDiv = document.createElement('div');
nickjillings@1370 1806 titleDiv.className = "node-title";
nickjillings@1370 1807 this.titleDOM.className = "node-title";
nickjillings@1370 1808 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 1809
nickjillings@1370 1810 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1811 this.childrenDOM.className = "node-children";
nickjillings@1370 1812 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1813
nickjillings@1370 1814 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1815 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1816 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1817 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1818
nicholas@2535 1819 this.build = function () {
nickjillings@1375 1820 this.attributeDOM.innerHTML = null;
nickjillings@1375 1821 this.childrenDOM.innerHTML = null;
nickjillings@1375 1822 var statementRoot = document.createElement("div");
nickjillings@1375 1823 var statement = document.createElement("span");
nicholas@2535 1824 statement.textContent = "Statement / Question: " + this.specification.statement;
nickjillings@1375 1825 statementRoot.appendChild(statement);
nickjillings@1375 1826 this.children.push(statementRoot);
nickjillings@1375 1827 this.childrenDOM.appendChild(statementRoot);
nicholas@2535 1828 switch (this.specification.type) {
nickjillings@1375 1829 case "statement":
nickjillings@1375 1830 this.titleDOM.textContent = "Statement";
nickjillings@1375 1831 break;
nickjillings@1375 1832 case "question":
nickjillings@1375 1833 this.titleDOM.textContent = "Question";
nicholas@2535 1834 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1835 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1836 var boxsize = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("boxsize")[0]);
nickjillings@1375 1837 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1838 this.attributes.push(id);
nickjillings@1375 1839 this.attributeDOM.appendChild(mandatory.holder);
nickjillings@1375 1840 this.attributes.push(mandatory);
nickjillings@1375 1841 this.attributeDOM.appendChild(boxsize.holder);
nickjillings@1375 1842 this.attributes.push(boxsize);
nickjillings@1375 1843 break;
nickjillings@1375 1844 case "number":
nickjillings@1375 1845 this.titleDOM.textContent = "Number";
nicholas@2535 1846 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1847 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1848 var min = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("min")[0]);
nicholas@2535 1849 var max = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("max")[0]);
nickjillings@1375 1850 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1851 this.attributes.push(id);
nickjillings@1375 1852 this.attributeDOM.appendChild(min.holder);
nickjillings@1375 1853 this.attributes.push(min);
nickjillings@1375 1854 this.attributeDOM.appendChild(max.holder);
nickjillings@1375 1855 this.attributes.push(max);
nickjillings@1375 1856 break;
nickjillings@1375 1857 case "checkbox":
nickjillings@1375 1858 this.titleDOM.textContent = "Checkbox";
nicholas@2535 1859 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1860 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1861 this.attributes.push(id);
nickjillings@1375 1862 break;
nickjillings@1375 1863 case "radio":
nickjillings@1375 1864 this.titleDOM.textContent = "Radio";
nicholas@2535 1865 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1866 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1867 this.attributes.push(id);
nickjillings@1375 1868 break;
nickjillings@1375 1869 }
nickjillings@1370 1870 }
nickjillings@1375 1871 this.build();
nicholas@2535 1872
nickjillings@1370 1873 this.editNode = {
nickjillings@1370 1874 root: document.createElement("button"),
nickjillings@1370 1875 parent: this,
nicholas@2535 1876 handleEvent: function () {
nickjillings@1370 1877 popupObject.show();
nicholas@2535 1878 popupStateNodes.state[5].generate(this.parent.specification, this.parent);
nickjillings@1370 1879 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1880 }
nickjillings@1370 1881 }
nickjillings@1370 1882 this.editNode.root.textContent = "Edit Entry";
nicholas@2535 1883 this.editNode.root.addEventListener("click", this.editNode, false);
nickjillings@1370 1884 this.buttonDOM.appendChild(this.editNode.root);
nicholas@2535 1885
nickjillings@1370 1886 this.deleteNode = {
nickjillings@1370 1887 root: document.createElement("button"),
nickjillings@1370 1888 parent: this,
nicholas@2535 1889 handleEvent: function () {
nickjillings@1370 1890 var optionList = this.parent.parent.specification.options;
nickjillings@1370 1891 var childList = this.parent.parent.children;
nicholas@2535 1892 for (var i = 0; i < this.parent.parent.specification.options.length; i++) {
nickjillings@1370 1893 var option = this.parent.parent.specification.options[i];
nicholas@2535 1894 if (option == this.parent.specification) {
nickjillings@1370 1895 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nicholas@2535 1896 if (i == this.parent.parent.specification.options.length - 1) {
nicholas@2535 1897 optionList = optionList.slice(0, i);
nicholas@2535 1898 childList = childList.slice(0, i);
nicholas@2535 1899 } else {
nicholas@2535 1900 optionList = optionList.slice(0, i).concat(optionList.slice(i + 1));
nicholas@2535 1901 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 1902 }
nickjillings@1370 1903 this.parent.parent.specification.options = optionList;
nickjillings@1370 1904 this.parent.parent.children = childList;
nickjillings@1370 1905 }
nickjillings@1370 1906 }
nickjillings@1370 1907 }
nickjillings@1370 1908 }
nickjillings@1370 1909 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 1910 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 1911 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 1912
nicholas@2535 1913 this.moveToPosition = function (new_index) {
nicholas@2535 1914 new_index = Math.min(new_index, this.parent.children.length);
nicholas@2535 1915 var curr_index = this.parent.children.findIndex(function (elem) {
nicholas@2535 1916 if (elem == this) {
nicholas@2535 1917 return true;
nicholas@2535 1918 } else {
nicholas@2535 1919 return false;
nicholas@2535 1920 }
nicholas@2535 1921 }, this);
n@2416 1922 // Split at the current location to remove the node and shift all the children up
nicholas@2535 1923 var tail = this.parent.children.splice(curr_index + 1);
n@2416 1924 this.parent.children.pop();
n@2416 1925 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1926
n@2416 1927 //Split at the new location and insert the node
n@2416 1928 tail = this.parent.children.splice(new_index);
n@2416 1929 this.parent.children.push(this);
n@2416 1930 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1931
n@2416 1932 // Re-build the specification
n@2416 1933 this.parent.specification.options = [];
n@2416 1934 this.parent.childrenDOM.innerHTML = "";
n@2416 1935 for (var obj of this.parent.children) {
n@2416 1936 this.parent.specification.options.push(obj.specification);
n@2416 1937 this.parent.childrenDOM.appendChild(obj.rootDOM);
n@2416 1938 }
nicholas@2535 1939 this.parent.children.forEach(function (obj, index) {
n@2420 1940 obj.moveButtons.disable(index);
n@2420 1941 });
n@2414 1942 }
nicholas@2535 1943
n@2420 1944 this.moveButtons = {
n@2420 1945 root_up: document.createElement("button"),
n@2420 1946 root_down: document.createElement("button"),
n@2420 1947 parent: this,
nicholas@2535 1948 handleEvent: function (event) {
n@2420 1949 var index = this.parent.parent.children.indexOf(this.parent);
n@2420 1950 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 1951 index = Math.max(index - 1, 0);
n@2420 1952 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 1953 index = Math.min(index + 1, this.parent.parent.children.length - 1);
n@2420 1954 }
n@2420 1955 this.parent.moveToPosition(index);
n@2420 1956 this.disable(index);
n@2420 1957 },
nicholas@2535 1958 disable: function (index) {
n@2420 1959 if (index == 0) {
n@2420 1960 this.root_up.disabled = true;
n@2420 1961 } else {
n@2420 1962 this.root_up.disabled = false;
n@2420 1963 }
nicholas@2535 1964 if (index == this.parent.parent.children.length - 1) {
n@2420 1965 this.root_down.disabled = true;
n@2420 1966 } else {
n@2420 1967 this.root_down.disabled = false;
n@2420 1968 }
n@2420 1969 }
n@2420 1970 }
nicholas@2535 1971 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 1972 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 1973 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 1974 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2420 1975 this.moveButtons.root_up.textContent = "Move Up";
n@2420 1976 this.moveButtons.root_down.textContent = "Move Down";
n@2420 1977 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2420 1978 this.buttonDOM.appendChild(this.moveButtons.root_down);
nickjillings@1370 1979 }
nickjillings@1370 1980 this.addNode = {
nickjillings@1370 1981 root: document.createElement("button"),
nickjillings@1370 1982 parent: this,
nicholas@2535 1983 handleEvent: function () {
nickjillings@2194 1984 var newNode = new this.parent.specification.OptionNode(this.parent.specification);
nickjillings@1370 1985 this.parent.specification.options.push(newNode);
nickjillings@1370 1986 popupObject.show();
nicholas@2535 1987 popupStateNodes.state[5].generate(newNode, this.parent);
nickjillings@1370 1988 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1989 }
nickjillings@1370 1990 }
nickjillings@1370 1991 this.addNode.root.textContent = "Add Survey Entry";
nicholas@2535 1992 this.addNode.root.addEventListener("click", this.addNode, false);
nickjillings@1370 1993 this.buttonDOM.appendChild(this.addNode.root);
nicholas@2535 1994
nicholas@2535 1995 for (var option of this.specification.options) {
nicholas@2535 1996 var newNode = new this.surveyEntryNode(this, option);
nickjillings@1370 1997 this.children.push(newNode);
nickjillings@1370 1998 this.childrenDOM.appendChild(newNode.rootDOM);
nickjillings@1370 1999 }
nicholas@2535 2000
nicholas@2535 2001 this.children.forEach(function (obj, index) {
n@2420 2002 obj.moveButtons.disable(index);
n@2420 2003 });
nickjillings@1370 2004 }
nicholas@2535 2005
nicholas@2535 2006 this.pageNode = function (parent, rootObject) {
nickjillings@1375 2007 this.type = "pageNode";
nickjillings@1370 2008 this.rootDOM = document.createElement("div");
nickjillings@1370 2009 this.titleDOM = document.createElement("span");
nickjillings@1370 2010 this.attributeDOM = document.createElement("div");
nickjillings@1370 2011 this.attributes = [];
nickjillings@1370 2012 this.childrenDOM = document.createElement("div");
nickjillings@1370 2013 this.children = [];
nickjillings@1370 2014 this.buttonDOM = document.createElement("div");
nickjillings@1370 2015 this.parent = parent;
nickjillings@1370 2016 this.specification = rootObject;
nickjillings@1370 2017 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1370 2018 this.rootDOM.className = "node";
nickjillings@1370 2019
nickjillings@1370 2020 var titleDiv = document.createElement('div');
nickjillings@1370 2021 titleDiv.className = "node-title";
nickjillings@1370 2022 this.titleDOM.className = "node-title";
nickjillings@1370 2023 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2024 titleDiv.appendChild(this.titleDOM);
nicholas@2535 2025
nickjillings@1370 2026 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2027 this.childrenDOM.className = "node-children";
nickjillings@1370 2028 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2029
nickjillings@1370 2030 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2031 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2032 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2033 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2034
nickjillings@1370 2035 // Do the comment prefix node
nicholas@2535 2036 var cpn = this.parent.createGeneralNodeDOM("Comment Prefix", "" + this.specification.id + "-commentprefix", this.parent);
nickjillings@1370 2037 cpn.rootDOM.removeChild(cpn.attributeDOM);
nickjillings@1370 2038 var obj = {
nickjillings@1370 2039 root: document.createElement("div"),
nickjillings@1370 2040 input: document.createElement("input"),
nickjillings@1370 2041 parent: this,
nicholas@2535 2042 handleEvent: function () {
nickjillings@1370 2043 this.parent.specification.commentBoxPrefix = event.currentTarget.value;
nickjillings@1370 2044 }
nickjillings@1370 2045 }
nickjillings@1370 2046 cpn.children.push(obj);
nickjillings@1370 2047 cpn.childrenDOM.appendChild(obj.root);
nickjillings@1370 2048 obj.root.appendChild(obj.input);
nicholas@2535 2049 obj.input.addEventListener("change", obj, false);
nickjillings@1370 2050 obj.input.value = this.specification.commentBoxPrefix;
nickjillings@1370 2051 this.childrenDOM.appendChild(cpn.rootDOM);
nickjillings@1370 2052 this.children.push(cpn);
nicholas@2535 2053
nickjillings@1370 2054 // Now both before and after surveys
nicholas@2535 2055 if (this.specification.preTest == undefined) {
nickjillings@2194 2056 this.specification.preTest = new specification.surveyNode(specification);
nickjillings@1370 2057 this.specification.preTest.location = "pre";
nickjillings@1370 2058 }
nicholas@2535 2059 if (this.specification.postTest == undefined) {
nickjillings@2194 2060 this.specification.postTest = new specification.surveyNode(specification);
nickjillings@1370 2061 this.specification.postTest.location = "post";
nickjillings@1370 2062 }
nicholas@2535 2063 var surveyBefore = new this.parent.surveyNode(this, this.specification.preTest, "Pre");
nicholas@2535 2064 var surveyAfter = new this.parent.surveyNode(this, this.specification.postTest, "Post");
nickjillings@1370 2065 this.children.push(surveyBefore);
nickjillings@1370 2066 this.children.push(surveyAfter);
nickjillings@1370 2067 this.childrenDOM.appendChild(surveyBefore.rootDOM);
nickjillings@1370 2068 this.childrenDOM.appendChild(surveyAfter.rootDOM);
nicholas@2535 2069
nickjillings@1370 2070 // Build the attributes
nickjillings@1370 2071 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2072 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2073 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2074 var attrObject = this.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2075 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2076 this.attributes.push(attrObject);
nickjillings@1370 2077 }
nicholas@2535 2078
nickjillings@1370 2079 this.interfaces = [];
nicholas@2535 2080
nicholas@2535 2081 this.getAudioElements = function () {
n@2421 2082 var array = [];
nicholas@2535 2083 for (var i = 0; i < this.children.length; i++) {
n@2421 2084 if (this.children[i].type == "audioElementNode") {
n@2421 2085 array[array.length] = this.children[i];
n@2421 2086 }
n@2421 2087 }
n@2421 2088 return array;
n@2421 2089 }
nicholas@2535 2090
nicholas@2535 2091 this.redrawChildren = function () {
n@2421 2092 this.childrenDOM.innerHTML = "";
nicholas@2535 2093 for (var child of this.children) {
n@2421 2094 this.childrenDOM.appendChild(child.rootDOM);
n@2421 2095 }
n@2421 2096 }
nicholas@2535 2097
nicholas@2535 2098 this.audioElementNode = function (parent, rootObject) {
nickjillings@1375 2099 this.type = "audioElementNode";
nickjillings@1370 2100 this.rootDOM = document.createElement("div");
nickjillings@1370 2101 this.titleDOM = document.createElement("span");
nickjillings@1370 2102 this.attributeDOM = document.createElement("div");
nickjillings@1370 2103 this.attributes = [];
nickjillings@1370 2104 this.childrenDOM = document.createElement("div");
nickjillings@1370 2105 this.children = [];
nickjillings@1370 2106 this.buttonDOM = document.createElement("div");
nickjillings@1370 2107 this.parent = parent;
nickjillings@1370 2108 this.specification = rootObject;
nickjillings@1370 2109 this.schema = specification.schema.getAllElementsByName("audioelement")[0];
nickjillings@1370 2110 this.rootDOM.className = "node";
nickjillings@1370 2111
nickjillings@1370 2112 var titleDiv = document.createElement('div');
nickjillings@1370 2113 titleDiv.className = "node-title";
nickjillings@1370 2114 this.titleDOM.className = "node-title";
nickjillings@1370 2115 this.titleDOM.textContent = "Audio Element";
nickjillings@1370 2116 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2117
nickjillings@1370 2118 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2119 this.childrenDOM.className = "node-children";
nickjillings@1370 2120 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2121
nickjillings@1370 2122 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2123 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2124 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2125 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2126
nickjillings@1370 2127 // Build the attributes
nickjillings@1370 2128 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2129 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2130 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2131 var attrObject = this.parent.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2132 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2133 this.attributes.push(attrObject);
nickjillings@1370 2134 }
nicholas@2535 2135
nickjillings@1370 2136 this.deleteNode = {
nickjillings@1370 2137 root: document.createElement("button"),
nickjillings@1370 2138 parent: this,
nicholas@2535 2139 handleEvent: function () {
nicholas@2535 2140 var i = this.parent.parent.specification.audioElements.findIndex(this.findNode, this);
nickjillings@1370 2141 if (i >= 0) {
nickjillings@1370 2142 var aeList = this.parent.parent.specification.audioElements;
nicholas@2535 2143 if (i < aeList.length - 1) {
nicholas@2535 2144 aeList = aeList.slice(0, i).concat(aeList.slice(i + 1));
nickjillings@1370 2145 } else {
nicholas@2535 2146 aeList = aeList.slice(0, i);
nickjillings@1370 2147 }
nickjillings@1370 2148 }
nicholas@2535 2149 i = this.parent.parent.children.findIndex(function (element, index, array) {
nickjillings@1370 2150 if (element == this.parent)
nickjillings@1370 2151 return true;
nickjillings@1370 2152 else
nickjillings@1370 2153 return false;
nicholas@2535 2154 }, this);
nickjillings@1370 2155 if (i >= 0) {
nickjillings@1370 2156 var childList = this.parent.children;
nicholas@2535 2157 if (i < aeList.length - 1) {
nicholas@2535 2158 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 2159 } else {
nicholas@2535 2160 childList = childList.slice(0, i);
nickjillings@1370 2161 }
nickjillings@1370 2162 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nickjillings@1370 2163 }
nickjillings@1370 2164 },
nicholas@2535 2165 findNode: function (element, index, array) {
nickjillings@1370 2166 if (element == this.parent.specification)
nickjillings@1370 2167 return true;
nickjillings@1370 2168 else
nickjillings@1370 2169 return false;
nickjillings@1370 2170 }
nickjillings@1370 2171 }
nickjillings@1370 2172 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 2173 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 2174 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 2175
n@2421 2176 this.moveButtons = {
n@2421 2177 root_up: document.createElement("button"),
n@2421 2178 root_down: document.createElement("button"),
n@2421 2179 parent: this,
nicholas@2535 2180 handleEvent: function (event) {
n@2421 2181 var index = this.parent.parent.getAudioElements().indexOf(this.parent);
n@2421 2182 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 2183 index = Math.max(index - 1, 0);
n@2421 2184 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 2185 index = Math.min(index + 1, this.parent.parent.getAudioElements().length - 1);
n@2421 2186 }
n@2421 2187 this.parent.moveToPosition(index);
n@2421 2188 this.disable(index);
n@2421 2189 },
nicholas@2535 2190 disable: function (index) {
n@2421 2191 if (index == 0) {
n@2421 2192 this.root_up.disabled = true;
n@2421 2193 } else {
n@2421 2194 this.root_up.disabled = false;
n@2421 2195 }
nicholas@2535 2196 if (index == this.parent.parent.getAudioElements().length - 1) {
n@2421 2197 this.root_down.disabled = true;
n@2421 2198 } else {
n@2421 2199 this.root_down.disabled = false;
n@2421 2200 }
n@2421 2201 }
n@2421 2202 }
nicholas@2535 2203 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 2204 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 2205 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 2206 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2421 2207 this.moveButtons.root_up.textContent = "Move Up";
n@2421 2208 this.moveButtons.root_down.textContent = "Move Down";
n@2421 2209 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2421 2210 this.buttonDOM.appendChild(this.moveButtons.root_down);
nicholas@2535 2211
nicholas@2535 2212 this.moveToPosition = function (new_index) {
nicholas@2535 2213
n@2421 2214 // Get the zero-th Object
n@2421 2215 var zero_object = this.parent.getAudioElements()[0];
n@2421 2216 var parent_children_root_index = this.parent.children.indexOf(zero_object);
n@2421 2217 // splice out the array for processing
n@2421 2218 var process_array = this.parent.children.splice(parent_children_root_index);
nicholas@2535 2219
nicholas@2535 2220
n@2421 2221 new_index = Math.min(new_index, process_array.length);
nicholas@2535 2222 var curr_index = process_array.findIndex(function (elem) {
nicholas@2535 2223 if (elem == this) {
nicholas@2535 2224 return true;
nicholas@2535 2225 } else {
nicholas@2535 2226 return false;
nicholas@2535 2227 }
nicholas@2535 2228 }, this);
nicholas@2535 2229
n@2421 2230 // Split at the current location to remove the node and shift all the children up
nicholas@2535 2231 var tail = process_array.splice(curr_index + 1);
n@2421 2232 process_array.pop();
n@2421 2233 process_array = process_array.concat(tail);
nicholas@2535 2234
n@2421 2235 //Split at the new location and insert the node
n@2421 2236 tail = process_array.splice(new_index);
n@2421 2237 process_array.push(this);
n@2421 2238 process_array = process_array.concat(tail);
nicholas@2535 2239
n@2421 2240 // Re-attach to the parent.children
n@2421 2241 this.parent.children = this.parent.children.concat(process_array);
nicholas@2535 2242
n@2421 2243 // Re-build the specification
n@2421 2244 this.parent.specification.audioElements = [];
n@2421 2245 for (var obj of process_array) {
n@2421 2246 this.parent.specification.audioElements.push(obj.specification);
n@2421 2247 }
n@2421 2248 this.parent.redrawChildren();
nicholas@2535 2249
nicholas@2535 2250 process_array.forEach(function (obj, index) {
n@2421 2251 obj.moveButtons.disable(index);
n@2421 2252 });
nicholas@2535 2253
n@2421 2254 }
nickjillings@1370 2255 }
nicholas@2535 2256
nicholas@2535 2257 this.commentQuestionNode = function (parent, rootObject) {
nickjillings@1375 2258 this.type = "commentQuestionNode";
nickjillings@1370 2259 this.rootDOM = document.createElement("div");
nickjillings@1370 2260 this.titleDOM = document.createElement("span");
nickjillings@1370 2261 this.attributeDOM = document.createElement("div");
nickjillings@1370 2262 this.attributes = [];
nickjillings@1370 2263 this.childrenDOM = document.createElement("div");
nickjillings@1370 2264 this.children = [];
nickjillings@1370 2265 this.buttonDOM = document.createElement("div");
nickjillings@1370 2266 this.parent = parent;
nickjillings@1370 2267 this.specification = rootObject;
nickjillings@1370 2268 this.schema = specification.schema.getAllElementsByName("page")[0];
n@2421 2269 this.rootDOM.className = "node audio-element";
nickjillings@1370 2270
nickjillings@1370 2271 var titleDiv = document.createElement('div');
nickjillings@1370 2272 titleDiv.className = "node-title";
nickjillings@1370 2273 this.titleDOM.className = "node-title";
nickjillings@1370 2274 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2275 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2276
nickjillings@1370 2277 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2278 this.childrenDOM.className = "node-children";
nickjillings@1370 2279 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2280
nickjillings@1370 2281 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2282 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2283 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2284 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2285
nickjillings@1370 2286 }
nicholas@2535 2287
nickjillings@1374 2288 // Build the components
nickjillings@1310 2289 if (this.specification.interfaces.length == 0) {
nickjillings@2194 2290 this.specification.interfaces.push(new specification.interfaceNode(specification));
nickjillings@1310 2291 }
nicholas@2535 2292 for (var interfaceObj of this.specification.interfaces) {
nicholas@2535 2293 var newInterface = new this.parent.interfaceNode(this.parent, interfaceObj);
nicholas@2535 2294 newInterface.build("Interface", "" + this.specification.id + "-interface", this.childrenDOM);
nickjillings@1381 2295 this.children.push(newInterface);
nickjillings@1381 2296 this.interfaces.push(newInterface);
nickjillings@1381 2297 }
nicholas@2535 2298
nicholas@2535 2299 for (var elements of this.specification.audioElements) {
nicholas@2535 2300 var audioElementDOM = new this.audioElementNode(this, elements);
nickjillings@1374 2301 this.children.push(audioElementDOM);
nickjillings@1374 2302 this.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1374 2303 }
nicholas@2535 2304
nicholas@2535 2305 this.getAudioElements().forEach(function (elem) {
n@2421 2306 elem.moveButtons.disable();
n@2421 2307 });
nicholas@2535 2308
nickjillings@1370 2309 this.addInterface = {
nickjillings@1370 2310 root: document.createElement("button"),
nickjillings@1370 2311 parent: this,
nicholas@2535 2312 handleEvent: function () {
nickjillings@2194 2313 var InterfaceObj = new specification.interfaceNode(specification);
nicholas@2535 2314 var newInterface = new this.parent.parent.interfaceNode(this.parent.parent, InterfaceObj);
nicholas@2535 2315 newInterface.build("Interface", "" + this.parent.specification.id + "-interface", this.parent.childrenDOM);
nickjillings@1370 2316 this.parent.children.push(newInterface);
nickjillings@1370 2317 this.parent.specification.interfaces.push(InterfaceObj);
nickjillings@1370 2318 this.parent.interfaces.push(newInterface);
nickjillings@1370 2319 }
nickjillings@1370 2320 }
nickjillings@1370 2321 this.addInterface.root.textContent = "Add Interface";
nicholas@2535 2322 this.addInterface.root.addEventListener("click", this.addInterface, false);
nickjillings@1370 2323 this.buttonDOM.appendChild(this.addInterface.root);
nicholas@2535 2324
nickjillings@1370 2325 this.addAudioElement = {
nickjillings@1370 2326 root: document.createElement("button"),
nickjillings@1370 2327 parent: this,
nicholas@2535 2328 handleEvent: function () {
nickjillings@2194 2329 var audioElementObject = new this.parent.specification.audioElementNode(specification);
nicholas@2535 2330 var audioElementDOM = new this.parent.audioElementNode(this.parent, audioElementObject);
nickjillings@1370 2331 this.parent.specification.audioElements.push(audioElementObject);
nickjillings@1370 2332 this.parent.children.push(audioElementDOM);
nickjillings@1370 2333 this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1370 2334 }
nickjillings@1370 2335 }
nickjillings@1370 2336 this.addAudioElement.root.textContent = "Add Audio Element";
nicholas@2535 2337 this.addAudioElement.root.addEventListener("click", this.addAudioElement, false);
nickjillings@1370 2338 this.buttonDOM.appendChild(this.addAudioElement.root);
nickjillings@1370 2339 }
nicholas@2535 2340 }