annotate test_create/test_core.js @ 2612:5c36d79b2f4b

Schema change to support #101
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 15 Nov 2016 09:39:49 +0000
parents 060f1a5ee9be
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@2610 978 var protoMarkers = protoScale.getElementsByTagName("scalelabel");
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);
n@2609 995 this.addMarker = {
n@2609 996 root: document.createElement("button"),
n@2609 997 parent: this,
n@2609 998 handleEvent: function () {
n@2609 999 var marker = {
n@2609 1000 position: 0,
n@2609 1001 text: "text"
n@2609 1002 };
n@2609 1003 this.parent.scaleRoot.scales.push(marker);
n@2609 1004 var markerNode = new this.parent.buildMarkerNode(this.parent, marker);
n@2609 1005 document.getElementById("popup-option-holder").appendChild(markerNode.root);
n@2609 1006 this.parent.markerNodes.push(markerNode);
n@2609 1007 }
n@2609 1008 };
n@2609 1009 this.addMarker.root.textContent = "Add Marker";
n@2609 1010 this.addMarker.root.addEventListener("click", this.addMarker);
nicholas@2535 1011 this.generate = function (scaleRoot, parent) {
nickjillings@1385 1012 this.scaleRoot = scaleRoot;
nickjillings@1385 1013 this.parent = parent;
nicholas@2535 1014
nickjillings@1385 1015 // Generate Pre-Set dropdown
nicholas@2390 1016 var protoScales = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getElementsByTagName("scale");
nickjillings@1385 1017 this.preset.input.innerHTML = "";
nicholas@2535 1018
nicholas@2535 1019 for (var i = 0; i < protoScales.length; i++) {
nickjillings@1385 1020 var selectOption = document.createElement("option");
nickjillings@1385 1021 var scaleName = protoScales[i].getAttribute("name");
nicholas@2535 1022 selectOption.setAttribute("name", scaleName);
nickjillings@1385 1023 selectOption.textContent = scaleName;
nickjillings@1385 1024 this.preset.input.appendChild(selectOption);
nickjillings@1385 1025 }
nickjillings@2115 1026 this.content.appendChild(this.addMarker.root);
nicholas@2535 1027
nickjillings@1385 1028 // Create Marker List
nickjillings@1385 1029 this.buildMarkerList();
nickjillings@1385 1030 }
nicholas@2535 1031 this.buildMarkerList = function () {
nickjillings@1385 1032 var markerInject = document.getElementById("popup-option-holder");
nickjillings@1385 1033 markerInject.innerHTML = "";
nickjillings@1385 1034 this.markerNodes = [];
nicholas@2535 1035 for (var i = 0; i < this.scaleRoot.scales.length; i++) {
nicholas@2535 1036 var markerNode = new this.buildMarkerNode(this, this.scaleRoot.scales[i]);
nickjillings@1385 1037 markerInject.appendChild(markerNode.root);
nickjillings@1385 1038 this.markerNodes.push(markerNode);
nicholas@2535 1039
nickjillings@1385 1040 }
nickjillings@1385 1041 }
nicholas@2535 1042
nicholas@2535 1043 this.buildMarkerNode = function (parent, specification) {
nickjillings@2115 1044 this.root = document.createElement("div");
nickjillings@2115 1045 this.root.className = "popup-option-entry";
nickjillings@2115 1046 this.positionInput = document.createElement("input");
nickjillings@2115 1047 this.positionInput.min = 0;
nickjillings@2115 1048 this.positionInput.max = 100;
nickjillings@2115 1049 this.positionInput.value = specification.position;
nicholas@2535 1050 this.positionInput.setAttribute("name", "position");
nickjillings@2115 1051 this.textInput = document.createElement("input");
nicholas@2535 1052 this.textInput.setAttribute("name", "text");
nickjillings@2180 1053 this.textInput.style.width = "300px";
nickjillings@2115 1054 this.textInput.value = specification.text;
nickjillings@2115 1055 this.specification = specification;
nickjillings@2115 1056 this.parent = parent;
nicholas@2535 1057 this.handleEvent = function (event) {
nicholas@2535 1058 switch (event.currentTarget.getAttribute("name")) {
nickjillings@2115 1059 case "position":
nickjillings@2115 1060 this.specification.position = Number(event.currentTarget.value);
nickjillings@2115 1061 break;
nickjillings@2115 1062 case "text":
nickjillings@2115 1063 this.specification.text = event.currentTarget.value;
nickjillings@2115 1064 break;
nickjillings@2115 1065 }
nickjillings@2115 1066 }
nicholas@2535 1067 this.positionInput.addEventListener("change", this, false);
nicholas@2535 1068 this.textInput.addEventListener("change", this, false);
nickjillings@2115 1069
nickjillings@2115 1070 var posText = document.createElement("span");
nickjillings@2115 1071 posText.textContent = "Position: ";
nickjillings@2115 1072 var textText = document.createElement("span");
nickjillings@2115 1073 textText.textContent = "Text: ";
nickjillings@2115 1074 this.root.appendChild(posText);
nickjillings@2115 1075 this.root.appendChild(this.positionInput);
nickjillings@2115 1076 this.root.appendChild(textText);
nickjillings@2115 1077 this.root.appendChild(this.textInput);
nickjillings@2115 1078
nickjillings@2115 1079 this.deleteMarker = {
nickjillings@2115 1080 root: document.createElement("button"),
nickjillings@2115 1081 parent: this,
nicholas@2535 1082 handleEvent: function () {
nicholas@2535 1083 var index = this.parent.parent.scaleRoot.scales.findIndex(function (element, index, array) {
nicholas@2535 1084 if (element == this) {
nicholas@2535 1085 return true;
nicholas@2535 1086 } else {
nicholas@2535 1087 return false;
nicholas@2535 1088 }
nicholas@2535 1089 }, this.parent.specification)
nickjillings@2115 1090 if (index >= 0) {
nicholas@2535 1091 this.parent.parent.scaleRoot.scales.splice(index, 1);
nickjillings@2115 1092 }
nickjillings@2115 1093 document.getElementById("popup-option-holder").removeChild(this.parent.root);
nickjillings@2115 1094 }
nickjillings@2115 1095 }
nicholas@2535 1096 this.deleteMarker.root.addEventListener("click", this.deleteMarker);
nickjillings@2115 1097 this.deleteMarker.root.textContent = "Delete Marker"
nickjillings@2115 1098 this.root.appendChild(this.deleteMarker.root);
nickjillings@2115 1099 }
nickjillings@1385 1100 }
nickjillings@1370 1101 }
nickjillings@1370 1102 }
nickjillings@1370 1103
nicholas@2535 1104 function SpecificationToHTML() {
nickjillings@1370 1105 // This takes the specification node and converts it to an on-page HTML object
nickjillings@1370 1106 // Each Specification Node is given its own JS object which listens to the XSD for instant verification
nickjillings@1370 1107 // Once generated, it directly binds into the specification object to update with changes
nickjillings@1370 1108 // Fixed DOM entries
nickjillings@1370 1109 this.injectDOM;
nickjillings@1370 1110 this.setupDOM;
nickjillings@1370 1111 this.pages = [];
nicholas@2535 1112
nickjillings@1370 1113 // Self-contained generators
nicholas@2535 1114 this.createGeneralNodeDOM = function (name, id, parent) {
nickjillings@1375 1115 this.type = name;
nickjillings@1370 1116 var root = document.createElement('div');
nickjillings@1370 1117 root.id = id;
nickjillings@1370 1118 root.className = "node";
nickjillings@1370 1119
nickjillings@1370 1120 var titleDiv = document.createElement('div');
nickjillings@1370 1121 titleDiv.className = "node-title";
nickjillings@1370 1122 var title = document.createElement('span');
nickjillings@1370 1123 title.className = "node-title";
nickjillings@1370 1124 title.textContent = name;
nickjillings@1370 1125 titleDiv.appendChild(title);
nickjillings@1370 1126
nickjillings@1370 1127 var attributeDiv = document.createElement('div');
nickjillings@1370 1128 attributeDiv.className = "node-attributes";
nickjillings@1370 1129
nickjillings@1370 1130 var childrenDiv = document.createElement('div');
nickjillings@1370 1131 childrenDiv.className = "node-children";
nickjillings@1370 1132
nickjillings@1370 1133 var buttonsDiv = document.createElement('div');
nickjillings@1370 1134 buttonsDiv.className = "node-buttons";
nickjillings@1370 1135
nickjillings@1370 1136 root.appendChild(titleDiv);
nickjillings@1370 1137 root.appendChild(attributeDiv);
nickjillings@1370 1138 root.appendChild(childrenDiv);
nickjillings@1370 1139 root.appendChild(buttonsDiv);
nickjillings@1370 1140
nickjillings@1370 1141 var obj = {
nickjillings@1370 1142 rootDOM: root,
nickjillings@1370 1143 titleDOM: title,
nickjillings@1370 1144 attributeDOM: attributeDiv,
nickjillings@1370 1145 attributes: [],
nickjillings@1370 1146 childrenDOM: childrenDiv,
nickjillings@1370 1147 children: [],
nickjillings@1370 1148 buttonDOM: buttonsDiv,
nickjillings@1370 1149 parent: parent
nickjillings@1370 1150 }
nickjillings@1370 1151 return obj;
nickjillings@1370 1152 }
nicholas@2535 1153
nicholas@2535 1154 this.convertAttributeToDOM = function (node, schema) {
nickjillings@1370 1155 // This takes an attribute schema node and returns an object with the input node and any bindings
nicholas@2535 1156 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) {
nicholas@2535 1157 schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
nicholas@2535 1158 }
nicholas@2535 1159 var obj = new function () {
nickjillings@1370 1160 this.input;
nickjillings@1370 1161 this.name;
nickjillings@1370 1162 this.owner;
nickjillings@1370 1163 this.holder;
nicholas@2535 1164
nickjillings@1370 1165 this.name = schema.getAttribute('name');
nickjillings@1370 1166 this.default = schema.getAttribute('default');
nickjillings@1370 1167 this.dataType = schema.getAttribute('type');
nickjillings@2158 1168 if (this.dataType == undefined) {
nickjillings@2158 1169 if (schema.childElementCount > 0) {
nicholas@2390 1170 if (schema.firstElementChild.nodeName == "xs:simpleType") {
nickjillings@2158 1171 this.dataType = schema.getAllElementsByTagName("xs:restriction")[0].getAttribute("base");
nickjillings@2158 1172 }
nickjillings@2158 1173 }
nickjillings@2158 1174 }
nicholas@2535 1175 if (typeof this.dataType == "string") {
nicholas@2535 1176 this.dataType = this.dataType.substr(3);
nicholas@2535 1177 } else {
nicholas@2535 1178 this.dataType = "string";
nicholas@2535 1179 }
nickjillings@1370 1180 var minVar = undefined;
nickjillings@1370 1181 var maxVar = undefined;
nicholas@2535 1182 switch (this.dataType) {
nickjillings@1370 1183 case "negativeInteger":
nickjillings@1370 1184 maxVar = -1;
nickjillings@1370 1185 break;
nickjillings@1370 1186 case "positiveInteger":
nickjillings@1370 1187 minVar = 1;
nickjillings@1370 1188 break;
nickjillings@1370 1189 case "nonNegativeInteger":
nickjillings@1370 1190 minVar = 0;
nickjillings@1370 1191 break;
nickjillings@1370 1192 case "nonPositiveInteger":
nickjillings@1370 1193 maxVar = 0;
nickjillings@1370 1194 break;
nickjillings@1370 1195 case "byte":
nickjillings@1370 1196 minVar = 0;
nickjillings@1370 1197 maxVar = 256;
nickjillings@1370 1198 break;
nickjillings@1370 1199 case "short":
nickjillings@1370 1200 minVar = 0;
nickjillings@1370 1201 maxVar = 65536;
nickjillings@1370 1202 break;
nickjillings@1370 1203 default:
nickjillings@1370 1204 break;
nickjillings@1370 1205 }
nicholas@2535 1206
nickjillings@2174 1207 this.enumeration = schema.getAllElementsByTagName("xs:enumeration");
nickjillings@2174 1208 if (this.enumeration.length == 0) {
nickjillings@2174 1209 this.input = document.createElement('input');
nicholas@2535 1210 switch (this.dataType) {
nickjillings@2174 1211 case "boolean":
nickjillings@2174 1212 this.input.type = "checkbox";
nickjillings@2174 1213 break;
nickjillings@2174 1214 case "negativeInteger":
nickjillings@2174 1215 case "positiveInteger":
nickjillings@2174 1216 case "nonNegativeInteger":
nickjillings@2174 1217 case "nonPositiveInteger":
nickjillings@2174 1218 case "integer":
nickjillings@2174 1219 case "short":
nickjillings@2174 1220 case "byte":
nickjillings@2174 1221 this.input.step = 1;
nickjillings@2174 1222 case "decimal":
nickjillings@2174 1223 this.input.type = "number";
nickjillings@2174 1224 this.input.min = minVar;
nickjillings@2174 1225 this.input.max = maxVar;
nickjillings@2174 1226 break;
nickjillings@2174 1227 default:
nickjillings@2174 1228 break;
nickjillings@2174 1229 }
nickjillings@2174 1230 } else {
nickjillings@2174 1231 this.input = document.createElement("select");
nicholas@2535 1232 for (var i = 0; i < this.enumeration.length; i++) {
nickjillings@2174 1233 var option = document.createElement("option");
nickjillings@2174 1234 var value = this.enumeration[i].getAttribute("value");
nicholas@2535 1235 option.setAttribute("value", value);
nickjillings@2174 1236 option.textContent = value;
nickjillings@2174 1237 this.input.appendChild(option);
nickjillings@2174 1238 }
nickjillings@1370 1239 }
nickjillings@1370 1240 var value;
nicholas@2535 1241 eval("value = node." + this.name)
nicholas@2535 1242 if (this.default != undefined && value == undefined) {
nickjillings@2174 1243 value = this.default;
nickjillings@2174 1244 }
nickjillings@2174 1245 if (this.input.type == "checkbox") {
nicholas@2535 1246 if (value == "true" || value == "True") {
nicholas@2535 1247 this.input.checked = false;
nicholas@2535 1248 } else {
nicholas@2535 1249 this.input.checked = false;
nicholas@2535 1250 }
nickjillings@2174 1251 } else {
nickjillings@1370 1252 this.input.value = value;
nickjillings@1370 1253 }
nicholas@2535 1254 this.handleEvent = function (event) {
nickjillings@1370 1255 var value;
nicholas@2535 1256 if (this.input.nodeName == "INPUT") {
nicholas@2535 1257 switch (this.input.type) {
nickjillings@2174 1258 case "checkbox":
nickjillings@2174 1259 value = event.currentTarget.checked;
nickjillings@2174 1260 break;
nickjillings@2174 1261 case "number":
n@2423 1262 if (event.currentTarget.value != "") {
n@2423 1263 value = Number(event.currentTarget.value);
n@2423 1264 } else {
n@2423 1265 value = undefined;
n@2423 1266 }
nickjillings@2174 1267 break;
nickjillings@2174 1268 default:
n@2423 1269 if (event.currentTarget.value != "") {
n@2423 1270 value = event.currentTarget.value;
n@2423 1271 } else {
n@2423 1272 value = undefined;
n@2423 1273 }
nicholas@2535 1274 break;
nickjillings@2174 1275 }
nickjillings@2174 1276 } else if (this.input.nodeName == "SELECT") {
nickjillings@2174 1277 value = event.currentTarget.value;
nickjillings@1370 1278 }
nicholas@2535 1279 eval("this.owner." + this.name + " = value");
nickjillings@1370 1280 }
nickjillings@1370 1281 this.holder = document.createElement('div');
nickjillings@1370 1282 this.holder.className = "attribute";
nicholas@2535 1283 this.holder.setAttribute('name', this.name);
nickjillings@1370 1284 var text = document.createElement('span');
nicholas@2535 1285 eval("text.textContent = attributeText." + this.name + "+': '");
nickjillings@1370 1286 this.holder.appendChild(text);
nickjillings@1370 1287 this.holder.appendChild(this.input);
nickjillings@1370 1288 this.owner = node;
nicholas@2535 1289 this.input.addEventListener("change", this, false);
nickjillings@1370 1290 }
nicholas@2535 1291 if (obj.attribute != null) {
nickjillings@1370 1292 obj.input.value = obj.attribute;
nickjillings@1370 1293 }
nickjillings@1370 1294 return obj;
nickjillings@1370 1295 }
nicholas@2535 1296
nicholas@2535 1297 this.convert = function (root) {
nickjillings@1370 1298 //Performs the actual conversion using the given root DOM as the root
nickjillings@1370 1299 this.injectDOM = root;
nicholas@2535 1300
nickjillings@1373 1301 // Build the export button
nickjillings@1373 1302 var exportButton = document.createElement("button");
nickjillings@1373 1303 exportButton.textContent = "Export to XML";
nicholas@2535 1304 exportButton.onclick = function () {
nickjillings@1373 1305 var doc = specification.encode();
nickjillings@1373 1306 var obj = {};
nickjillings@1373 1307 obj.title = "Export";
nickjillings@1373 1308 obj.content = document.createElement("div");
nickjillings@1373 1309 obj.content.id = "finish";
nickjillings@1373 1310 var span = document.createElement("span");
n@2405 1311 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 1312 obj.content.appendChild(span);
n@2405 1313 span = document.createElement("p");
n@2405 1314 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 1315 obj.content.appendChild(span);
nickjillings@1373 1316 var link = document.createElement("div");
n@2412 1317 link.appendChild(doc.firstChild);
nickjillings@1373 1318 var file = [link.innerHTML];
nicholas@2535 1319 var bb = new Blob(file, {
nicholas@2535 1320 type: 'application/xml'
nicholas@2535 1321 });
nickjillings@1373 1322 var dnlk = window.URL.createObjectURL(bb);
nickjillings@1373 1323 var a = document.createElement("a");
nickjillings@1373 1324 a.hidden = '';
nickjillings@1373 1325 a.href = dnlk;
nickjillings@1373 1326 a.download = "project-specification.xml";
nickjillings@1373 1327 a.textContent = "Save File";
nickjillings@1373 1328 obj.content.appendChild(a);
nickjillings@1373 1329 popupObject.show();
nickjillings@1373 1330 popupObject.postNode(obj);
nickjillings@1373 1331 }
nickjillings@1373 1332 this.injectDOM.appendChild(exportButton);
nicholas@2535 1333
nickjillings@1370 1334 // First perform the setupNode;
nickjillings@1370 1335 var setupSchema = specification.schema.getAllElementsByName('setup')[0];
nicholas@2535 1336 this.setupDOM = new this.createGeneralNodeDOM('Global Configuration', 'setup', null);
nickjillings@1370 1337 this.injectDOM.appendChild(this.setupDOM.rootDOM);
nickjillings@1370 1338 var setupAttributes = setupSchema.getAllElementsByTagName('xs:attribute');
nicholas@2535 1339 for (var i = 0; i < setupAttributes.length; i++) {
nickjillings@1370 1340 var attributeName = setupAttributes[i].getAttribute('name');
nicholas@2535 1341 var attrObject = this.convertAttributeToDOM(specification, setupAttributes[i]);
nickjillings@1370 1342 this.setupDOM.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 1343 this.setupDOM.attributes.push(attrObject);
nickjillings@1370 1344 }
nicholas@2535 1345
nickjillings@2179 1346 // Build the exit Text node
nicholas@2535 1347 var exitText = new this.createGeneralNodeDOM("Exit Text", "exit-test", this.setupDOM);
nickjillings@2179 1348 exitText.rootDOM.removeChild(exitText.attributeDOM);
nickjillings@2179 1349 this.setupDOM.children.push(exitText);
nickjillings@2179 1350 this.setupDOM.childrenDOM.appendChild(exitText.rootDOM);
nickjillings@2179 1351 var obj = {
nickjillings@2179 1352 rootDOM: document.createElement("div"),
nickjillings@2179 1353 labelDOM: document.createElement("label"),
nickjillings@2179 1354 inputDOM: document.createElement("textarea"),
nickjillings@2179 1355 parent: exitText,
nickjillings@2179 1356 specification: specification,
nicholas@2535 1357 handleEvent: function (event) {
nickjillings@2179 1358 this.specification.exitText = this.inputDOM.value;
nickjillings@2179 1359 }
nickjillings@2179 1360 }
b@2367 1361 var exitWarning = document.createElement("div");
b@2367 1362 obj.rootDOM.appendChild(exitWarning);
b@2367 1363 exitWarning.textContent = "Only visible when the above 'On complete redirect URL' field is empty.";
nickjillings@2179 1364 obj.rootDOM.appendChild(obj.labelDOM);
nickjillings@2179 1365 obj.rootDOM.appendChild(obj.inputDOM);
nickjillings@2179 1366 obj.labelDOM.textContent = "Text: ";
nickjillings@2179 1367 obj.inputDOM.value = obj.specification.exitText;
nicholas@2535 1368 obj.inputDOM.addEventListener("change", obj);
nickjillings@2179 1369 exitText.children.push(obj);
nickjillings@2179 1370 exitText.childrenDOM.appendChild(obj.rootDOM);
nicholas@2535 1371
nickjillings@1370 1372 // Now we must build the interface Node
nicholas@2535 1373 this.interfaceDOM = new this.interfaceNode(this, specification.interfaces);
nicholas@2535 1374 this.interfaceDOM.build("Interface", "setup-interface", this.setupDOM.rootDOM);
nicholas@2535 1375
nickjillings@1370 1376 // Now build the Metrics selection node
nicholas@2535 1377 var metric = this.createGeneralNodeDOM("Session Metrics", "setup-metric", this.setupDOM);
nickjillings@1370 1378 metric.rootDOM.removeChild(metric.attributeDOM);
nickjillings@1370 1379 this.setupDOM.children.push(metric);
nickjillings@1370 1380 this.setupDOM.childrenDOM.appendChild(metric.rootDOM);
nickjillings@1370 1381 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1382 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 1383 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1384 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 1385 testXML = testXML.getAllElementsByTagName("metrics");
nicholas@2390 1386 var interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1387 while (interfaceXMLChild) {
nickjillings@1370 1388 var obj = {
nickjillings@1370 1389 input: document.createElement('input'),
nickjillings@1370 1390 root: document.createElement('div'),
nickjillings@1370 1391 text: document.createElement('span'),
nickjillings@1370 1392 specification: specification.metrics.enabled,
nicholas@2390 1393 name: interfaceXMLChild.getAttribute("name"),
nicholas@2535 1394 handleEvent: function () {
nicholas@2535 1395 for (var i = 0; i < this.specification.length; i++) {
nicholas@2535 1396 if (this.specification[i] == this.name) {
nickjillings@1370 1397 var options = this.specification;
nickjillings@1370 1398 if (this.input.checked == false) {
nicholas@2535 1399 if (i == options.length) {
nicholas@2535 1400 options = options.slice(0, i);
nicholas@2535 1401 } else {
nicholas@2535 1402 options = options.slice(0, i).concat(options.slice(i + 1));
nickjillings@1370 1403 }
nickjillings@1370 1404 } else {
nickjillings@1370 1405 return;
nickjillings@1370 1406 }
nickjillings@1370 1407 this.specification = options;
nickjillings@1370 1408 break;
nickjillings@1370 1409 }
nickjillings@1370 1410 }
nickjillings@1370 1411 if (this.input.checked) {
nickjillings@1370 1412 this.specification.push(this.name);
nickjillings@1370 1413 }
nickjillings@1370 1414 }
nickjillings@1370 1415 };
nickjillings@1370 1416 obj.root.className = "attribute";
nickjillings@1370 1417 obj.input.type = "checkbox";
nickjillings@1370 1418 obj.root.appendChild(obj.text);
nickjillings@1370 1419 obj.root.appendChild(obj.input);
nicholas@2390 1420 obj.text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1421 metric.children.push(obj);
nickjillings@1370 1422 metric.childrenDOM.appendChild(obj.root);
nicholas@2535 1423 for (var j = 0; j < specification.metrics.enabled.length; j++) {
nicholas@2535 1424 if (specification.metrics.enabled[j] == obj.name) {
nickjillings@1370 1425 obj.input.checked = true;
nickjillings@1370 1426 break;
nickjillings@1370 1427 }
nickjillings@1370 1428 }
nicholas@2390 1429 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1430 }
nicholas@2535 1431
nickjillings@1370 1432 // Now both before and after surveys
nicholas@2535 1433 if (specification.preTest == undefined) {
nickjillings@2194 1434 specification.preTest = new specification.surveyNode(specification);
nickjillings@1370 1435 specification.preTest.location = "pre";
nickjillings@1370 1436 }
nicholas@2535 1437 if (specification.postTest == undefined) {
nickjillings@2194 1438 specification.postTest = new specification.surveyNode(specification);
nickjillings@1370 1439 specification.postTest.location = "post";
nickjillings@1370 1440 }
nicholas@2535 1441 var surveyBefore = new this.surveyNode(this, specification.preTest, "Pre");
nicholas@2535 1442 var surveyAfter = new this.surveyNode(this, specification.postTest, "Post");
nickjillings@1370 1443 this.setupDOM.children.push(surveyBefore);
nickjillings@1370 1444 this.setupDOM.children.push(surveyAfter);
nickjillings@1370 1445 this.setupDOM.childrenDOM.appendChild(surveyBefore.rootDOM);
nickjillings@1370 1446 this.setupDOM.childrenDOM.appendChild(surveyAfter.rootDOM);
nicholas@2535 1447
nickjillings@1370 1448 // Add in the page creator button
nickjillings@1370 1449 this.addPage = {
nickjillings@1370 1450 root: document.createElement("button"),
nickjillings@1370 1451 parent: this,
nicholas@2535 1452 handleEvent: function () {
nickjillings@2194 1453 var pageObj = new specification.page(specification);
nickjillings@1370 1454 specification.pages.push(pageObj);
nicholas@2535 1455 var newPage = new this.parent.pageNode(this.parent, pageObj);
nicholas@2315 1456 document.getElementById("page-holder").appendChild(newPage.rootDOM);
nickjillings@1370 1457 this.parent.pages.push(newPage);
nickjillings@1370 1458 }
nickjillings@1370 1459 }
nickjillings@1370 1460 this.addPage.root.textContent = "Add Page";
nicholas@2315 1461 this.addPage.root.id = "new-page-button";
nicholas@2315 1462 this.addPage.root.style.float = "left";
nicholas@2535 1463 this.addPage.root.addEventListener("click", this.addPage, false);
nicholas@2535 1464
nicholas@2315 1465 var pageHolder = document.createElement("div");
nicholas@2535 1466 pageHolder.id = "page-holder";
nicholas@2315 1467 this.injectDOM.appendChild(pageHolder);
nicholas@2535 1468
nickjillings@1374 1469 // Build each page
nicholas@2535 1470 for (var page of specification.pages) {
nicholas@2535 1471 var newPage = new this.pageNode(this, page);
nicholas@2315 1472 pageHolder.appendChild(newPage.rootDOM);
nickjillings@1374 1473 this.pages.push(newPage);
nickjillings@1374 1474 }
nicholas@2535 1475
nicholas@2315 1476 this.injectDOM.appendChild(this.addPage.root);
nickjillings@1370 1477 }
nicholas@2535 1478
nicholas@2535 1479 this.interfaceNode = function (parent, rootObject) {
nickjillings@1375 1480 this.type = "interfaceNode";
nickjillings@1370 1481 this.rootDOM;
nickjillings@1370 1482 this.titleDOM;
nickjillings@1370 1483 this.attributeDOM;
nickjillings@1370 1484 this.attributes = [];
nickjillings@1370 1485 this.childrenDOM;
nickjillings@1370 1486 this.children = [];
nickjillings@1370 1487 this.buttonDOM;
nickjillings@1370 1488 this.parent = parent;
nickjillings@1370 1489 this.HTMLPoint;
nickjillings@1370 1490 this.specification = rootObject;
nickjillings@1370 1491 this.schema = specification.schema.getAllElementsByName("interface")[1];
nicholas@2535 1492
nicholas@2535 1493 this.createIOasAttr = function (name, specification, parent, type) {
nickjillings@1370 1494 this.root = document.createElement('div');
nickjillings@1370 1495 this.input = document.createElement("input");
nickjillings@1370 1496 this.name = name;
nickjillings@1370 1497 this.type = type;
nickjillings@1370 1498 this.parent = parent;
nickjillings@1370 1499 this.specification = specification;
nicholas@2535 1500 this.handleEvent = function (event) {
nicholas@2535 1501 for (var i = 0; i < this.specification.options.length; i++) {
nicholas@2535 1502 if (this.specification.options[i].name == this.name) {
nickjillings@1370 1503 var options = this.specification.options;
nickjillings@1370 1504 if (this.input.checked == false) {
nicholas@2535 1505 if (i == options.length) {
nicholas@2535 1506 options = options.slice(0, i);
nicholas@2535 1507 } else {
nicholas@2535 1508 options = options.slice(0, i).concat(options.slice(i + 1));
nickjillings@1370 1509 }
nickjillings@1370 1510 } else {
nickjillings@1370 1511 return;
nickjillings@1370 1512 }
nickjillings@1370 1513 this.specification.options = options;
nickjillings@1370 1514 break;
nickjillings@1370 1515 }
nickjillings@1370 1516 }
nickjillings@1370 1517 if (this.input.checked) {
nickjillings@1370 1518 var obj = {
nickjillings@1370 1519 name: this.name,
nickjillings@1370 1520 type: this.type
nickjillings@1370 1521 };
nickjillings@1370 1522 this.specification.options.push(obj);
nickjillings@1370 1523 }
nicholas@2535 1524 if (this.parent.HTMLPoint.id == "setup") {
nickjillings@1370 1525 // We've changed a global setting, must update all child 'interfaces' and disable them
nicholas@2535 1526 for (pages of convert.pages) {
nicholas@2535 1527 for (interface of pages.interfaces) {
nicholas@2535 1528 if (this.type == "check") {
nicholas@2535 1529 for (node of interface.children[0].attributes) {
nickjillings@1370 1530 if (node.name == this.name) {
nickjillings@1370 1531 if (this.input.checked) {
nickjillings@1370 1532 node.input.disabled = true;
nickjillings@1370 1533 node.input.checked = false;
nickjillings@1370 1534 } else {
nickjillings@1370 1535 node.input.disabled = false;
nickjillings@1370 1536 }
nickjillings@1370 1537 break;
nickjillings@1370 1538 }
nickjillings@1370 1539 }
nicholas@2535 1540 } else if (this.type == "show") {
nicholas@2535 1541 for (node of interface.children[1].attributes) {
nickjillings@1370 1542 if (node.name == this.name) {
nickjillings@1370 1543 if (this.input.checked) {
nickjillings@1370 1544 node.input.disabled = true;
nickjillings@1370 1545 } else {
nickjillings@1370 1546 node.input.disabled = false;
nickjillings@1370 1547 }
nickjillings@1370 1548 break;
nickjillings@1370 1549 }
nickjillings@1370 1550 }
nickjillings@1370 1551 }
nickjillings@1370 1552 }
nickjillings@1370 1553 }
nickjillings@1370 1554 }
nickjillings@1370 1555 };
nicholas@2535 1556 this.findIndex = function (element, index, array) {
nickjillings@1370 1557 if (element.name == this.name)
nickjillings@1370 1558 return true;
nickjillings@1370 1559 else
nickjillings@1370 1560 return false;
nickjillings@1370 1561 };
nicholas@2535 1562 this.findNode = function (element, index, array) {
nickjillings@1370 1563 if (element.name == this.name)
nickjillings@1370 1564 return true;
nickjillings@1370 1565 else
nickjillings@1370 1566 return false;
nickjillings@1370 1567 };
nickjillings@1370 1568 this.input.type = "checkbox";
nicholas@2535 1569 this.input.setAttribute("name", name);
nicholas@2535 1570 this.input.addEventListener("change", this, false);
nickjillings@1370 1571 this.root.appendChild(this.input);
nickjillings@1370 1572 this.root.className = "attribute";
nickjillings@1370 1573 return this;
nickjillings@1370 1574 }
nicholas@2535 1575
nicholas@2535 1576 this.build = function (name, id, parent) {
nicholas@2535 1577 var obj = this.parent.createGeneralNodeDOM(name, id, parent);
nicholas@2535 1578
nickjillings@1370 1579 this.rootDOM = obj.rootDOM;
nickjillings@1370 1580 this.titleDOM = obj.titleDOM;
nickjillings@1370 1581 this.attributeDOM = obj.attributeDOM;
nickjillings@1370 1582 this.childrenDOM = obj.childrenDOM;
nickjillings@1370 1583 this.buttonDOM = obj.buttonsDOM;
nickjillings@1370 1584 this.HTMLPoint = parent;
nickjillings@1370 1585 this.rootDOM.removeChild(this.attributeDOM);
nicholas@2243 1586 if (parent.id != "setup") {
nicholas@2243 1587 // Put in the <title> node:
nicholas@2243 1588 this.titleNode = {
nicholas@2243 1589 root: document.createElement("div"),
nicholas@2243 1590 label: document.createElement("span"),
nicholas@2243 1591 input: document.createElement("input"),
nicholas@2243 1592 parent: this,
nicholas@2535 1593 handleEvent: function (event) {
nicholas@2243 1594 this.parent.specification.title = event.currentTarget.value;
nicholas@2243 1595 }
nicholas@2243 1596 }
nicholas@2611 1597 this.titleNode.label.textContent = "Presented Axis Title:";
nicholas@2243 1598 this.titleNode.root.className = "node-children";
nicholas@2243 1599 this.titleNode.root.appendChild(this.titleNode.label);
nicholas@2243 1600 this.titleNode.root.appendChild(this.titleNode.input);
nicholas@2535 1601 this.titleNode.input.addEventListener("change", this.titleNode, false);
nicholas@2243 1602 this.titleNode.input.value = this.specification.title;
nicholas@2243 1603 this.children.push(this.titleNode);
nicholas@2243 1604 this.childrenDOM.appendChild(this.titleNode.root);
nicholas@2611 1605 // Set the interface-name attribute
nicholas@2611 1606 this.axisName = {
nicholas@2611 1607 root: document.createElement("div"),
nicholas@2611 1608 label: document.createElement("span"),
nicholas@2611 1609 input: document.createElement("input"),
nicholas@2611 1610 parent: this,
nicholas@2611 1611 handleEvent: function (event) {
nicholas@2611 1612 this.parent.specification.name = event.currentTarget.value;
nicholas@2611 1613 }
nicholas@2611 1614 }
nicholas@2611 1615 this.axisName.label.textContent = "Saved Axis Name (no spaces):";
nicholas@2611 1616 this.axisName.root.className = "node-children";
nicholas@2611 1617 this.axisName.root.appendChild(this.axisName.label);
nicholas@2611 1618 this.axisName.root.appendChild(this.axisName.input);
nicholas@2611 1619 this.axisName.input.addEventListener("change", this.axisName, false);
nicholas@2611 1620 this.axisName.input.value = this.specification.name;
nicholas@2611 1621 this.children.push(this.axisName);
nicholas@2611 1622 this.childrenDOM.appendChild(this.axisName.root);
nicholas@2243 1623 }
nicholas@2535 1624
nickjillings@1370 1625 // Put in the check / show options as individual children
nicholas@2535 1626 var checks = this.parent.createGeneralNodeDOM("Checks", "setup-interface-checks", this);
nickjillings@1370 1627
nickjillings@1370 1628 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1629 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1630 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1631 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1632 testXML = testXML.getAllElementsByTagName("checks");
nicholas@2390 1633 var interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1634 while (interfaceXMLChild) {
nicholas@2535 1635 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "check");
nicholas@2535 1636 for (var option of this.specification.options) {
nicholas@2535 1637 if (option.name == obj.name) {
nickjillings@1370 1638 obj.input.checked = true;
nickjillings@1370 1639 break;
nickjillings@1370 1640 }
nickjillings@1370 1641 }
nickjillings@1370 1642 if (parent.id != "setup") {
nicholas@2535 1643 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1644 if (node != undefined) {
nickjillings@1381 1645 if (node.input.checked) {
nickjillings@1381 1646 obj.input.checked = false;
nickjillings@1381 1647 obj.input.disabled = true;
nickjillings@1381 1648 }
nickjillings@1370 1649 }
nickjillings@1370 1650 }
nickjillings@1370 1651 var text = document.createElement('span');
nicholas@2390 1652 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1653 obj.root.appendChild(text);
nickjillings@1370 1654 checks.attributeDOM.appendChild(obj.root);
nickjillings@1370 1655 checks.attributes.push(obj);
nicholas@2390 1656 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1657 }
nickjillings@1370 1658 this.children.push(checks);
nickjillings@1370 1659 this.childrenDOM.appendChild(checks.rootDOM);
nickjillings@1370 1660
nicholas@2535 1661 var show = this.parent.createGeneralNodeDOM("Show", "setup-interface-show", this);
nickjillings@1370 1662 interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1663 checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1664 testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1665 interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1666 testXML = testXML.getAllElementsByTagName("show");
nicholas@2390 1667 interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1668 while (interfaceXMLChild) {
nicholas@2535 1669 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "show");
nicholas@2535 1670 for (var option of this.specification.options) {
nicholas@2535 1671 if (option.name == obj.name) {
nickjillings@1370 1672 obj.input.checked = true;
nickjillings@1370 1673 break;
nickjillings@1370 1674 }
nickjillings@1370 1675 }
nickjillings@1370 1676 if (parent.id != "setup") {
nicholas@2535 1677 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1678 if (node != undefined) {
nickjillings@1381 1679 if (node.input.checked) {
nickjillings@1381 1680 obj.input.checked = false;
nickjillings@1381 1681 obj.input.disabled = true;
nickjillings@1381 1682 }
nickjillings@1370 1683 }
nickjillings@1370 1684 }
nickjillings@1370 1685 var text = document.createElement('span');
nicholas@2390 1686 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1687 obj.root.appendChild(text);
nickjillings@1370 1688 show.attributeDOM.appendChild(obj.root);
nickjillings@1370 1689 show.attributes.push(obj);
nicholas@2390 1690 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1691 }
nickjillings@1370 1692 this.children.push(show);
nickjillings@1370 1693 this.childrenDOM.appendChild(show.rootDOM);
nicholas@2535 1694
nicholas@2535 1695 if (parent.id == "setup") {} else {
nicholas@2535 1696 var nameAttr = this.parent.convertAttributeToDOM(this, specification.schema.getAllElementsByName("name")[0]);
nickjillings@1370 1697 this.attributeDOM.appendChild(nameAttr.holder);
nickjillings@1370 1698 this.attributes.push(nameAttr);
nicholas@2535 1699 var scales = new this.scalesNode(this, this.specification);
nickjillings@1385 1700 this.children.push(scales);
nickjillings@1385 1701 this.childrenDOM.appendChild(scales.rootDOM);
nickjillings@1370 1702 }
nicholas@2535 1703 if (parent != undefined) {
nickjillings@1370 1704 parent.appendChild(this.rootDOM);
nickjillings@1370 1705 }
nickjillings@1370 1706 }
nicholas@2535 1707
nicholas@2535 1708 this.scalesNode = function (parent, rootObject) {
nickjillings@1385 1709 this.type = "scalesNode";
nickjillings@1385 1710 this.rootDOM = document.createElement("div");
nickjillings@1385 1711 this.titleDOM = document.createElement("span");
nickjillings@1385 1712 this.attributeDOM = document.createElement("div");
nickjillings@1385 1713 this.attributes = [];
nickjillings@1385 1714 this.childrenDOM = document.createElement("div");
nickjillings@1385 1715 this.children = [];
nickjillings@1385 1716 this.buttonDOM = document.createElement("div");
nickjillings@1385 1717 this.parent = parent;
nickjillings@1385 1718 this.specification = rootObject;
nickjillings@1385 1719 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1385 1720 this.rootDOM.className = "node";
nickjillings@1385 1721
nickjillings@1385 1722 var titleDiv = document.createElement('div');
nickjillings@1385 1723 titleDiv.className = "node-title";
nickjillings@1385 1724 this.titleDOM.className = "node-title";
nickjillings@1385 1725 this.titleDOM.textContent = "Interface Scales";
nickjillings@1385 1726 titleDiv.appendChild(this.titleDOM);
nickjillings@1385 1727
nickjillings@1385 1728 this.attributeDOM.className = "node-attributes";
nickjillings@1385 1729 this.childrenDOM.className = "node-children";
nickjillings@1385 1730 this.buttonDOM.className = "node-buttons";
nickjillings@1385 1731
nickjillings@1385 1732 this.rootDOM.appendChild(titleDiv);
nickjillings@1385 1733 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1385 1734 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1385 1735 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1736
nickjillings@1385 1737 this.editButton = {
nickjillings@1385 1738 button: document.createElement("button"),
nickjillings@1385 1739 parent: this,
nicholas@2535 1740 handleEvent: function (event) {
nickjillings@1385 1741 popupObject.show();
nickjillings@1385 1742 popupObject.postNode(popupStateNodes.state[6]);
nicholas@2535 1743 popupStateNodes.state[6].generate(this.parent.specification, this.parent);
nickjillings@1385 1744 }
nickjillings@1385 1745 };
nickjillings@1385 1746 this.editButton.button.textContent = "Edit Scales/Markers";
nicholas@2535 1747 this.editButton.button.addEventListener("click", this.editButton, false);
nickjillings@1385 1748 this.buttonDOM.appendChild(this.editButton.button);
nickjillings@1385 1749 }
nickjillings@1370 1750 }
nicholas@2535 1751
nicholas@2535 1752 this.surveyNode = function (parent, rootObject, location) {
nickjillings@1375 1753 this.type = "surveyNode";
nickjillings@1370 1754 this.rootDOM = document.createElement("div");
nickjillings@1370 1755 this.titleDOM = document.createElement("span");
nickjillings@1370 1756 this.attributeDOM = document.createElement("div");
nickjillings@1370 1757 this.attributes = [];
nickjillings@1370 1758 this.childrenDOM = document.createElement("div");
nickjillings@1370 1759 this.children = [];
nickjillings@1370 1760 this.buttonDOM = document.createElement("div");
nickjillings@1370 1761 this.parent = parent;
nickjillings@1370 1762 this.specification = rootObject;
nickjillings@1370 1763 this.schema = specification.schema.getAllElementsByName("survey")[1];
nickjillings@1370 1764 this.rootDOM.className = "node";
nickjillings@1370 1765
nickjillings@1370 1766 var titleDiv = document.createElement('div');
nickjillings@1370 1767 titleDiv.className = "node-title";
nickjillings@1370 1768 this.titleDOM.className = "node-title";
nickjillings@1370 1769 this.titleDOM.textContent = "Survey";
nickjillings@1370 1770 titleDiv.appendChild(this.titleDOM);
nicholas@2535 1771
nickjillings@1370 1772 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1773 var locationAttr = document.createElement("span");
nickjillings@1370 1774 this.attributeDOM.appendChild(locationAttr);
nickjillings@1370 1775 if (location == "Pre" || location == "pre") {
nickjillings@1370 1776 locationAttr.textContent = "Location: Before";
nickjillings@1370 1777 } else {
nickjillings@1370 1778 locationAttr.textContent = "Location: After";
nickjillings@1370 1779 }
nickjillings@1370 1780 this.childrenDOM.className = "node-children";
nickjillings@1370 1781 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1782
nickjillings@1370 1783 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1784 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1785 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1786 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1787
nicholas@2535 1788 this.surveyEntryNode = function (parent, rootObject) {
nickjillings@1375 1789 this.type = "surveyEntryNode";
nickjillings@1370 1790 this.rootDOM = document.createElement("div");
nickjillings@1370 1791 this.titleDOM = document.createElement("span");
nickjillings@1370 1792 this.attributeDOM = document.createElement("div");
nickjillings@1370 1793 this.attributes = [];
nickjillings@1370 1794 this.childrenDOM = document.createElement("div");
nickjillings@1370 1795 this.children = [];
nickjillings@1370 1796 this.buttonDOM = document.createElement("div");
nickjillings@1370 1797 this.parent = parent;
nickjillings@1370 1798 this.specification = rootObject;
nickjillings@1370 1799 this.schema = specification.schema.getAllElementsByName("surveyentry")[1];
nickjillings@1370 1800
nickjillings@1370 1801 this.rootDOM.className = "node";
nickjillings@1370 1802 this.rootDOM.style.minWidth = "50%";
nickjillings@1370 1803
nickjillings@1370 1804 var titleDiv = document.createElement('div');
nickjillings@1370 1805 titleDiv.className = "node-title";
nickjillings@1370 1806 this.titleDOM.className = "node-title";
nickjillings@1370 1807 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 1808
nickjillings@1370 1809 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1810 this.childrenDOM.className = "node-children";
nickjillings@1370 1811 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1812
nickjillings@1370 1813 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1814 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1815 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1816 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1817
nicholas@2535 1818 this.build = function () {
nickjillings@1375 1819 this.attributeDOM.innerHTML = null;
nickjillings@1375 1820 this.childrenDOM.innerHTML = null;
nickjillings@1375 1821 var statementRoot = document.createElement("div");
nickjillings@1375 1822 var statement = document.createElement("span");
nicholas@2535 1823 statement.textContent = "Statement / Question: " + this.specification.statement;
nickjillings@1375 1824 statementRoot.appendChild(statement);
nickjillings@1375 1825 this.children.push(statementRoot);
nickjillings@1375 1826 this.childrenDOM.appendChild(statementRoot);
nicholas@2535 1827 switch (this.specification.type) {
nickjillings@1375 1828 case "statement":
nickjillings@1375 1829 this.titleDOM.textContent = "Statement";
nickjillings@1375 1830 break;
nickjillings@1375 1831 case "question":
nickjillings@1375 1832 this.titleDOM.textContent = "Question";
nicholas@2535 1833 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1834 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1835 var boxsize = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("boxsize")[0]);
nickjillings@1375 1836 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1837 this.attributes.push(id);
nickjillings@1375 1838 this.attributeDOM.appendChild(mandatory.holder);
nickjillings@1375 1839 this.attributes.push(mandatory);
nickjillings@1375 1840 this.attributeDOM.appendChild(boxsize.holder);
nickjillings@1375 1841 this.attributes.push(boxsize);
nickjillings@1375 1842 break;
nickjillings@1375 1843 case "number":
nickjillings@1375 1844 this.titleDOM.textContent = "Number";
nicholas@2535 1845 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1846 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1847 var min = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("min")[0]);
nicholas@2535 1848 var max = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("max")[0]);
nickjillings@1375 1849 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1850 this.attributes.push(id);
nickjillings@1375 1851 this.attributeDOM.appendChild(min.holder);
nickjillings@1375 1852 this.attributes.push(min);
nickjillings@1375 1853 this.attributeDOM.appendChild(max.holder);
nickjillings@1375 1854 this.attributes.push(max);
nickjillings@1375 1855 break;
nickjillings@1375 1856 case "checkbox":
nickjillings@1375 1857 this.titleDOM.textContent = "Checkbox";
nicholas@2535 1858 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1859 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1860 this.attributes.push(id);
nickjillings@1375 1861 break;
nickjillings@1375 1862 case "radio":
nickjillings@1375 1863 this.titleDOM.textContent = "Radio";
nicholas@2535 1864 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1865 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1866 this.attributes.push(id);
nickjillings@1375 1867 break;
nickjillings@1375 1868 }
nickjillings@1370 1869 }
nickjillings@1375 1870 this.build();
nicholas@2535 1871
nickjillings@1370 1872 this.editNode = {
nickjillings@1370 1873 root: document.createElement("button"),
nickjillings@1370 1874 parent: this,
nicholas@2535 1875 handleEvent: function () {
nickjillings@1370 1876 popupObject.show();
nicholas@2535 1877 popupStateNodes.state[5].generate(this.parent.specification, this.parent);
nickjillings@1370 1878 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1879 }
nickjillings@1370 1880 }
nickjillings@1370 1881 this.editNode.root.textContent = "Edit Entry";
nicholas@2535 1882 this.editNode.root.addEventListener("click", this.editNode, false);
nickjillings@1370 1883 this.buttonDOM.appendChild(this.editNode.root);
nicholas@2535 1884
nickjillings@1370 1885 this.deleteNode = {
nickjillings@1370 1886 root: document.createElement("button"),
nickjillings@1370 1887 parent: this,
nicholas@2535 1888 handleEvent: function () {
nickjillings@1370 1889 var optionList = this.parent.parent.specification.options;
nickjillings@1370 1890 var childList = this.parent.parent.children;
nicholas@2535 1891 for (var i = 0; i < this.parent.parent.specification.options.length; i++) {
nickjillings@1370 1892 var option = this.parent.parent.specification.options[i];
nicholas@2535 1893 if (option == this.parent.specification) {
nickjillings@1370 1894 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nicholas@2535 1895 if (i == this.parent.parent.specification.options.length - 1) {
nicholas@2535 1896 optionList = optionList.slice(0, i);
nicholas@2535 1897 childList = childList.slice(0, i);
nicholas@2535 1898 } else {
nicholas@2535 1899 optionList = optionList.slice(0, i).concat(optionList.slice(i + 1));
nicholas@2535 1900 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 1901 }
nickjillings@1370 1902 this.parent.parent.specification.options = optionList;
nickjillings@1370 1903 this.parent.parent.children = childList;
nickjillings@1370 1904 }
nickjillings@1370 1905 }
nickjillings@1370 1906 }
nickjillings@1370 1907 }
nickjillings@1370 1908 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 1909 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 1910 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 1911
nicholas@2535 1912 this.moveToPosition = function (new_index) {
nicholas@2535 1913 new_index = Math.min(new_index, this.parent.children.length);
nicholas@2535 1914 var curr_index = this.parent.children.findIndex(function (elem) {
nicholas@2535 1915 if (elem == this) {
nicholas@2535 1916 return true;
nicholas@2535 1917 } else {
nicholas@2535 1918 return false;
nicholas@2535 1919 }
nicholas@2535 1920 }, this);
n@2416 1921 // Split at the current location to remove the node and shift all the children up
nicholas@2535 1922 var tail = this.parent.children.splice(curr_index + 1);
n@2416 1923 this.parent.children.pop();
n@2416 1924 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1925
n@2416 1926 //Split at the new location and insert the node
n@2416 1927 tail = this.parent.children.splice(new_index);
n@2416 1928 this.parent.children.push(this);
n@2416 1929 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1930
n@2416 1931 // Re-build the specification
n@2416 1932 this.parent.specification.options = [];
n@2416 1933 this.parent.childrenDOM.innerHTML = "";
n@2416 1934 for (var obj of this.parent.children) {
n@2416 1935 this.parent.specification.options.push(obj.specification);
n@2416 1936 this.parent.childrenDOM.appendChild(obj.rootDOM);
n@2416 1937 }
nicholas@2535 1938 this.parent.children.forEach(function (obj, index) {
n@2420 1939 obj.moveButtons.disable(index);
n@2420 1940 });
n@2414 1941 }
nicholas@2535 1942
n@2420 1943 this.moveButtons = {
n@2420 1944 root_up: document.createElement("button"),
n@2420 1945 root_down: document.createElement("button"),
n@2420 1946 parent: this,
nicholas@2535 1947 handleEvent: function (event) {
n@2420 1948 var index = this.parent.parent.children.indexOf(this.parent);
n@2420 1949 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 1950 index = Math.max(index - 1, 0);
n@2420 1951 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 1952 index = Math.min(index + 1, this.parent.parent.children.length - 1);
n@2420 1953 }
n@2420 1954 this.parent.moveToPosition(index);
n@2420 1955 this.disable(index);
n@2420 1956 },
nicholas@2535 1957 disable: function (index) {
n@2420 1958 if (index == 0) {
n@2420 1959 this.root_up.disabled = true;
n@2420 1960 } else {
n@2420 1961 this.root_up.disabled = false;
n@2420 1962 }
nicholas@2535 1963 if (index == this.parent.parent.children.length - 1) {
n@2420 1964 this.root_down.disabled = true;
n@2420 1965 } else {
n@2420 1966 this.root_down.disabled = false;
n@2420 1967 }
n@2420 1968 }
n@2420 1969 }
nicholas@2535 1970 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 1971 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 1972 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 1973 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2420 1974 this.moveButtons.root_up.textContent = "Move Up";
n@2420 1975 this.moveButtons.root_down.textContent = "Move Down";
n@2420 1976 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2420 1977 this.buttonDOM.appendChild(this.moveButtons.root_down);
nickjillings@1370 1978 }
nickjillings@1370 1979 this.addNode = {
nickjillings@1370 1980 root: document.createElement("button"),
nickjillings@1370 1981 parent: this,
nicholas@2535 1982 handleEvent: function () {
nickjillings@2194 1983 var newNode = new this.parent.specification.OptionNode(this.parent.specification);
nickjillings@1370 1984 this.parent.specification.options.push(newNode);
nickjillings@1370 1985 popupObject.show();
nicholas@2535 1986 popupStateNodes.state[5].generate(newNode, this.parent);
nickjillings@1370 1987 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1988 }
nickjillings@1370 1989 }
nickjillings@1370 1990 this.addNode.root.textContent = "Add Survey Entry";
nicholas@2535 1991 this.addNode.root.addEventListener("click", this.addNode, false);
nickjillings@1370 1992 this.buttonDOM.appendChild(this.addNode.root);
nicholas@2535 1993
nicholas@2535 1994 for (var option of this.specification.options) {
nicholas@2535 1995 var newNode = new this.surveyEntryNode(this, option);
nickjillings@1370 1996 this.children.push(newNode);
nickjillings@1370 1997 this.childrenDOM.appendChild(newNode.rootDOM);
nickjillings@1370 1998 }
nicholas@2535 1999
nicholas@2535 2000 this.children.forEach(function (obj, index) {
n@2420 2001 obj.moveButtons.disable(index);
n@2420 2002 });
nickjillings@1370 2003 }
nicholas@2535 2004
nicholas@2535 2005 this.pageNode = function (parent, rootObject) {
nickjillings@1375 2006 this.type = "pageNode";
nickjillings@1370 2007 this.rootDOM = document.createElement("div");
nickjillings@1370 2008 this.titleDOM = document.createElement("span");
nickjillings@1370 2009 this.attributeDOM = document.createElement("div");
nickjillings@1370 2010 this.attributes = [];
nickjillings@1370 2011 this.childrenDOM = document.createElement("div");
nickjillings@1370 2012 this.children = [];
nickjillings@1370 2013 this.buttonDOM = document.createElement("div");
nickjillings@1370 2014 this.parent = parent;
nickjillings@1370 2015 this.specification = rootObject;
nickjillings@1370 2016 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1370 2017 this.rootDOM.className = "node";
nickjillings@1370 2018
nickjillings@1370 2019 var titleDiv = document.createElement('div');
nickjillings@1370 2020 titleDiv.className = "node-title";
nickjillings@1370 2021 this.titleDOM.className = "node-title";
nickjillings@1370 2022 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2023 titleDiv.appendChild(this.titleDOM);
nicholas@2535 2024
nickjillings@1370 2025 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2026 this.childrenDOM.className = "node-children";
nickjillings@1370 2027 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2028
nickjillings@1370 2029 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2030 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2031 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2032 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2033
nickjillings@1370 2034 // Do the comment prefix node
nicholas@2535 2035 var cpn = this.parent.createGeneralNodeDOM("Comment Prefix", "" + this.specification.id + "-commentprefix", this.parent);
nickjillings@1370 2036 cpn.rootDOM.removeChild(cpn.attributeDOM);
nickjillings@1370 2037 var obj = {
nickjillings@1370 2038 root: document.createElement("div"),
nickjillings@1370 2039 input: document.createElement("input"),
nickjillings@1370 2040 parent: this,
nicholas@2535 2041 handleEvent: function () {
nickjillings@1370 2042 this.parent.specification.commentBoxPrefix = event.currentTarget.value;
nickjillings@1370 2043 }
nickjillings@1370 2044 }
nickjillings@1370 2045 cpn.children.push(obj);
nickjillings@1370 2046 cpn.childrenDOM.appendChild(obj.root);
nickjillings@1370 2047 obj.root.appendChild(obj.input);
nicholas@2535 2048 obj.input.addEventListener("change", obj, false);
nickjillings@1370 2049 obj.input.value = this.specification.commentBoxPrefix;
nickjillings@1370 2050 this.childrenDOM.appendChild(cpn.rootDOM);
nickjillings@1370 2051 this.children.push(cpn);
nicholas@2535 2052
nickjillings@1370 2053 // Now both before and after surveys
nicholas@2535 2054 if (this.specification.preTest == undefined) {
nickjillings@2194 2055 this.specification.preTest = new specification.surveyNode(specification);
nickjillings@1370 2056 this.specification.preTest.location = "pre";
nickjillings@1370 2057 }
nicholas@2535 2058 if (this.specification.postTest == undefined) {
nickjillings@2194 2059 this.specification.postTest = new specification.surveyNode(specification);
nickjillings@1370 2060 this.specification.postTest.location = "post";
nickjillings@1370 2061 }
nicholas@2535 2062 var surveyBefore = new this.parent.surveyNode(this, this.specification.preTest, "Pre");
nicholas@2535 2063 var surveyAfter = new this.parent.surveyNode(this, this.specification.postTest, "Post");
nickjillings@1370 2064 this.children.push(surveyBefore);
nickjillings@1370 2065 this.children.push(surveyAfter);
nickjillings@1370 2066 this.childrenDOM.appendChild(surveyBefore.rootDOM);
nickjillings@1370 2067 this.childrenDOM.appendChild(surveyAfter.rootDOM);
nicholas@2535 2068
nickjillings@1370 2069 // Build the attributes
nickjillings@1370 2070 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2071 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2072 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2073 var attrObject = this.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2074 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2075 this.attributes.push(attrObject);
nickjillings@1370 2076 }
nicholas@2535 2077
nickjillings@1370 2078 this.interfaces = [];
nicholas@2535 2079
nicholas@2535 2080 this.getAudioElements = function () {
n@2421 2081 var array = [];
nicholas@2535 2082 for (var i = 0; i < this.children.length; i++) {
n@2421 2083 if (this.children[i].type == "audioElementNode") {
n@2421 2084 array[array.length] = this.children[i];
n@2421 2085 }
n@2421 2086 }
n@2421 2087 return array;
n@2421 2088 }
nicholas@2535 2089
nicholas@2535 2090 this.redrawChildren = function () {
n@2421 2091 this.childrenDOM.innerHTML = "";
nicholas@2535 2092 for (var child of this.children) {
n@2421 2093 this.childrenDOM.appendChild(child.rootDOM);
n@2421 2094 }
n@2421 2095 }
nicholas@2535 2096
nicholas@2535 2097 this.audioElementNode = function (parent, rootObject) {
nickjillings@1375 2098 this.type = "audioElementNode";
nickjillings@1370 2099 this.rootDOM = document.createElement("div");
nickjillings@1370 2100 this.titleDOM = document.createElement("span");
nickjillings@1370 2101 this.attributeDOM = document.createElement("div");
nickjillings@1370 2102 this.attributes = [];
nickjillings@1370 2103 this.childrenDOM = document.createElement("div");
nickjillings@1370 2104 this.children = [];
nickjillings@1370 2105 this.buttonDOM = document.createElement("div");
nickjillings@1370 2106 this.parent = parent;
nickjillings@1370 2107 this.specification = rootObject;
nickjillings@1370 2108 this.schema = specification.schema.getAllElementsByName("audioelement")[0];
nickjillings@1370 2109 this.rootDOM.className = "node";
nickjillings@1370 2110
nickjillings@1370 2111 var titleDiv = document.createElement('div');
nickjillings@1370 2112 titleDiv.className = "node-title";
nickjillings@1370 2113 this.titleDOM.className = "node-title";
nickjillings@1370 2114 this.titleDOM.textContent = "Audio Element";
nickjillings@1370 2115 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2116
nickjillings@1370 2117 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2118 this.childrenDOM.className = "node-children";
nickjillings@1370 2119 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2120
nickjillings@1370 2121 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2122 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2123 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2124 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2125
nickjillings@1370 2126 // Build the attributes
nickjillings@1370 2127 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2128 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2129 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2130 var attrObject = this.parent.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2131 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2132 this.attributes.push(attrObject);
nickjillings@1370 2133 }
nicholas@2535 2134
nickjillings@1370 2135 this.deleteNode = {
nickjillings@1370 2136 root: document.createElement("button"),
nickjillings@1370 2137 parent: this,
nicholas@2535 2138 handleEvent: function () {
nicholas@2535 2139 var i = this.parent.parent.specification.audioElements.findIndex(this.findNode, this);
nickjillings@1370 2140 if (i >= 0) {
nickjillings@1370 2141 var aeList = this.parent.parent.specification.audioElements;
nicholas@2535 2142 if (i < aeList.length - 1) {
nicholas@2535 2143 aeList = aeList.slice(0, i).concat(aeList.slice(i + 1));
nickjillings@1370 2144 } else {
nicholas@2535 2145 aeList = aeList.slice(0, i);
nickjillings@1370 2146 }
nickjillings@1370 2147 }
nicholas@2535 2148 i = this.parent.parent.children.findIndex(function (element, index, array) {
nickjillings@1370 2149 if (element == this.parent)
nickjillings@1370 2150 return true;
nickjillings@1370 2151 else
nickjillings@1370 2152 return false;
nicholas@2535 2153 }, this);
nickjillings@1370 2154 if (i >= 0) {
nickjillings@1370 2155 var childList = this.parent.children;
nicholas@2535 2156 if (i < aeList.length - 1) {
nicholas@2535 2157 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 2158 } else {
nicholas@2535 2159 childList = childList.slice(0, i);
nickjillings@1370 2160 }
nickjillings@1370 2161 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nickjillings@1370 2162 }
nickjillings@1370 2163 },
nicholas@2535 2164 findNode: function (element, index, array) {
nickjillings@1370 2165 if (element == this.parent.specification)
nickjillings@1370 2166 return true;
nickjillings@1370 2167 else
nickjillings@1370 2168 return false;
nickjillings@1370 2169 }
nickjillings@1370 2170 }
nickjillings@1370 2171 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 2172 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 2173 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 2174
n@2421 2175 this.moveButtons = {
n@2421 2176 root_up: document.createElement("button"),
n@2421 2177 root_down: document.createElement("button"),
n@2421 2178 parent: this,
nicholas@2535 2179 handleEvent: function (event) {
n@2421 2180 var index = this.parent.parent.getAudioElements().indexOf(this.parent);
n@2421 2181 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 2182 index = Math.max(index - 1, 0);
n@2421 2183 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 2184 index = Math.min(index + 1, this.parent.parent.getAudioElements().length - 1);
n@2421 2185 }
n@2421 2186 this.parent.moveToPosition(index);
n@2421 2187 this.disable(index);
n@2421 2188 },
nicholas@2535 2189 disable: function (index) {
n@2421 2190 if (index == 0) {
n@2421 2191 this.root_up.disabled = true;
n@2421 2192 } else {
n@2421 2193 this.root_up.disabled = false;
n@2421 2194 }
nicholas@2535 2195 if (index == this.parent.parent.getAudioElements().length - 1) {
n@2421 2196 this.root_down.disabled = true;
n@2421 2197 } else {
n@2421 2198 this.root_down.disabled = false;
n@2421 2199 }
n@2421 2200 }
n@2421 2201 }
nicholas@2535 2202 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 2203 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 2204 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 2205 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2421 2206 this.moveButtons.root_up.textContent = "Move Up";
n@2421 2207 this.moveButtons.root_down.textContent = "Move Down";
n@2421 2208 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2421 2209 this.buttonDOM.appendChild(this.moveButtons.root_down);
nicholas@2535 2210
nicholas@2535 2211 this.moveToPosition = function (new_index) {
nicholas@2535 2212
n@2421 2213 // Get the zero-th Object
n@2421 2214 var zero_object = this.parent.getAudioElements()[0];
n@2421 2215 var parent_children_root_index = this.parent.children.indexOf(zero_object);
n@2421 2216 // splice out the array for processing
n@2421 2217 var process_array = this.parent.children.splice(parent_children_root_index);
nicholas@2535 2218
nicholas@2535 2219
n@2421 2220 new_index = Math.min(new_index, process_array.length);
nicholas@2535 2221 var curr_index = process_array.findIndex(function (elem) {
nicholas@2535 2222 if (elem == this) {
nicholas@2535 2223 return true;
nicholas@2535 2224 } else {
nicholas@2535 2225 return false;
nicholas@2535 2226 }
nicholas@2535 2227 }, this);
nicholas@2535 2228
n@2421 2229 // Split at the current location to remove the node and shift all the children up
nicholas@2535 2230 var tail = process_array.splice(curr_index + 1);
n@2421 2231 process_array.pop();
n@2421 2232 process_array = process_array.concat(tail);
nicholas@2535 2233
n@2421 2234 //Split at the new location and insert the node
n@2421 2235 tail = process_array.splice(new_index);
n@2421 2236 process_array.push(this);
n@2421 2237 process_array = process_array.concat(tail);
nicholas@2535 2238
n@2421 2239 // Re-attach to the parent.children
n@2421 2240 this.parent.children = this.parent.children.concat(process_array);
nicholas@2535 2241
n@2421 2242 // Re-build the specification
n@2421 2243 this.parent.specification.audioElements = [];
n@2421 2244 for (var obj of process_array) {
n@2421 2245 this.parent.specification.audioElements.push(obj.specification);
n@2421 2246 }
n@2421 2247 this.parent.redrawChildren();
nicholas@2535 2248
nicholas@2535 2249 process_array.forEach(function (obj, index) {
n@2421 2250 obj.moveButtons.disable(index);
n@2421 2251 });
nicholas@2535 2252
n@2421 2253 }
nickjillings@1370 2254 }
nicholas@2535 2255
nicholas@2535 2256 this.commentQuestionNode = function (parent, rootObject) {
nickjillings@1375 2257 this.type = "commentQuestionNode";
nickjillings@1370 2258 this.rootDOM = document.createElement("div");
nickjillings@1370 2259 this.titleDOM = document.createElement("span");
nickjillings@1370 2260 this.attributeDOM = document.createElement("div");
nickjillings@1370 2261 this.attributes = [];
nickjillings@1370 2262 this.childrenDOM = document.createElement("div");
nickjillings@1370 2263 this.children = [];
nickjillings@1370 2264 this.buttonDOM = document.createElement("div");
nickjillings@1370 2265 this.parent = parent;
nickjillings@1370 2266 this.specification = rootObject;
nickjillings@1370 2267 this.schema = specification.schema.getAllElementsByName("page")[0];
n@2421 2268 this.rootDOM.className = "node audio-element";
nickjillings@1370 2269
nickjillings@1370 2270 var titleDiv = document.createElement('div');
nickjillings@1370 2271 titleDiv.className = "node-title";
nickjillings@1370 2272 this.titleDOM.className = "node-title";
nickjillings@1370 2273 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2274 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2275
nickjillings@1370 2276 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2277 this.childrenDOM.className = "node-children";
nickjillings@1370 2278 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2279
nickjillings@1370 2280 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2281 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2282 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2283 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2284
nickjillings@1370 2285 }
nicholas@2535 2286
nickjillings@1374 2287 // Build the components
nickjillings@1310 2288 if (this.specification.interfaces.length == 0) {
nickjillings@2194 2289 this.specification.interfaces.push(new specification.interfaceNode(specification));
nickjillings@1310 2290 }
nicholas@2535 2291 for (var interfaceObj of this.specification.interfaces) {
nicholas@2535 2292 var newInterface = new this.parent.interfaceNode(this.parent, interfaceObj);
nicholas@2535 2293 newInterface.build("Interface", "" + this.specification.id + "-interface", this.childrenDOM);
nickjillings@1381 2294 this.children.push(newInterface);
nickjillings@1381 2295 this.interfaces.push(newInterface);
nickjillings@1381 2296 }
nicholas@2535 2297
nicholas@2535 2298 for (var elements of this.specification.audioElements) {
nicholas@2535 2299 var audioElementDOM = new this.audioElementNode(this, elements);
nickjillings@1374 2300 this.children.push(audioElementDOM);
nickjillings@1374 2301 this.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1374 2302 }
nicholas@2535 2303
nicholas@2535 2304 this.getAudioElements().forEach(function (elem) {
n@2421 2305 elem.moveButtons.disable();
n@2421 2306 });
nicholas@2535 2307
nickjillings@1370 2308 this.addInterface = {
nickjillings@1370 2309 root: document.createElement("button"),
nickjillings@1370 2310 parent: this,
nicholas@2535 2311 handleEvent: function () {
nickjillings@2194 2312 var InterfaceObj = new specification.interfaceNode(specification);
nicholas@2535 2313 var newInterface = new this.parent.parent.interfaceNode(this.parent.parent, InterfaceObj);
nicholas@2535 2314 newInterface.build("Interface", "" + this.parent.specification.id + "-interface", this.parent.childrenDOM);
nickjillings@1370 2315 this.parent.children.push(newInterface);
nickjillings@1370 2316 this.parent.specification.interfaces.push(InterfaceObj);
nickjillings@1370 2317 this.parent.interfaces.push(newInterface);
nickjillings@1370 2318 }
nickjillings@1370 2319 }
nickjillings@1370 2320 this.addInterface.root.textContent = "Add Interface";
nicholas@2535 2321 this.addInterface.root.addEventListener("click", this.addInterface, false);
nickjillings@1370 2322 this.buttonDOM.appendChild(this.addInterface.root);
nicholas@2535 2323
nickjillings@1370 2324 this.addAudioElement = {
nickjillings@1370 2325 root: document.createElement("button"),
nickjillings@1370 2326 parent: this,
nicholas@2535 2327 handleEvent: function () {
nickjillings@2194 2328 var audioElementObject = new this.parent.specification.audioElementNode(specification);
nicholas@2535 2329 var audioElementDOM = new this.parent.audioElementNode(this.parent, audioElementObject);
nickjillings@1370 2330 this.parent.specification.audioElements.push(audioElementObject);
nickjillings@1370 2331 this.parent.children.push(audioElementDOM);
nickjillings@1370 2332 this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1370 2333 }
nickjillings@1370 2334 }
nickjillings@1370 2335 this.addAudioElement.root.textContent = "Add Audio Element";
nicholas@2535 2336 this.addAudioElement.root.addEventListener("click", this.addAudioElement, false);
nickjillings@1370 2337 this.buttonDOM.appendChild(this.addAudioElement.root);
nickjillings@1370 2338 }
nicholas@2535 2339 }