annotate test_create/test_core.js @ 2609:5409400fc1fb

Fix for #73
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 14 Nov 2016 20:02:08 +0000
parents fddfb7c0b4fa
children b982e92a8dad
rev   line source
nickjillings@1370 1 var interfaceSpecs;
nickjillings@1370 2 var xmlHttp;
nickjillings@1370 3 var popupObject;
nickjillings@1370 4 var popupStateNodes;
nickjillings@1370 5 var specification;
nickjillings@1370 6 var convert;
nickjillings@1370 7 var attributeText;
nicholas@2355 8 var page_lang = "en";
nickjillings@1370 9
nickjillings@1370 10 // Firefox does not have an XMLDocument.prototype.getElementsByName
nickjillings@1370 11 // and there is no searchAll style command, this custom function will
nickjillings@1370 12 // search all children recusrively for the name. Used for XSD where all
nickjillings@1370 13 // element nodes must have a name and therefore can pull the schema node
nicholas@2535 14 XMLDocument.prototype.getAllElementsByName = function (name) {
nickjillings@1370 15 name = String(name);
nickjillings@1370 16 var selected = this.documentElement.getAllElementsByName(name);
nickjillings@1370 17 return selected;
nickjillings@1370 18 }
nickjillings@1370 19
nicholas@2535 20 Element.prototype.getAllElementsByName = function (name) {
nickjillings@1370 21 name = String(name);
nickjillings@1370 22 var selected = [];
nickjillings@1370 23 var node = this.firstElementChild;
nicholas@2535 24 while (node != null) {
nicholas@2535 25 if (node.getAttribute('name') == name) {
nickjillings@1370 26 selected.push(node);
nickjillings@1370 27 }
nicholas@2535 28 if (node.childElementCount > 0) {
nickjillings@1370 29 selected = selected.concat(node.getAllElementsByName(name));
nickjillings@1370 30 }
nickjillings@1370 31 node = node.nextElementSibling;
nickjillings@1370 32 }
nickjillings@1370 33 return selected;
nickjillings@1370 34 }
nickjillings@1370 35
nicholas@2535 36 XMLDocument.prototype.getAllElementsByTagName = function (name) {
nickjillings@1370 37 name = String(name);
nickjillings@1370 38 var selected = this.documentElement.getAllElementsByTagName(name);
nickjillings@1370 39 return selected;
nickjillings@1370 40 }
nickjillings@1370 41
nicholas@2535 42 Element.prototype.getAllElementsByTagName = function (name) {
nickjillings@1370 43 name = String(name);
nickjillings@1370 44 var selected = [];
nickjillings@1370 45 var node = this.firstElementChild;
nicholas@2535 46 while (node != null) {
nicholas@2535 47 if (node.nodeName == name) {
nickjillings@1370 48 selected.push(node);
nickjillings@1370 49 }
nicholas@2535 50 if (node.childElementCount > 0) {
nickjillings@1370 51 selected = selected.concat(node.getAllElementsByTagName(name));
nickjillings@1370 52 }
nickjillings@1370 53 node = node.nextElementSibling;
nickjillings@1370 54 }
nickjillings@1370 55 return selected;
nickjillings@1370 56 }
nickjillings@1370 57
nickjillings@1370 58 // Firefox does not have an XMLDocument.prototype.getElementsByName
nickjillings@1370 59 if (typeof XMLDocument.prototype.getElementsByName != "function") {
nicholas@2535 60 XMLDocument.prototype.getElementsByName = function (name) {
nickjillings@1370 61 name = String(name);
nickjillings@1370 62 var node = this.documentElement.firstElementChild;
nickjillings@1370 63 var selected = [];
nicholas@2535 64 while (node != null) {
nicholas@2535 65 if (node.getAttribute('name') == name) {
nickjillings@1370 66 selected.push(node);
nickjillings@1370 67 }
nickjillings@1370 68 node = node.nextElementSibling;
nickjillings@1370 69 }
nickjillings@1370 70 return selected;
nickjillings@1370 71 }
nickjillings@1370 72 }
nickjillings@1370 73
nicholas@2535 74 window.onload = function () {
nickjillings@1370 75 specification = new Specification();
nickjillings@1370 76 convert = new SpecificationToHTML();
nickjillings@1370 77 xmlHttp = new XMLHttpRequest();
nicholas@2535 78 xmlHttp.open("GET", "test_create/interface-specs.xml", true);
nicholas@2535 79 xmlHttp.onload = function () {
nickjillings@1370 80 var parse = new DOMParser();
nicholas@2535 81 interfaceSpecs = parse.parseFromString(xmlHttp.response, 'text/xml');
nickjillings@1370 82 buildPage();
nickjillings@1370 83 popupObject.postNode(popupStateNodes.state[0])
nickjillings@1370 84 }
nickjillings@1370 85 xmlHttp.send();
nicholas@2535 86
nickjillings@1370 87 var xsdGet = new XMLHttpRequest();
nicholas@2535 88 xsdGet.open("GET", "xml/test-schema.xsd", true);
nicholas@2535 89 xsdGet.onload = function () {
nickjillings@1370 90 var parse = new DOMParser();
nicholas@2535 91 specification.schema = parse.parseFromString(xsdGet.response, 'text/xml');;
nickjillings@1370 92 }
nickjillings@1370 93 xsdGet.send();
nicholas@2535 94
nickjillings@1370 95 var jsonAttribute = new XMLHttpRequest();
nicholas@2535 96 jsonAttribute.open("GET", "test_create/attributes.json", true);
nicholas@2535 97 jsonAttribute.onload = function () {
nickjillings@1370 98 attributeText = JSON.parse(jsonAttribute.response)
nickjillings@1370 99 }
nickjillings@1370 100 jsonAttribute.send();
nickjillings@1370 101 }
nickjillings@1370 102
nicholas@2535 103 function buildPage() {
nicholas@2535 104 popupObject = new function () {
nickjillings@1370 105 this.object = document.getElementById("popupHolder");
nickjillings@1370 106 this.blanket = document.getElementById("blanket");
nickjillings@1370 107
nickjillings@1370 108 this.popupTitle = document.createElement("div");
nickjillings@1370 109 this.popupTitle.id = "popup-title-holder";
nickjillings@1370 110 this.popupTitle.align = "center";
nickjillings@1370 111 this.titleDOM = document.createElement("span");
nickjillings@1370 112 this.titleDOM.id = "popup-title";
nickjillings@1370 113 this.popupTitle.appendChild(this.titleDOM);
nickjillings@1370 114 this.object.appendChild(this.popupTitle);
nickjillings@1370 115
nickjillings@1370 116 this.popupContent = document.createElement("div");
nickjillings@1370 117 this.popupContent.id = "popup-content";
nickjillings@1370 118 this.object.appendChild(this.popupContent);
nicholas@2535 119
nickjillings@1370 120 this.proceedButton = document.createElement("button");
nickjillings@1370 121 this.proceedButton.id = "popup-proceed";
nickjillings@2108 122 this.proceedButton.className = "popup-button";
nickjillings@1370 123 this.proceedButton.textContent = "Next";
nicholas@2535 124 this.proceedButton.onclick = function () {
nickjillings@1370 125 popupObject.popupContent.innerHTML = null;
nicholas@2535 126 if (typeof popupObject.shownObject.continue == "function") {
nickjillings@2110 127 popupObject.shownObject.continue();
nickjillings@2110 128 } else {
nickjillings@2110 129 popupObject.hide();
nickjillings@2110 130 }
nickjillings@1370 131 };
nickjillings@1370 132 this.object.appendChild(this.proceedButton);
nicholas@2535 133
nickjillings@2108 134 this.backButton = document.createElement("button");
nickjillings@2108 135 this.backButton.id = "popup-back";
nickjillings@2108 136 this.backButton.className = "popup-button";
nickjillings@2108 137 this.backButton.textContent = "Back";
nicholas@2535 138 this.backButton.onclick = function () {
nickjillings@2108 139 popupObject.popupContent.innerHTML = null;
nickjillings@2108 140 popupObject.shownObject.back();
nickjillings@2108 141 };
nickjillings@2108 142 this.object.appendChild(this.backButton);
nicholas@2535 143
nickjillings@1370 144 this.shownObject;
nickjillings@1370 145
nicholas@2535 146 this.resize = function () {
nickjillings@1370 147 var w = window.innerWidth;
nickjillings@1370 148 var h = window.innerHeight;
nicholas@2535 149 this.object.style.left = Math.floor((w - 750) / 2) + 'px';
nicholas@2535 150 this.object.style.top = Math.floor((h - 500) / 2) + 'px';
nickjillings@1370 151 }
nickjillings@1370 152
nicholas@2535 153 this.show = function () {
nickjillings@1370 154 this.object.style.visibility = "visible";
nickjillings@1370 155 this.blanket.style.visibility = "visible";
nickjillings@2108 156 if (typeof this.shownObject.back == "function") {
nickjillings@2108 157 this.backButton.style.visibility = "visible";
nickjillings@2108 158 } else {
nickjillings@2108 159 this.backButton.style.visibility = "hidden";
nickjillings@2108 160 }
nickjillings@1370 161 }
nickjillings@1370 162
nicholas@2535 163 this.hide = function () {
nickjillings@1370 164 this.object.style.visibility = "hidden";
nickjillings@1370 165 this.blanket.style.visibility = "hidden";
nickjillings@2108 166 this.backButton.style.visibility = "hidden";
nickjillings@1370 167 }
nickjillings@1370 168
nicholas@2535 169 this.postNode = function (postObject) {
nickjillings@1370 170 //Passed object must have the following:
nickjillings@1370 171 // Title: text to show in the title
nickjillings@1370 172 // Content: HTML DOM to show on the page
nickjillings@1370 173 // On complete this HTML DOM is destroyed so make sure it is referenced elsewhere for processing
nickjillings@1370 174 this.titleDOM.textContent = postObject.title;
nickjillings@1370 175 this.popupContent.appendChild(postObject.content);
nickjillings@1370 176 this.shownObject = postObject;
nickjillings@2108 177 if (typeof this.shownObject.back == "function") {
nickjillings@2108 178 this.backButton.style.visibility = "visible";
nickjillings@2108 179 } else {
nickjillings@2108 180 this.backButton.style.visibility = "hidden";
nickjillings@2108 181 }
nickjillings@2110 182 if (typeof this.shownObject.continue == "function") {
nickjillings@2110 183 this.proceedButton.textContent = "Next";
nickjillings@2110 184 } else {
nickjillings@2110 185 this.proceedButton.textContent = "Finish";
nickjillings@2110 186 }
nickjillings@2108 187 this.show();
nickjillings@1370 188 }
nickjillings@1370 189
nickjillings@1370 190 this.resize();
nickjillings@1370 191 this.hide();
nickjillings@1370 192 };
nicholas@2535 193
nicholas@2535 194 popupStateNodes = new function () {
nickjillings@1370 195 // This defines the several popup states wanted
nickjillings@1370 196 this.state = [];
nicholas@2535 197 this.state[0] = new function () {
nickjillings@1370 198 this.title = "Welcome";
nickjillings@1370 199 this.content = document.createElement("div");
nickjillings@1370 200 this.content.id = "state-0";
nickjillings@1370 201 var span = document.createElement("span");
nickjillings@1370 202 span.textContent = "Welcome to the WAET test creator tool. This will allow you to create a new test from scratch to suit your testing needs. If you wish to update a test file, please drag and drop the XML document into the area below for processing, otherwise press 'Next' to start a new test. This tool generates files for the WAET 1.2.0 version."
nickjillings@1370 203 this.content.appendChild(span);
nickjillings@1370 204 this.dragArea = document.createElement("div");
nickjillings@1373 205 this.dragArea.className = "drag-area";
nickjillings@1373 206 this.dragArea.id = "project-drop";
nickjillings@1370 207 this.content.appendChild(this.dragArea);
nicholas@2535 208
nicholas@2535 209 this.dragArea.addEventListener('dragover', function (e) {
nickjillings@1373 210 e.stopPropagation();
nickjillings@1373 211 e.preventDefault();
nickjillings@1373 212 e.dataTransfer.dropEffect = 'copy';
nickjillings@1373 213 e.currentTarget.className = "drag-area drag-over";
nickjillings@1373 214 });
nicholas@2535 215
nicholas@2535 216 this.dragArea.addEventListener('dragexit', function (e) {
nickjillings@1373 217 e.stopPropagation();
nickjillings@1373 218 e.preventDefault();
nickjillings@1373 219 e.dataTransfer.dropEffect = 'copy';
nickjillings@1373 220 e.currentTarget.className = "drag-area";
nickjillings@1373 221 });
nicholas@2535 222
nicholas@2535 223 this.dragArea.addEventListener('drop', function (e) {
nickjillings@1373 224 e.stopPropagation();
nickjillings@1373 225 e.preventDefault();
nickjillings@1373 226 e.currentTarget.className = "drag-area drag-dropped";
nickjillings@1373 227 var files = e.dataTransfer.files[0];
nickjillings@1374 228 var reader = new FileReader();
nicholas@2535 229 reader.onload = function (decoded) {
nickjillings@1374 230 var parse = new DOMParser();
nicholas@2535 231 specification.decode(parse.parseFromString(decoded.target.result, 'text/xml'));
nickjillings@1374 232 popupObject.hide();
nickjillings@1375 233 popupObject.popupContent.innerHTML = null;
nickjillings@1374 234 convert.convert(document.getElementById('content'));
nickjillings@1374 235 }
nickjillings@1374 236 reader.readAsText(files);
nickjillings@1373 237 });
nickjillings@1370 238
nicholas@2535 239
nicholas@2535 240 this.continue = function () {
nickjillings@1370 241 popupObject.postNode(popupStateNodes.state[1]);
nickjillings@1370 242 }
nickjillings@1370 243 }
nicholas@2535 244 this.state[1] = new function () {
nickjillings@1370 245 this.title = "Select your interface";
nickjillings@1370 246 this.content = document.createElement("div");
nickjillings@1370 247 this.content.id = "state-1";
nickjillings@1370 248 var spnH = document.createElement('div');
nickjillings@1370 249 var span = document.createElement("span");
nickjillings@1370 250 span.textContent = "Please select your interface from the list shown below. This will define the various options which are available. This can later be changed.";
nickjillings@1370 251 spnH.appendChild(span);
nickjillings@1370 252 this.content.appendChild(spnH);
nickjillings@1370 253 this.select = document.createElement("select");
nicholas@2355 254 this.content.appendChild(this.select);
nicholas@2355 255 this.description = document.createElement("p");
nicholas@2355 256 this.content.appendChild(this.description);
nicholas@2390 257 this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].getElementsByTagName('test');
nicholas@2535 258 for (var i = 0; i < this.testsXML.length; i++) {
nickjillings@1370 259 var option = document.createElement('option');
nickjillings@1370 260 option.value = this.testsXML[i].getAttribute('name');
nickjillings@1370 261 option.textContent = this.testsXML[i].getAttribute('name');
nickjillings@1370 262 this.select.appendChild(option);
nickjillings@1370 263 }
nicholas@2535 264 this.handleEvent = function (event) {
nicholas@2355 265 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
nicholas@2355 266 var descriptors = testXML.getAllElementsByTagName("description");
nicholas@2355 267 this.description.textContent = "";
nicholas@2535 268 for (var i = 0; i < descriptors.length; i++) {
nicholas@2355 269 if (descriptors[i].getAttribute("lang") == page_lang) {
nicholas@2355 270 this.description.textContent = descriptors[i].textContent;
nicholas@2355 271 }
nicholas@2355 272 }
nicholas@2355 273 }
nicholas@2535 274 this.select.addEventListener("change", this);
nicholas@2355 275 this.handleEvent();
nicholas@2535 276 this.continue = function () {
nickjillings@1370 277 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
nickjillings@1370 278 specification.interface = testXML.getAttribute("interface");
nicholas@2535 279 if (specification.interfaces == null) {
nickjillings@2194 280 specification.interfaces = new specification.interfaceNode(specification);
nickjillings@2108 281 }
nicholas@2535 282 if (specification.metrics == null) {
nickjillings@2108 283 specification.metrics = new specification.metricNode();
nickjillings@2108 284 }
nickjillings@1370 285 popupStateNodes.state[2].generate();
nickjillings@1370 286 popupObject.postNode(popupStateNodes.state[2]);
nickjillings@1370 287 }
nicholas@2535 288 this.back = function () {
nickjillings@2108 289 popupObject.postNode(popupStateNodes.state[0]);
nickjillings@2108 290 }
nickjillings@1370 291 }
nicholas@2535 292 this.state[2] = new function () {
nickjillings@1370 293 this.title = "Test Checks & Restrictions";
nickjillings@1370 294 this.content = document.createElement("div");
nickjillings@1370 295 this.content.id = "state-1";
nickjillings@1370 296 var spnH = document.createElement('div');
nickjillings@1370 297 var span = document.createElement("span");
nickjillings@1370 298 span.textContent = "Select your test checks and restrictions. Greyed out items are fixed by the test/interface and cannot be changed";
nickjillings@1370 299 spnH.appendChild(span);
nickjillings@1370 300 this.content.appendChild(spnH);
nickjillings@1370 301 var holder = document.createElement("div");
nickjillings@1370 302 this.options = [];
nickjillings@1370 303 this.testXML = null;
nickjillings@1370 304 this.interfaceXML = null;
nickjillings@2108 305 this.dynamicContent = document.createElement("div");
nickjillings@2108 306 this.content.appendChild(this.dynamicContent);
nicholas@2535 307 this.generate = function () {
nickjillings@2108 308 this.options = [];
nickjillings@2108 309 this.dynamicContent.innerHTML = null;
nickjillings@1370 310 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 311 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 312 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 313 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 314 this.testXML = this.testXML.getAllElementsByTagName("checks");
nicholas@2390 315 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 316 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 317 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 318 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 319 var testNode
nicholas@2535 320 if (this.testXML.length > 0) {
nickjillings@1370 321 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 322 if (testNode.length != 0) {
nicholas@2535 323 testNode = testNode[0];
nicholas@2535 324 } else {
nicholas@2535 325 testNode = undefined;
nicholas@2535 326 }
nickjillings@1370 327 } else {
nickjillings@1370 328 testNode = undefined;
nickjillings@1370 329 }
nickjillings@2108 330 var obj = {
nickjillings@2108 331 root: document.createElement("div"),
nickjillings@2109 332 text: document.createElement("label"),
nickjillings@2108 333 input: document.createElement("input"),
nickjillings@2108 334 parent: this,
nickjillings@2108 335 name: checkName,
nicholas@2535 336 handleEvent: function (event) {
nickjillings@2108 337 if (this.input.checked) {
nickjillings@2108 338 // Add to specification.interfaces.option
nicholas@2535 339 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 340 if (element.name == this.name) {
nicholas@2535 341 return true;
nicholas@2535 342 } else {
nicholas@2535 343 return false;
nicholas@2535 344 }
nicholas@2535 345 }, this);
nickjillings@2108 346 if (included == null) {
nicholas@2535 347 specification.interfaces.options.push({
nicholas@2535 348 type: "check",
nicholas@2535 349 name: this.name
nicholas@2535 350 });
nickjillings@2108 351 }
nickjillings@2108 352 } else {
nickjillings@2108 353 // Remove from specification.interfaces.option
nicholas@2535 354 var position = specification.interfaces.options.findIndex(function (element, index, array) {
nicholas@2535 355 if (element.name == this.name) {
nicholas@2535 356 return true;
nicholas@2535 357 } else {
nicholas@2535 358 return false;
nicholas@2535 359 }
nicholas@2535 360 }, this);
nickjillings@2108 361 if (position >= 0) {
nicholas@2535 362 specification.interfaces.options.splice(position, 1);
nickjillings@2108 363 }
nickjillings@2108 364 }
nickjillings@2108 365 }
nickjillings@1370 366 }
nicholas@2535 367
nicholas@2535 368 obj.input.addEventListener("click", obj);
nickjillings@2108 369 obj.root.className = "popup-checkbox";
nickjillings@2108 370 obj.input.type = "checkbox";
nicholas@2535 371 obj.input.setAttribute('id', checkName);
nicholas@2535 372 obj.text.setAttribute("for", checkName);
nickjillings@2108 373 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 374 obj.root.appendChild(obj.input);
nickjillings@2108 375 obj.root.appendChild(obj.text);
nicholas@2535 376 if (testNode != undefined) {
nicholas@2535 377 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 378 obj.input.checked = true;
nickjillings@1370 379 }
nicholas@2535 380 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 381 obj.input.disabled = true;
nickjillings@2108 382 obj.input.checked = false;
nickjillings@2108 383 obj.root.className = "popup-checkbox disabled";
nicholas@2535 384 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 385 obj.input.disabled = true;
nickjillings@2108 386 obj.input.checked = true;
nickjillings@2108 387 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 388 }
nickjillings@2108 389 } else {
nicholas@2535 390 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 391 obj.input.checked = true;
nickjillings@2108 392 }
nicholas@2535 393 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 394 obj.input.disabled = true;
nickjillings@2108 395 obj.input.checked = false;
nickjillings@2108 396 obj.root.className = "popup-checkbox disabled";
nicholas@2535 397 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 398 obj.input.disabled = true;
nickjillings@2108 399 obj.input.checked = true;
nickjillings@2108 400 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 401 }
nickjillings@1370 402 }
nicholas@2535 403 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 404 if (element.name == this.name) {
nicholas@2535 405 return true;
nicholas@2535 406 } else {
nicholas@2535 407 return false;
nicholas@2535 408 }
nicholas@2535 409 }, obj);
nickjillings@2108 410 if (included != undefined) {
nickjillings@2108 411 obj.input.checked = true;
nickjillings@2108 412 }
nickjillings@2108 413 obj.handleEvent();
nickjillings@2108 414 this.options.push(obj);
nickjillings@2108 415 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 416 }
nickjillings@1370 417 }
nicholas@2535 418 this.continue = function () {
nickjillings@1370 419 popupStateNodes.state[3].generate();
nickjillings@1370 420 popupObject.postNode(popupStateNodes.state[3]);
nickjillings@1370 421 }
nicholas@2535 422 this.back = function () {
nickjillings@2108 423 popupObject.postNode(popupStateNodes.state[1]);
nickjillings@2108 424 }
nickjillings@1370 425 }
nicholas@2535 426 this.state[3] = new function () {
nickjillings@1370 427 this.title = "Test Metrics";
nickjillings@1370 428 this.content = document.createElement("div");
nickjillings@1370 429 this.content.id = "state-1";
nickjillings@1370 430 var spnH = document.createElement('div');
nickjillings@1370 431 var span = document.createElement("span");
nickjillings@1370 432 span.textContent = "Select which data points to include in the exported results XML. Some of this is required for certain post script analysis. See the documentation for further details";
nickjillings@1370 433 spnH.appendChild(span);
nickjillings@1370 434 this.content.appendChild(spnH);
nickjillings@1370 435 this.options = [];
nickjillings@1370 436 this.checkText;
nickjillings@1370 437 this.testXML;
nickjillings@1370 438 this.interfaceXML;
nickjillings@2108 439 this.dynamicContent = document.createElement("div");
nickjillings@2108 440 this.content.appendChild(this.dynamicContent);
nicholas@2535 441 this.generate = function () {
nickjillings@2108 442 this.options = [];
nickjillings@2108 443 this.dynamicContent.innerHTML = null;
nickjillings@1370 444 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 445 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 446 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 447 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
nickjillings@1370 448 this.testXML = this.testXML.getAllElementsByTagName("metrics");
nicholas@2390 449 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 450 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 451 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 452 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 453 var testNode
nicholas@2535 454 if (this.testXML.length > 0) {
nickjillings@1370 455 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 456 if (testNode.length != 0) {
nicholas@2535 457 testNode = testNode[0];
nicholas@2535 458 } else {
nicholas@2535 459 testNode = undefined;
nicholas@2535 460 }
nickjillings@1370 461 } else {
nickjillings@1370 462 testNode = undefined;
nickjillings@1370 463 }
nickjillings@2108 464 var obj = {
nickjillings@2108 465 root: document.createElement("div"),
nickjillings@2109 466 text: document.createElement("label"),
nickjillings@2108 467 input: document.createElement("input"),
nickjillings@2108 468 parent: this,
nickjillings@2108 469 name: checkName,
nicholas@2535 470 handleEvent: function (event) {
nickjillings@2108 471 if (this.input.checked) {
nickjillings@2108 472 // Add to specification.interfaces.option
nicholas@2535 473 var included = specification.metrics.enabled.find(function (element, index, array) {
nicholas@2535 474 if (element == this.name) {
nicholas@2535 475 return true;
nicholas@2535 476 } else {
nicholas@2535 477 return false;
nicholas@2535 478 }
nicholas@2535 479 }, this);
nickjillings@2108 480 if (included == null) {
nickjillings@2108 481 specification.metrics.enabled.push(this.name);
nickjillings@2108 482 }
nickjillings@2108 483 } else {
nickjillings@2108 484 // Remove from specification.interfaces.option
nicholas@2535 485 var position = specification.metrics.enabled.findIndex(function (element, index, array) {
nicholas@2535 486 if (element == this.name) {
nicholas@2535 487 return true;
nicholas@2535 488 } else {
nicholas@2535 489 return false;
nicholas@2535 490 }
nicholas@2535 491 }, this);
nickjillings@2108 492 if (position >= 0) {
nicholas@2535 493 specification.metrics.enabled.splice(position, 1);
nickjillings@2108 494 }
nickjillings@2108 495 }
nickjillings@2108 496 }
nickjillings@1370 497 }
nicholas@2535 498
nicholas@2535 499 obj.input.addEventListener("click", obj);
nickjillings@2108 500 obj.root.className = "popup-checkbox";
nickjillings@2108 501 obj.input.type = "checkbox";
nicholas@2535 502 obj.input.setAttribute('id', checkName);
nicholas@2535 503 obj.text.setAttribute("for", checkName);
nickjillings@2108 504 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 505 obj.root.appendChild(obj.input);
nickjillings@2108 506 obj.root.appendChild(obj.text);
nicholas@2535 507 if (testNode != undefined) {
nicholas@2535 508 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 509 obj.input.checked = true;
nickjillings@1370 510 }
nicholas@2535 511 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 512 obj.input.disabled = true;
nickjillings@2108 513 obj.input.checked = false;
nickjillings@2108 514 obj.root.className = "popup-checkbox disabled";
nicholas@2535 515 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 516 obj.input.disabled = true;
nickjillings@2108 517 obj.input.checked = true;
nickjillings@2108 518 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 519 }
nickjillings@2108 520 } else {
nicholas@2535 521 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 522 obj.input.checked = true;
nickjillings@2108 523 }
nicholas@2535 524 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 525 obj.input.disabled = true;
nickjillings@2108 526 obj.input.checked = false;
nickjillings@2108 527 obj.root.className = "popup-checkbox disabled";
nicholas@2535 528 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 529 obj.input.disabled = true;
nickjillings@2108 530 obj.input.checked = true;
nickjillings@2108 531 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 532 }
nickjillings@1370 533 }
nicholas@2535 534 var included = specification.metrics.enabled.find(function (element, index, array) {
nicholas@2535 535 if (element == this.name) {
nicholas@2535 536 return true;
nicholas@2535 537 } else {
nicholas@2535 538 return false;
nicholas@2535 539 }
nicholas@2535 540 }, obj);
nickjillings@2108 541 obj.handleEvent();
nickjillings@2108 542 if (included != undefined) {
nickjillings@2108 543 obj.input.checked = true;
nickjillings@2108 544 }
nickjillings@2108 545 this.options.push(obj);
nickjillings@2108 546 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 547 }
nickjillings@1370 548 }
nicholas@2535 549 this.continue = function () {
nickjillings@1370 550 popupStateNodes.state[4].generate();
nickjillings@1370 551 popupObject.postNode(popupStateNodes.state[4]);
nickjillings@1370 552 }
nicholas@2535 553 this.back = function () {
nickjillings@2108 554 popupObject.postNode(popupStateNodes.state[2]);
nickjillings@2108 555 }
nickjillings@1370 556 }
nicholas@2535 557 this.state[4] = new function () {
nickjillings@1370 558 this.title = "Test Visuals";
nickjillings@1370 559 this.content = document.createElement("div");
nickjillings@1370 560 this.content.id = "state-1";
nickjillings@1370 561 var spnH = document.createElement('div');
nickjillings@1370 562 var span = document.createElement("span");
nickjillings@1370 563 span.textContent = "You can display extra visual content with your interface for the test user to interact with. Select from the available options below. Greyed out options are unavailable for your selected interface";
nickjillings@1370 564 spnH.appendChild(span);
nickjillings@1370 565 this.content.appendChild(spnH);
nickjillings@1370 566 this.options = [];
nickjillings@1370 567 this.checkText;
nickjillings@1370 568 this.testXML;
nickjillings@1370 569 this.interfaceXML;
nickjillings@2108 570 this.dynamicContent = document.createElement("div");
nickjillings@2108 571 this.content.appendChild(this.dynamicContent);
nicholas@2535 572 this.generate = function () {
nickjillings@2108 573 this.options = [];
nickjillings@2108 574 this.dynamicContent.innerHTML = null;
nickjillings@1370 575 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 576 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
nickjillings@1370 577 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 578 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
nickjillings@2108 579 this.testXML = this.testXML.getAllElementsByTagName("show");
nicholas@2390 580 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
nicholas@2535 581 for (var i = 0; i < interfaceXMLChildren.length; i++) {
nicholas@2390 582 var interfaceNode = interfaceXMLChildren[i];
nickjillings@1370 583 var checkName = interfaceNode.getAttribute('name');
nickjillings@1370 584 var testNode
nicholas@2535 585 if (this.testXML.length > 0) {
nickjillings@1370 586 testNode = this.testXML[0].getAllElementsByName(checkName);
nicholas@2535 587 if (testNode.length != 0) {
nicholas@2535 588 testNode = testNode[0];
nicholas@2535 589 } else {
nicholas@2535 590 testNode = undefined;
nicholas@2535 591 }
nickjillings@1370 592 } else {
nickjillings@1370 593 testNode = undefined;
nickjillings@1370 594 }
nickjillings@2108 595 var obj = {
nickjillings@2108 596 root: document.createElement("div"),
nickjillings@2109 597 text: document.createElement("label"),
nickjillings@2108 598 input: document.createElement("input"),
nickjillings@2108 599 parent: this,
nickjillings@2108 600 name: checkName,
nicholas@2535 601 handleEvent: function (event) {
nickjillings@2108 602 if (this.input.checked) {
nickjillings@2108 603 // Add to specification.interfaces.option
nicholas@2535 604 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 605 if (element.name == this.name) {
nicholas@2535 606 return true;
nicholas@2535 607 } else {
nicholas@2535 608 return false;
nicholas@2535 609 }
nicholas@2535 610 }, this);
nickjillings@2108 611 if (included == null) {
nicholas@2535 612 specification.interfaces.options.push({
nicholas@2535 613 type: "show",
nicholas@2535 614 name: this.name
nicholas@2535 615 });
nickjillings@2108 616 }
nickjillings@2108 617 } else {
nickjillings@2108 618 // Remove from specification.interfaces.option
nicholas@2535 619 var position = specification.interfaces.options.findIndex(function (element, index, array) {
nicholas@2535 620 if (element.name == this.name) {
nicholas@2535 621 return true;
nicholas@2535 622 } else {
nicholas@2535 623 return false;
nicholas@2535 624 }
nicholas@2535 625 }, this);
nickjillings@2108 626 if (position >= 0) {
nicholas@2535 627 specification.interfaces.options.splice(position, 1);
nickjillings@2108 628 }
nickjillings@2108 629 }
nickjillings@2108 630 }
nickjillings@1370 631 }
nicholas@2535 632
nicholas@2535 633 obj.input.addEventListener("click", obj);
nickjillings@2108 634 obj.root.className = "popup-checkbox";
nickjillings@2108 635 obj.input.type = "checkbox";
nicholas@2535 636 obj.input.setAttribute('id', checkName);
nicholas@2535 637 obj.text.setAttribute("for", checkName);
nickjillings@2108 638 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
nickjillings@2108 639 obj.root.appendChild(obj.input);
nickjillings@2108 640 obj.root.appendChild(obj.text);
nicholas@2535 641 if (testNode != undefined) {
nicholas@2535 642 if (testNode.getAttribute('default') == 'on') {
nickjillings@2108 643 obj.input.checked = true;
nickjillings@1370 644 }
nicholas@2535 645 if (testNode.getAttribute('support') == "none") {
nickjillings@2108 646 obj.input.disabled = true;
nickjillings@2108 647 obj.input.checked = false;
nickjillings@2108 648 obj.root.className = "popup-checkbox disabled";
nicholas@2535 649 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 650 obj.input.disabled = true;
nickjillings@2108 651 obj.input.checked = true;
nickjillings@2108 652 obj.root.className = "popup-checkbox disabled";
nickjillings@2108 653 }
nickjillings@2108 654 } else {
nicholas@2535 655 if (interfaceNode.getAttribute('default') == 'on') {
nickjillings@2108 656 obj.input.checked = true;
nickjillings@2108 657 }
nicholas@2535 658 if (interfaceNode.getAttribute('support') == "none") {
nickjillings@2108 659 obj.input.disabled = true;
nickjillings@2108 660 obj.input.checked = false;
nickjillings@2108 661 obj.root.className = "popup-checkbox disabled";
nicholas@2535 662 } else if (interfaceNode.getAttribute('support') == "mandatory") {
nickjillings@2108 663 obj.input.disabled = true;
nickjillings@2108 664 obj.input.checked = true;
nickjillings@2108 665 obj.root.className = "popup-checkbox disabled";
nickjillings@1370 666 }
nickjillings@1370 667 }
nicholas@2535 668 var included = specification.interfaces.options.find(function (element, index, array) {
nicholas@2535 669 if (element.name == this.name) {
nicholas@2535 670 return true;
nicholas@2535 671 } else {
nicholas@2535 672 return false;
nicholas@2535 673 }
nicholas@2535 674 }, obj);
nickjillings@2108 675 if (included != undefined) {
nickjillings@2108 676 obj.input.checked = true;
nickjillings@2108 677 }
nickjillings@2108 678 obj.handleEvent();
nickjillings@2108 679 this.options.push(obj);
nickjillings@2108 680 this.dynamicContent.appendChild(obj.root);
nickjillings@1370 681 }
nickjillings@1370 682 }
nicholas@2535 683 this.continue = function () {
nickjillings@1370 684 popupObject.hide();
nickjillings@1370 685 convert.convert(document.getElementById('content'));
nickjillings@1370 686 }
nicholas@2535 687 this.back = function () {
nickjillings@2108 688 popupObject.postNode(popupStateNodes.state[3]);
nickjillings@2108 689 }
nickjillings@1370 690 }
nicholas@2535 691 this.state[5] = new function () {
nickjillings@1370 692 this.title = "Add/Edit Survey Element";
nickjillings@1370 693 this.content = document.createElement("div");
nickjillings@1370 694 this.content.id = "state-1";
nickjillings@1370 695 var spnH = document.createElement('div');
nickjillings@1370 696 var span = document.createElement("span");
nickjillings@1370 697 span.textContent = "You can configure your survey element here. Press 'Continue' to complete your changes.";
nickjillings@1370 698 spnH.appendChild(span);
nickjillings@1370 699 this.content.appendChild(spnH);
nickjillings@1370 700 this.dynamic = document.createElement("div");
nickjillings@1370 701 this.option = null;
nickjillings@1370 702 this.parent = null;
nickjillings@1375 703 this.optionLists = [];
nickjillings@2158 704 this.select = document.createElement("select");
nicholas@2535 705 this.select.setAttribute("name", "type");
nicholas@2535 706 this.select.addEventListener("change", this, false);
nickjillings@2158 707 this.content.appendChild(this.select);
nickjillings@1370 708 this.content.appendChild(this.dynamic);
nicholas@2535 709 this.generate = function (option, parent) {
nickjillings@1370 710 this.option = option;
nickjillings@1370 711 this.parent = parent;
nickjillings@2158 712 if (this.select.childElementCount == 0) {
nickjillings@2158 713 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("type")[0].getAllElementsByTagName("xs:enumeration");
nicholas@2535 714 for (var i = 0; i < optionList.length; i++) {
nickjillings@2158 715 var selectOption = document.createElement("option");
nickjillings@2158 716 selectOption.value = optionList[i].getAttribute("value");
nickjillings@2158 717 selectOption.textContent = selectOption.value;
nickjillings@2158 718 this.select.appendChild(selectOption);
nickjillings@2158 719 }
nickjillings@1370 720 }
nicholas@2535 721 if (this.option.type != undefined) {
nickjillings@2158 722 this.select.value = this.option.type
nickjillings@1370 723 } else {
nickjillings@2158 724 this.select.value = "statement";
nickjillings@1370 725 this.option.type = "statement";
nickjillings@1370 726 }
nicholas@2535 727
nickjillings@1370 728 this.dynamic.innerHTML = null;
nickjillings@1370 729 var statement = document.createElement("div");
nickjillings@1370 730 var statementText = document.createElement("span");
nickjillings@2159 731 var statementEntry = document.createElement("input");
nickjillings@1370 732 statement.appendChild(statementText);
nickjillings@1370 733 statement.appendChild(statementEntry);
nickjillings@2159 734 statement.className = "survey-entry-attribute";
nickjillings@1370 735 statementText.textContent = "Statement/Question";
nickjillings@2159 736 statementEntry.style.width = "500px";
nicholas@2535 737 statementEntry.addEventListener("change", this, false);
nicholas@2535 738 statementEntry.setAttribute("name", "statement");
nickjillings@1370 739 statementEntry.value = this.option.statement;
nickjillings@1370 740 this.dynamic.appendChild(statement);
nicholas@2535 741
nickjillings@1375 742 var id = document.createElement("div");
nickjillings@1375 743 var idText = document.createElement("span");
nickjillings@1375 744 var idEntry = document.createElement("input");
nickjillings@1375 745 id.appendChild(idText);
nickjillings@1375 746 id.appendChild(idEntry);
nickjillings@2159 747 id.className = "survey-entry-attribute";
nickjillings@1375 748 idText.textContent = "ID: ";
nicholas@2535 749 idEntry.addEventListener("change", this, false);
nicholas@2535 750 idEntry.setAttribute("name", "id");
nickjillings@1375 751 idEntry.value = this.option.id;
nicholas@2535 752
nickjillings@2158 753 this.dynamic.appendChild(id);
nicholas@2535 754
nicholas@2535 755 switch (this.option.type) {
nickjillings@1370 756 case "statement":
nickjillings@1370 757 break;
nickjillings@1370 758 case "question":
nickjillings@1370 759 var boxsizeSelect = document.createElement("select");
nickjillings@1370 760 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration");
nicholas@2535 761 for (var i = 0; i < optionList.length; i++) {
nickjillings@1370 762 var selectOption = document.createElement("option");
nickjillings@1370 763 selectOption.value = optionList[i].getAttribute("value");
nickjillings@1370 764 selectOption.textContent = selectOption.value;
nickjillings@1370 765 boxsizeSelect.appendChild(selectOption);
nickjillings@1370 766 }
nicholas@2535 767 if (this.option.boxsize != undefined) {
nickjillings@1370 768 boxsizeSelect.value = this.option.boxsize;
nickjillings@1370 769 } else {
nickjillings@1370 770 boxsizeSelect.value = "normal";
nickjillings@1370 771 this.option.boxsize = "normal";
nickjillings@1370 772 }
nicholas@2535 773 boxsizeSelect.setAttribute("name", "boxsize");
nicholas@2535 774 boxsizeSelect.addEventListener("change", this, false);
nickjillings@1370 775 var boxsize = document.createElement("div");
nickjillings@1370 776 var boxsizeText = document.createElement("span");
nickjillings@1370 777 boxsizeText.textContent = "Entry Size: ";
nickjillings@1370 778 boxsize.appendChild(boxsizeText);
nickjillings@1370 779 boxsize.appendChild(boxsizeSelect);
nickjillings@2159 780 boxsize.className = "survey-entry-attribute";
nickjillings@1370 781 this.dynamic.appendChild(boxsize);
nicholas@2535 782
nickjillings@1370 783 var mandatory = document.createElement("div");
nickjillings@1370 784 var mandatoryInput = document.createElement("input");
nickjillings@1370 785 var mandatoryText = document.createElement("span");
nickjillings@1370 786 mandatoryText.textContent = "Mandatory: ";
nickjillings@1370 787 mandatory.appendChild(mandatoryText);
nickjillings@1370 788 mandatory.appendChild(mandatoryInput);
nickjillings@2159 789 mandatory.className = "survey-entry-attribute";
nickjillings@1370 790 mandatoryInput.type = "checkbox";
nicholas@2535 791 if (this.option.mandatory) {
nicholas@2535 792 mandatoryInput.checked = true;
nicholas@2535 793 } else {
nicholas@2535 794 mandatoryInput.checked = false;
nicholas@2535 795 }
nicholas@2535 796 mandatoryInput.setAttribute("name", "mandatory");
nicholas@2535 797 mandatoryInput.addEventListener("change", this, false);
nickjillings@1375 798 this.dynamic.appendChild(mandatory);
nickjillings@1375 799 break;
nickjillings@1375 800 case "number":
nickjillings@1375 801 this.dynamic.appendChild(id);
nicholas@2535 802
nickjillings@1375 803 var mandatory = document.createElement("div");
nickjillings@1375 804 var mandatoryInput = document.createElement("input");
nickjillings@1375 805 var mandatoryText = document.createElement("span");
nickjillings@1375 806 mandatoryText.textContent = "Mandatory: ";
nickjillings@1370 807 mandatory.appendChild(mandatoryText);
nickjillings@1370 808 mandatory.appendChild(mandatoryInput);
nickjillings@2159 809 mandatory.className = "survey-entry-attribute";
nickjillings@1375 810 mandatoryInput.type = "checkbox";
nicholas@2535 811 if (this.option.mandatory) {
nicholas@2535 812 mandatoryInput.checked = true;
nicholas@2535 813 } else {
nicholas@2535 814 mandatoryInput.checked = false;
nicholas@2535 815 }
nicholas@2535 816 mandatoryInput.setAttribute("name", "mandatory");
nicholas@2535 817 mandatoryInput.addEventListener("change", this, false);
nickjillings@1370 818 this.dynamic.appendChild(mandatory);
nicholas@2535 819
nickjillings@1375 820 var minimum = document.createElement("div");
nickjillings@1375 821 var minimumEntry = document.createElement("input");
nickjillings@1375 822 var minimumText = document.createElement("span");
nickjillings@1375 823 minimumText.textContent = "Minimum: ";
nickjillings@1375 824 minimum.appendChild(minimumText);
nickjillings@1375 825 minimum.appendChild(minimumEntry);
nickjillings@2159 826 minimum.className = "survey-entry-attribute";
nickjillings@1375 827 minimumEntry.type = "number";
nicholas@2535 828 minimumEntry.setAttribute("name", "min");
nicholas@2535 829 minimumEntry.addEventListener("change", this, false);
nickjillings@1375 830 minimumEntry.value = this.option.min;
nickjillings@1375 831 this.dynamic.appendChild(minimum);
nicholas@2535 832
nickjillings@1375 833 var maximum = document.createElement("div");
nickjillings@1375 834 var maximumEntry = document.createElement("input");
nickjillings@1375 835 var maximumText = document.createElement("span");
nickjillings@1375 836 maximumText.textContent = "Maximum: ";
nickjillings@1375 837 maximum.appendChild(maximumText);
nickjillings@1375 838 maximum.appendChild(maximumEntry);
nickjillings@2159 839 maximum.className = "survey-entry-attribute";
nickjillings@1375 840 maximumEntry.type = "number";
nicholas@2535 841 maximumEntry.setAttribute("name", "max");
nicholas@2535 842 maximumEntry.addEventListener("change", this, false);
nickjillings@1375 843 maximumEntry.value = this.option.max;
nickjillings@1375 844 this.dynamic.appendChild(maximum);
nickjillings@1370 845 break;
nickjillings@1375 846 case "checkbox":
nickjillings@1375 847 case "radio":
nickjillings@1375 848 this.dynamic.appendChild(id);
nickjillings@1375 849 var optionHolder = document.createElement("div");
nickjillings@1375 850 optionHolder.className = 'node';
nickjillings@1375 851 optionHolder.id = 'popup-option-holder';
nicholas@2535 852 var optionObject = function (parent, option) {
nickjillings@1375 853 this.rootDOM = document.createElement("div");
nickjillings@1375 854 this.rootDOM.className = "popup-option-entry";
nickjillings@1375 855 this.inputName = document.createElement("input");
nicholas@2535 856 this.inputName.setAttribute("name", "name");
nickjillings@1375 857 this.inputLabel = document.createElement("input");
nicholas@2535 858 this.inputLabel.setAttribute("name", "text");
nickjillings@1375 859 this.specification = option;
nickjillings@1375 860 this.parent = parent;
nicholas@2535 861 this.handleEvent = function () {
nickjillings@1375 862 var target = event.currentTarget.getAttribute("name");
nicholas@2535 863 eval("this.specification." + target + " = event.currentTarget.value");
nickjillings@1375 864 };
nicholas@2535 865
nickjillings@1375 866 var nameText = document.createElement("span");
nickjillings@1375 867 nameText.textContent = "Name: ";
nickjillings@1375 868 var labelText = document.createElement("span");
nickjillings@1375 869 labelText.textContent = "Label: ";
nickjillings@1375 870 this.rootDOM.appendChild(nameText);
nickjillings@1375 871 this.rootDOM.appendChild(this.inputName);
nickjillings@1375 872 this.rootDOM.appendChild(labelText);
nickjillings@1375 873 this.rootDOM.appendChild(this.inputLabel);
nicholas@2535 874 this.inputName.addEventListener("change", this, false);
nicholas@2535 875 this.inputLabel.addEventListener("change", this, false);
nickjillings@1375 876 this.inputName.value = this.specification.name;
nickjillings@1375 877 this.inputLabel.value = this.specification.text;
nickjillings@2180 878 this.inputLabel.style.width = "350px";
nicholas@2535 879
nickjillings@1375 880 this.deleteEntry = {
nickjillings@1375 881 root: document.createElement("button"),
nickjillings@1375 882 parent: this,
nicholas@2535 883 handleEvent: function () {
nickjillings@1375 884 document.getElementById("popup-option-holder").removeChild(this.parent.rootDOM);
nicholas@2535 885 var index = this.parent.parent.option.options.findIndex(function (element, index, array) {
nickjillings@1375 886 if (element == this.parent.specification)
nickjillings@1375 887 return true;
nickjillings@1375 888 else
nickjillings@1375 889 return false;
nicholas@2535 890 }, this);
nickjillings@1375 891 var optionList = this.parent.parent.option.options;
nicholas@2535 892 if (index == optionList.length - 1) {
nicholas@2535 893 optionList = optionList.slice(0, index);
nickjillings@1375 894 } else {
nicholas@2535 895 optionList = optionList.slice(0, index).concat(optionList.slice(index + 1));
nickjillings@1375 896 }
nickjillings@1375 897 this.parent.parent.option.options = optionList;
nickjillings@1375 898 }
nickjillings@1375 899 };
nickjillings@1375 900 this.deleteEntry.root.textContent = "Delete Option";
nicholas@2535 901 this.deleteEntry.root.addEventListener("click", this.deleteEntry, false);
nickjillings@1375 902 this.rootDOM.appendChild(this.deleteEntry.root);
nickjillings@1375 903 }
nickjillings@2158 904 this.addEntry = {
nickjillings@2158 905 parent: this,
nickjillings@2158 906 root: document.createElement("button"),
nicholas@2535 907 handleEvent: function () {
nicholas@2535 908 var node = {
nicholas@2535 909 name: "name",
nicholas@2535 910 text: "text"
nicholas@2535 911 };
nickjillings@2158 912 var optionsList = this.parent.option.options;
nickjillings@2158 913 optionsList.push(node);
nicholas@2535 914 var obj = new optionObject(this.parent, optionsList[optionsList.length - 1]);
nickjillings@2158 915 this.parent.optionLists.push(obj);
nickjillings@2158 916 document.getElementById("popup-option-holder").appendChild(obj.rootDOM);
nickjillings@2158 917 }
nickjillings@2158 918 }
nickjillings@2158 919 this.addEntry.root.textContent = "Add Option";
nicholas@2535 920 this.addEntry.root.addEventListener("click", this.addEntry);
nickjillings@2158 921 this.dynamic.appendChild(this.addEntry.root);
nicholas@2535 922 for (var i = 0; i < this.option.options.length; i++) {
nicholas@2535 923 var obj = new optionObject(this, this.option.options[i]);
nickjillings@1375 924 this.optionLists.push(obj);
nickjillings@1375 925 optionHolder.appendChild(obj.rootDOM);
nickjillings@1375 926 }
nickjillings@1375 927 this.dynamic.appendChild(optionHolder);
nickjillings@1370 928 }
nickjillings@1370 929 }
nicholas@2536 930 this.handleEvent = function (event) {
nickjillings@1370 931 var name = event.currentTarget.getAttribute("name");
nickjillings@2159 932 var nodeName = event.currentTarget.nodeName;
nickjillings@2159 933 if (name == "type" && nodeName == "SELECT") {
nickjillings@2159 934 // If type has changed, we may need to rebuild the entire state node
nicholas@2535 935 if (event.currentTarget.value != this.option.name) {
nickjillings@2159 936 this.option.type = event.currentTarget.value;
nicholas@2535 937 this.generate(this.option, this.parent);
nickjillings@2159 938 }
nickjillings@2159 939 return;
nickjillings@2159 940 }
nicholas@2535 941 switch (event.currentTarget.getAttribute("type")) {
nickjillings@2159 942 case "checkbox":
nicholas@2535 943 eval("this.option." + name + " = event.currentTarget.checked");
nickjillings@1370 944 break;
nickjillings@2159 945 default:
nicholas@2535 946 eval("this.option." + name + " = event.currentTarget.value");
nickjillings@1370 947 break;
nickjillings@1370 948 }
nickjillings@1370 949 }
nicholas@2535 950 this.continue = function () {
nicholas@2535 951 if (this.parent.type == "surveyNode") {
nicholas@2535 952 var newNode = new this.parent.surveyEntryNode(this.parent, this.option);
nickjillings@1375 953 this.parent.children.push(newNode);
nickjillings@1375 954 this.parent.childrenDOM.appendChild(newNode.rootDOM);
nickjillings@1375 955 } else if (this.parent.type == "surveyEntryNode") {
nickjillings@1375 956 this.parent.build();
nickjillings@1375 957 }
nickjillings@1370 958 popupObject.hide();
nickjillings@1370 959 }
nickjillings@1370 960 }
nicholas@2535 961 this.state[6] = new function () {
nickjillings@1385 962 this.title = "Edit Scale Markers";
nickjillings@1385 963 this.content = document.createElement("div");
nickjillings@1385 964 this.content.id = "state-6";
nickjillings@1385 965 var spnH = document.createElement('div');
nickjillings@1385 966 var span = document.createElement("span");
nickjillings@1385 967 span.textContent = "You can edit your scale markers here for the selected interface.";
nickjillings@1385 968 spnH.appendChild(span);
nickjillings@1385 969 this.scaleRoot;
nickjillings@1385 970 this.parent;
nicholas@2535 971 this.markerNodes = [];
nickjillings@1385 972 this.preset = {
nickjillings@1385 973 input: document.createElement("select"),
nickjillings@1385 974 parent: this,
nicholas@2535 975 handleEvent: function (event) {
nickjillings@1385 976 this.parent.scaleRoot.scales = [];
nickjillings@1385 977 var protoScale = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getAllElementsByName(event.currentTarget.value)[0];
nicholas@2390 978 var protoMarkers = protoScale.getElementsByTagName("scale");
nicholas@2535 979 for (var i = 0; i < protoMarkers.length; i++) {
nickjillings@1385 980 var marker = {
nickjillings@1385 981 position: protoMarkers[i].getAttribute("position"),
nickjillings@1385 982 text: protoMarkers[i].textContent
nickjillings@1385 983 }
nickjillings@1385 984 this.parent.scaleRoot.scales.push(marker);
nickjillings@1385 985 }
nickjillings@1385 986 this.parent.buildMarkerList();
nickjillings@1385 987 }
nickjillings@1385 988 }
nicholas@2535 989 this.preset.input.addEventListener("change", this.preset);
nickjillings@1385 990 this.content.appendChild(this.preset.input);
nickjillings@1385 991 var optionHolder = document.createElement("div");
nickjillings@1385 992 optionHolder.className = 'node';
nickjillings@1385 993 optionHolder.id = 'popup-option-holder';
nickjillings@1385 994 this.content.appendChild(optionHolder);
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@2243 1597 this.titleNode.label.textContent = "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@2243 1605 }
nicholas@2535 1606
nickjillings@1370 1607 // Put in the check / show options as individual children
nicholas@2535 1608 var checks = this.parent.createGeneralNodeDOM("Checks", "setup-interface-checks", this);
nickjillings@1370 1609
nickjillings@1370 1610 var interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1611 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1612 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1613 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
nickjillings@1370 1614 testXML = testXML.getAllElementsByTagName("checks");
nicholas@2390 1615 var interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1616 while (interfaceXMLChild) {
nicholas@2535 1617 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "check");
nicholas@2535 1618 for (var option of this.specification.options) {
nicholas@2535 1619 if (option.name == obj.name) {
nickjillings@1370 1620 obj.input.checked = true;
nickjillings@1370 1621 break;
nickjillings@1370 1622 }
nickjillings@1370 1623 }
nickjillings@1370 1624 if (parent.id != "setup") {
nicholas@2535 1625 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1626 if (node != undefined) {
nickjillings@1381 1627 if (node.input.checked) {
nickjillings@1381 1628 obj.input.checked = false;
nickjillings@1381 1629 obj.input.disabled = true;
nickjillings@1381 1630 }
nickjillings@1370 1631 }
nickjillings@1370 1632 }
nickjillings@1370 1633 var text = document.createElement('span');
nicholas@2390 1634 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1635 obj.root.appendChild(text);
nickjillings@1370 1636 checks.attributeDOM.appendChild(obj.root);
nickjillings@1370 1637 checks.attributes.push(obj);
nicholas@2390 1638 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1639 }
nickjillings@1370 1640 this.children.push(checks);
nickjillings@1370 1641 this.childrenDOM.appendChild(checks.rootDOM);
nickjillings@1370 1642
nicholas@2535 1643 var show = this.parent.createGeneralNodeDOM("Show", "setup-interface-show", this);
nickjillings@1370 1644 interfaceName = popupStateNodes.state[1].select.value;
nickjillings@1370 1645 checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1646 testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
nickjillings@1370 1647 interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
nickjillings@1370 1648 testXML = testXML.getAllElementsByTagName("show");
nicholas@2390 1649 interfaceXMLChild = interfaceXML.firstElementChild;
nicholas@2535 1650 while (interfaceXMLChild) {
nicholas@2535 1651 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "show");
nicholas@2535 1652 for (var option of this.specification.options) {
nicholas@2535 1653 if (option.name == obj.name) {
nickjillings@1370 1654 obj.input.checked = true;
nickjillings@1370 1655 break;
nickjillings@1370 1656 }
nickjillings@1370 1657 }
nickjillings@1370 1658 if (parent.id != "setup") {
nicholas@2535 1659 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
nickjillings@1381 1660 if (node != undefined) {
nickjillings@1381 1661 if (node.input.checked) {
nickjillings@1381 1662 obj.input.checked = false;
nickjillings@1381 1663 obj.input.disabled = true;
nickjillings@1381 1664 }
nickjillings@1370 1665 }
nickjillings@1370 1666 }
nickjillings@1370 1667 var text = document.createElement('span');
nicholas@2390 1668 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
nickjillings@1370 1669 obj.root.appendChild(text);
nickjillings@1370 1670 show.attributeDOM.appendChild(obj.root);
nickjillings@1370 1671 show.attributes.push(obj);
nicholas@2390 1672 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
nickjillings@1370 1673 }
nickjillings@1370 1674 this.children.push(show);
nickjillings@1370 1675 this.childrenDOM.appendChild(show.rootDOM);
nicholas@2535 1676
nicholas@2535 1677 if (parent.id == "setup") {} else {
nicholas@2535 1678 var nameAttr = this.parent.convertAttributeToDOM(this, specification.schema.getAllElementsByName("name")[0]);
nickjillings@1370 1679 this.attributeDOM.appendChild(nameAttr.holder);
nickjillings@1370 1680 this.attributes.push(nameAttr);
nicholas@2535 1681 var scales = new this.scalesNode(this, this.specification);
nickjillings@1385 1682 this.children.push(scales);
nickjillings@1385 1683 this.childrenDOM.appendChild(scales.rootDOM);
nickjillings@1370 1684 }
nicholas@2535 1685 if (parent != undefined) {
nickjillings@1370 1686 parent.appendChild(this.rootDOM);
nickjillings@1370 1687 }
nickjillings@1370 1688 }
nicholas@2535 1689
nicholas@2535 1690 this.scalesNode = function (parent, rootObject) {
nickjillings@1385 1691 this.type = "scalesNode";
nickjillings@1385 1692 this.rootDOM = document.createElement("div");
nickjillings@1385 1693 this.titleDOM = document.createElement("span");
nickjillings@1385 1694 this.attributeDOM = document.createElement("div");
nickjillings@1385 1695 this.attributes = [];
nickjillings@1385 1696 this.childrenDOM = document.createElement("div");
nickjillings@1385 1697 this.children = [];
nickjillings@1385 1698 this.buttonDOM = document.createElement("div");
nickjillings@1385 1699 this.parent = parent;
nickjillings@1385 1700 this.specification = rootObject;
nickjillings@1385 1701 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1385 1702 this.rootDOM.className = "node";
nickjillings@1385 1703
nickjillings@1385 1704 var titleDiv = document.createElement('div');
nickjillings@1385 1705 titleDiv.className = "node-title";
nickjillings@1385 1706 this.titleDOM.className = "node-title";
nickjillings@1385 1707 this.titleDOM.textContent = "Interface Scales";
nickjillings@1385 1708 titleDiv.appendChild(this.titleDOM);
nickjillings@1385 1709
nickjillings@1385 1710 this.attributeDOM.className = "node-attributes";
nickjillings@1385 1711 this.childrenDOM.className = "node-children";
nickjillings@1385 1712 this.buttonDOM.className = "node-buttons";
nickjillings@1385 1713
nickjillings@1385 1714 this.rootDOM.appendChild(titleDiv);
nickjillings@1385 1715 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1385 1716 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1385 1717 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1718
nickjillings@1385 1719 this.editButton = {
nickjillings@1385 1720 button: document.createElement("button"),
nickjillings@1385 1721 parent: this,
nicholas@2535 1722 handleEvent: function (event) {
nickjillings@1385 1723 popupObject.show();
nickjillings@1385 1724 popupObject.postNode(popupStateNodes.state[6]);
nicholas@2535 1725 popupStateNodes.state[6].generate(this.parent.specification, this.parent);
nickjillings@1385 1726 }
nickjillings@1385 1727 };
nickjillings@1385 1728 this.editButton.button.textContent = "Edit Scales/Markers";
nicholas@2535 1729 this.editButton.button.addEventListener("click", this.editButton, false);
nickjillings@1385 1730 this.buttonDOM.appendChild(this.editButton.button);
nickjillings@1385 1731 }
nickjillings@1370 1732 }
nicholas@2535 1733
nicholas@2535 1734 this.surveyNode = function (parent, rootObject, location) {
nickjillings@1375 1735 this.type = "surveyNode";
nickjillings@1370 1736 this.rootDOM = document.createElement("div");
nickjillings@1370 1737 this.titleDOM = document.createElement("span");
nickjillings@1370 1738 this.attributeDOM = document.createElement("div");
nickjillings@1370 1739 this.attributes = [];
nickjillings@1370 1740 this.childrenDOM = document.createElement("div");
nickjillings@1370 1741 this.children = [];
nickjillings@1370 1742 this.buttonDOM = document.createElement("div");
nickjillings@1370 1743 this.parent = parent;
nickjillings@1370 1744 this.specification = rootObject;
nickjillings@1370 1745 this.schema = specification.schema.getAllElementsByName("survey")[1];
nickjillings@1370 1746 this.rootDOM.className = "node";
nickjillings@1370 1747
nickjillings@1370 1748 var titleDiv = document.createElement('div');
nickjillings@1370 1749 titleDiv.className = "node-title";
nickjillings@1370 1750 this.titleDOM.className = "node-title";
nickjillings@1370 1751 this.titleDOM.textContent = "Survey";
nickjillings@1370 1752 titleDiv.appendChild(this.titleDOM);
nicholas@2535 1753
nickjillings@1370 1754 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1755 var locationAttr = document.createElement("span");
nickjillings@1370 1756 this.attributeDOM.appendChild(locationAttr);
nickjillings@1370 1757 if (location == "Pre" || location == "pre") {
nickjillings@1370 1758 locationAttr.textContent = "Location: Before";
nickjillings@1370 1759 } else {
nickjillings@1370 1760 locationAttr.textContent = "Location: After";
nickjillings@1370 1761 }
nickjillings@1370 1762 this.childrenDOM.className = "node-children";
nickjillings@1370 1763 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1764
nickjillings@1370 1765 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1766 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1767 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1768 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1769
nicholas@2535 1770 this.surveyEntryNode = function (parent, rootObject) {
nickjillings@1375 1771 this.type = "surveyEntryNode";
nickjillings@1370 1772 this.rootDOM = document.createElement("div");
nickjillings@1370 1773 this.titleDOM = document.createElement("span");
nickjillings@1370 1774 this.attributeDOM = document.createElement("div");
nickjillings@1370 1775 this.attributes = [];
nickjillings@1370 1776 this.childrenDOM = document.createElement("div");
nickjillings@1370 1777 this.children = [];
nickjillings@1370 1778 this.buttonDOM = document.createElement("div");
nickjillings@1370 1779 this.parent = parent;
nickjillings@1370 1780 this.specification = rootObject;
nickjillings@1370 1781 this.schema = specification.schema.getAllElementsByName("surveyentry")[1];
nickjillings@1370 1782
nickjillings@1370 1783 this.rootDOM.className = "node";
nickjillings@1370 1784 this.rootDOM.style.minWidth = "50%";
nickjillings@1370 1785
nickjillings@1370 1786 var titleDiv = document.createElement('div');
nickjillings@1370 1787 titleDiv.className = "node-title";
nickjillings@1370 1788 this.titleDOM.className = "node-title";
nickjillings@1370 1789 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 1790
nickjillings@1370 1791 this.attributeDOM.className = "node-attributes";
nickjillings@1370 1792 this.childrenDOM.className = "node-children";
nickjillings@1370 1793 this.buttonDOM.className = "node-buttons";
nickjillings@1370 1794
nickjillings@1370 1795 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 1796 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 1797 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 1798 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 1799
nicholas@2535 1800 this.build = function () {
nickjillings@1375 1801 this.attributeDOM.innerHTML = null;
nickjillings@1375 1802 this.childrenDOM.innerHTML = null;
nickjillings@1375 1803 var statementRoot = document.createElement("div");
nickjillings@1375 1804 var statement = document.createElement("span");
nicholas@2535 1805 statement.textContent = "Statement / Question: " + this.specification.statement;
nickjillings@1375 1806 statementRoot.appendChild(statement);
nickjillings@1375 1807 this.children.push(statementRoot);
nickjillings@1375 1808 this.childrenDOM.appendChild(statementRoot);
nicholas@2535 1809 switch (this.specification.type) {
nickjillings@1375 1810 case "statement":
nickjillings@1375 1811 this.titleDOM.textContent = "Statement";
nickjillings@1375 1812 break;
nickjillings@1375 1813 case "question":
nickjillings@1375 1814 this.titleDOM.textContent = "Question";
nicholas@2535 1815 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1816 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1817 var boxsize = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("boxsize")[0]);
nickjillings@1375 1818 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1819 this.attributes.push(id);
nickjillings@1375 1820 this.attributeDOM.appendChild(mandatory.holder);
nickjillings@1375 1821 this.attributes.push(mandatory);
nickjillings@1375 1822 this.attributeDOM.appendChild(boxsize.holder);
nickjillings@1375 1823 this.attributes.push(boxsize);
nickjillings@1375 1824 break;
nickjillings@1375 1825 case "number":
nickjillings@1375 1826 this.titleDOM.textContent = "Number";
nicholas@2535 1827 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nicholas@2535 1828 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
nicholas@2535 1829 var min = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("min")[0]);
nicholas@2535 1830 var max = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("max")[0]);
nickjillings@1375 1831 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1832 this.attributes.push(id);
nickjillings@1375 1833 this.attributeDOM.appendChild(min.holder);
nickjillings@1375 1834 this.attributes.push(min);
nickjillings@1375 1835 this.attributeDOM.appendChild(max.holder);
nickjillings@1375 1836 this.attributes.push(max);
nickjillings@1375 1837 break;
nickjillings@1375 1838 case "checkbox":
nickjillings@1375 1839 this.titleDOM.textContent = "Checkbox";
nicholas@2535 1840 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1841 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1842 this.attributes.push(id);
nickjillings@1375 1843 break;
nickjillings@1375 1844 case "radio":
nickjillings@1375 1845 this.titleDOM.textContent = "Radio";
nicholas@2535 1846 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
nickjillings@1375 1847 this.attributeDOM.appendChild(id.holder);
nickjillings@1375 1848 this.attributes.push(id);
nickjillings@1375 1849 break;
nickjillings@1375 1850 }
nickjillings@1370 1851 }
nickjillings@1375 1852 this.build();
nicholas@2535 1853
nickjillings@1370 1854 this.editNode = {
nickjillings@1370 1855 root: document.createElement("button"),
nickjillings@1370 1856 parent: this,
nicholas@2535 1857 handleEvent: function () {
nickjillings@1370 1858 popupObject.show();
nicholas@2535 1859 popupStateNodes.state[5].generate(this.parent.specification, this.parent);
nickjillings@1370 1860 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1861 }
nickjillings@1370 1862 }
nickjillings@1370 1863 this.editNode.root.textContent = "Edit Entry";
nicholas@2535 1864 this.editNode.root.addEventListener("click", this.editNode, false);
nickjillings@1370 1865 this.buttonDOM.appendChild(this.editNode.root);
nicholas@2535 1866
nickjillings@1370 1867 this.deleteNode = {
nickjillings@1370 1868 root: document.createElement("button"),
nickjillings@1370 1869 parent: this,
nicholas@2535 1870 handleEvent: function () {
nickjillings@1370 1871 var optionList = this.parent.parent.specification.options;
nickjillings@1370 1872 var childList = this.parent.parent.children;
nicholas@2535 1873 for (var i = 0; i < this.parent.parent.specification.options.length; i++) {
nickjillings@1370 1874 var option = this.parent.parent.specification.options[i];
nicholas@2535 1875 if (option == this.parent.specification) {
nickjillings@1370 1876 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nicholas@2535 1877 if (i == this.parent.parent.specification.options.length - 1) {
nicholas@2535 1878 optionList = optionList.slice(0, i);
nicholas@2535 1879 childList = childList.slice(0, i);
nicholas@2535 1880 } else {
nicholas@2535 1881 optionList = optionList.slice(0, i).concat(optionList.slice(i + 1));
nicholas@2535 1882 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 1883 }
nickjillings@1370 1884 this.parent.parent.specification.options = optionList;
nickjillings@1370 1885 this.parent.parent.children = childList;
nickjillings@1370 1886 }
nickjillings@1370 1887 }
nickjillings@1370 1888 }
nickjillings@1370 1889 }
nickjillings@1370 1890 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 1891 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 1892 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 1893
nicholas@2535 1894 this.moveToPosition = function (new_index) {
nicholas@2535 1895 new_index = Math.min(new_index, this.parent.children.length);
nicholas@2535 1896 var curr_index = this.parent.children.findIndex(function (elem) {
nicholas@2535 1897 if (elem == this) {
nicholas@2535 1898 return true;
nicholas@2535 1899 } else {
nicholas@2535 1900 return false;
nicholas@2535 1901 }
nicholas@2535 1902 }, this);
n@2416 1903 // Split at the current location to remove the node and shift all the children up
nicholas@2535 1904 var tail = this.parent.children.splice(curr_index + 1);
n@2416 1905 this.parent.children.pop();
n@2416 1906 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1907
n@2416 1908 //Split at the new location and insert the node
n@2416 1909 tail = this.parent.children.splice(new_index);
n@2416 1910 this.parent.children.push(this);
n@2416 1911 this.parent.children = this.parent.children.concat(tail);
nicholas@2535 1912
n@2416 1913 // Re-build the specification
n@2416 1914 this.parent.specification.options = [];
n@2416 1915 this.parent.childrenDOM.innerHTML = "";
n@2416 1916 for (var obj of this.parent.children) {
n@2416 1917 this.parent.specification.options.push(obj.specification);
n@2416 1918 this.parent.childrenDOM.appendChild(obj.rootDOM);
n@2416 1919 }
nicholas@2535 1920 this.parent.children.forEach(function (obj, index) {
n@2420 1921 obj.moveButtons.disable(index);
n@2420 1922 });
n@2414 1923 }
nicholas@2535 1924
n@2420 1925 this.moveButtons = {
n@2420 1926 root_up: document.createElement("button"),
n@2420 1927 root_down: document.createElement("button"),
n@2420 1928 parent: this,
nicholas@2535 1929 handleEvent: function (event) {
n@2420 1930 var index = this.parent.parent.children.indexOf(this.parent);
n@2420 1931 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 1932 index = Math.max(index - 1, 0);
n@2420 1933 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 1934 index = Math.min(index + 1, this.parent.parent.children.length - 1);
n@2420 1935 }
n@2420 1936 this.parent.moveToPosition(index);
n@2420 1937 this.disable(index);
n@2420 1938 },
nicholas@2535 1939 disable: function (index) {
n@2420 1940 if (index == 0) {
n@2420 1941 this.root_up.disabled = true;
n@2420 1942 } else {
n@2420 1943 this.root_up.disabled = false;
n@2420 1944 }
nicholas@2535 1945 if (index == this.parent.parent.children.length - 1) {
n@2420 1946 this.root_down.disabled = true;
n@2420 1947 } else {
n@2420 1948 this.root_down.disabled = false;
n@2420 1949 }
n@2420 1950 }
n@2420 1951 }
nicholas@2535 1952 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 1953 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 1954 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 1955 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2420 1956 this.moveButtons.root_up.textContent = "Move Up";
n@2420 1957 this.moveButtons.root_down.textContent = "Move Down";
n@2420 1958 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2420 1959 this.buttonDOM.appendChild(this.moveButtons.root_down);
nickjillings@1370 1960 }
nickjillings@1370 1961 this.addNode = {
nickjillings@1370 1962 root: document.createElement("button"),
nickjillings@1370 1963 parent: this,
nicholas@2535 1964 handleEvent: function () {
nickjillings@2194 1965 var newNode = new this.parent.specification.OptionNode(this.parent.specification);
nickjillings@1370 1966 this.parent.specification.options.push(newNode);
nickjillings@1370 1967 popupObject.show();
nicholas@2535 1968 popupStateNodes.state[5].generate(newNode, this.parent);
nickjillings@1370 1969 popupObject.postNode(popupStateNodes.state[5]);
nickjillings@1370 1970 }
nickjillings@1370 1971 }
nickjillings@1370 1972 this.addNode.root.textContent = "Add Survey Entry";
nicholas@2535 1973 this.addNode.root.addEventListener("click", this.addNode, false);
nickjillings@1370 1974 this.buttonDOM.appendChild(this.addNode.root);
nicholas@2535 1975
nicholas@2535 1976 for (var option of this.specification.options) {
nicholas@2535 1977 var newNode = new this.surveyEntryNode(this, option);
nickjillings@1370 1978 this.children.push(newNode);
nickjillings@1370 1979 this.childrenDOM.appendChild(newNode.rootDOM);
nickjillings@1370 1980 }
nicholas@2535 1981
nicholas@2535 1982 this.children.forEach(function (obj, index) {
n@2420 1983 obj.moveButtons.disable(index);
n@2420 1984 });
nickjillings@1370 1985 }
nicholas@2535 1986
nicholas@2535 1987 this.pageNode = function (parent, rootObject) {
nickjillings@1375 1988 this.type = "pageNode";
nickjillings@1370 1989 this.rootDOM = document.createElement("div");
nickjillings@1370 1990 this.titleDOM = document.createElement("span");
nickjillings@1370 1991 this.attributeDOM = document.createElement("div");
nickjillings@1370 1992 this.attributes = [];
nickjillings@1370 1993 this.childrenDOM = document.createElement("div");
nickjillings@1370 1994 this.children = [];
nickjillings@1370 1995 this.buttonDOM = document.createElement("div");
nickjillings@1370 1996 this.parent = parent;
nickjillings@1370 1997 this.specification = rootObject;
nickjillings@1370 1998 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1370 1999 this.rootDOM.className = "node";
nickjillings@1370 2000
nickjillings@1370 2001 var titleDiv = document.createElement('div');
nickjillings@1370 2002 titleDiv.className = "node-title";
nickjillings@1370 2003 this.titleDOM.className = "node-title";
nickjillings@1370 2004 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2005 titleDiv.appendChild(this.titleDOM);
nicholas@2535 2006
nickjillings@1370 2007 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2008 this.childrenDOM.className = "node-children";
nickjillings@1370 2009 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2010
nickjillings@1370 2011 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2012 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2013 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2014 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2015
nickjillings@1370 2016 // Do the comment prefix node
nicholas@2535 2017 var cpn = this.parent.createGeneralNodeDOM("Comment Prefix", "" + this.specification.id + "-commentprefix", this.parent);
nickjillings@1370 2018 cpn.rootDOM.removeChild(cpn.attributeDOM);
nickjillings@1370 2019 var obj = {
nickjillings@1370 2020 root: document.createElement("div"),
nickjillings@1370 2021 input: document.createElement("input"),
nickjillings@1370 2022 parent: this,
nicholas@2535 2023 handleEvent: function () {
nickjillings@1370 2024 this.parent.specification.commentBoxPrefix = event.currentTarget.value;
nickjillings@1370 2025 }
nickjillings@1370 2026 }
nickjillings@1370 2027 cpn.children.push(obj);
nickjillings@1370 2028 cpn.childrenDOM.appendChild(obj.root);
nickjillings@1370 2029 obj.root.appendChild(obj.input);
nicholas@2535 2030 obj.input.addEventListener("change", obj, false);
nickjillings@1370 2031 obj.input.value = this.specification.commentBoxPrefix;
nickjillings@1370 2032 this.childrenDOM.appendChild(cpn.rootDOM);
nickjillings@1370 2033 this.children.push(cpn);
nicholas@2535 2034
nickjillings@1370 2035 // Now both before and after surveys
nicholas@2535 2036 if (this.specification.preTest == undefined) {
nickjillings@2194 2037 this.specification.preTest = new specification.surveyNode(specification);
nickjillings@1370 2038 this.specification.preTest.location = "pre";
nickjillings@1370 2039 }
nicholas@2535 2040 if (this.specification.postTest == undefined) {
nickjillings@2194 2041 this.specification.postTest = new specification.surveyNode(specification);
nickjillings@1370 2042 this.specification.postTest.location = "post";
nickjillings@1370 2043 }
nicholas@2535 2044 var surveyBefore = new this.parent.surveyNode(this, this.specification.preTest, "Pre");
nicholas@2535 2045 var surveyAfter = new this.parent.surveyNode(this, this.specification.postTest, "Post");
nickjillings@1370 2046 this.children.push(surveyBefore);
nickjillings@1370 2047 this.children.push(surveyAfter);
nickjillings@1370 2048 this.childrenDOM.appendChild(surveyBefore.rootDOM);
nickjillings@1370 2049 this.childrenDOM.appendChild(surveyAfter.rootDOM);
nicholas@2535 2050
nickjillings@1370 2051 // Build the attributes
nickjillings@1370 2052 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2053 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2054 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2055 var attrObject = this.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2056 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2057 this.attributes.push(attrObject);
nickjillings@1370 2058 }
nicholas@2535 2059
nickjillings@1370 2060 this.interfaces = [];
nicholas@2535 2061
nicholas@2535 2062 this.getAudioElements = function () {
n@2421 2063 var array = [];
nicholas@2535 2064 for (var i = 0; i < this.children.length; i++) {
n@2421 2065 if (this.children[i].type == "audioElementNode") {
n@2421 2066 array[array.length] = this.children[i];
n@2421 2067 }
n@2421 2068 }
n@2421 2069 return array;
n@2421 2070 }
nicholas@2535 2071
nicholas@2535 2072 this.redrawChildren = function () {
n@2421 2073 this.childrenDOM.innerHTML = "";
nicholas@2535 2074 for (var child of this.children) {
n@2421 2075 this.childrenDOM.appendChild(child.rootDOM);
n@2421 2076 }
n@2421 2077 }
nicholas@2535 2078
nicholas@2535 2079 this.audioElementNode = function (parent, rootObject) {
nickjillings@1375 2080 this.type = "audioElementNode";
nickjillings@1370 2081 this.rootDOM = document.createElement("div");
nickjillings@1370 2082 this.titleDOM = document.createElement("span");
nickjillings@1370 2083 this.attributeDOM = document.createElement("div");
nickjillings@1370 2084 this.attributes = [];
nickjillings@1370 2085 this.childrenDOM = document.createElement("div");
nickjillings@1370 2086 this.children = [];
nickjillings@1370 2087 this.buttonDOM = document.createElement("div");
nickjillings@1370 2088 this.parent = parent;
nickjillings@1370 2089 this.specification = rootObject;
nickjillings@1370 2090 this.schema = specification.schema.getAllElementsByName("audioelement")[0];
nickjillings@1370 2091 this.rootDOM.className = "node";
nickjillings@1370 2092
nickjillings@1370 2093 var titleDiv = document.createElement('div');
nickjillings@1370 2094 titleDiv.className = "node-title";
nickjillings@1370 2095 this.titleDOM.className = "node-title";
nickjillings@1370 2096 this.titleDOM.textContent = "Audio Element";
nickjillings@1370 2097 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2098
nickjillings@1370 2099 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2100 this.childrenDOM.className = "node-children";
nickjillings@1370 2101 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2102
nickjillings@1370 2103 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2104 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2105 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2106 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2107
nickjillings@1370 2108 // Build the attributes
nickjillings@1370 2109 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
nicholas@2535 2110 for (var i = 0; i < attributeList.length; i++) {
nickjillings@1370 2111 var attributeName = attributeList[i].getAttribute('name');
nicholas@2535 2112 var attrObject = this.parent.parent.convertAttributeToDOM(rootObject, attributeList[i]);
nickjillings@1370 2113 this.attributeDOM.appendChild(attrObject.holder);
nickjillings@1370 2114 this.attributes.push(attrObject);
nickjillings@1370 2115 }
nicholas@2535 2116
nickjillings@1370 2117 this.deleteNode = {
nickjillings@1370 2118 root: document.createElement("button"),
nickjillings@1370 2119 parent: this,
nicholas@2535 2120 handleEvent: function () {
nicholas@2535 2121 var i = this.parent.parent.specification.audioElements.findIndex(this.findNode, this);
nickjillings@1370 2122 if (i >= 0) {
nickjillings@1370 2123 var aeList = this.parent.parent.specification.audioElements;
nicholas@2535 2124 if (i < aeList.length - 1) {
nicholas@2535 2125 aeList = aeList.slice(0, i).concat(aeList.slice(i + 1));
nickjillings@1370 2126 } else {
nicholas@2535 2127 aeList = aeList.slice(0, i);
nickjillings@1370 2128 }
nickjillings@1370 2129 }
nicholas@2535 2130 i = this.parent.parent.children.findIndex(function (element, index, array) {
nickjillings@1370 2131 if (element == this.parent)
nickjillings@1370 2132 return true;
nickjillings@1370 2133 else
nickjillings@1370 2134 return false;
nicholas@2535 2135 }, this);
nickjillings@1370 2136 if (i >= 0) {
nickjillings@1370 2137 var childList = this.parent.children;
nicholas@2535 2138 if (i < aeList.length - 1) {
nicholas@2535 2139 childList = childList.slice(0, i).concat(childList.slice(i + 1));
nickjillings@1370 2140 } else {
nicholas@2535 2141 childList = childList.slice(0, i);
nickjillings@1370 2142 }
nickjillings@1370 2143 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
nickjillings@1370 2144 }
nickjillings@1370 2145 },
nicholas@2535 2146 findNode: function (element, index, array) {
nickjillings@1370 2147 if (element == this.parent.specification)
nickjillings@1370 2148 return true;
nickjillings@1370 2149 else
nickjillings@1370 2150 return false;
nickjillings@1370 2151 }
nickjillings@1370 2152 }
nickjillings@1370 2153 this.deleteNode.root.textContent = "Delete Entry";
nicholas@2535 2154 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
nickjillings@1370 2155 this.buttonDOM.appendChild(this.deleteNode.root);
nicholas@2535 2156
n@2421 2157 this.moveButtons = {
n@2421 2158 root_up: document.createElement("button"),
n@2421 2159 root_down: document.createElement("button"),
n@2421 2160 parent: this,
nicholas@2535 2161 handleEvent: function (event) {
n@2421 2162 var index = this.parent.parent.getAudioElements().indexOf(this.parent);
n@2421 2163 if (event.currentTarget.getAttribute("direction") == "up") {
nicholas@2535 2164 index = Math.max(index - 1, 0);
n@2421 2165 } else if (event.currentTarget.getAttribute("direction") == "down") {
nicholas@2535 2166 index = Math.min(index + 1, this.parent.parent.getAudioElements().length - 1);
n@2421 2167 }
n@2421 2168 this.parent.moveToPosition(index);
n@2421 2169 this.disable(index);
n@2421 2170 },
nicholas@2535 2171 disable: function (index) {
n@2421 2172 if (index == 0) {
n@2421 2173 this.root_up.disabled = true;
n@2421 2174 } else {
n@2421 2175 this.root_up.disabled = false;
n@2421 2176 }
nicholas@2535 2177 if (index == this.parent.parent.getAudioElements().length - 1) {
n@2421 2178 this.root_down.disabled = true;
n@2421 2179 } else {
n@2421 2180 this.root_down.disabled = false;
n@2421 2181 }
n@2421 2182 }
n@2421 2183 }
nicholas@2535 2184 this.moveButtons.root_up.setAttribute("direction", "up");
nicholas@2535 2185 this.moveButtons.root_down.setAttribute("direction", "down");
nicholas@2535 2186 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
nicholas@2535 2187 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
n@2421 2188 this.moveButtons.root_up.textContent = "Move Up";
n@2421 2189 this.moveButtons.root_down.textContent = "Move Down";
n@2421 2190 this.buttonDOM.appendChild(this.moveButtons.root_up);
n@2421 2191 this.buttonDOM.appendChild(this.moveButtons.root_down);
nicholas@2535 2192
nicholas@2535 2193 this.moveToPosition = function (new_index) {
nicholas@2535 2194
n@2421 2195 // Get the zero-th Object
n@2421 2196 var zero_object = this.parent.getAudioElements()[0];
n@2421 2197 var parent_children_root_index = this.parent.children.indexOf(zero_object);
n@2421 2198 // splice out the array for processing
n@2421 2199 var process_array = this.parent.children.splice(parent_children_root_index);
nicholas@2535 2200
nicholas@2535 2201
n@2421 2202 new_index = Math.min(new_index, process_array.length);
nicholas@2535 2203 var curr_index = process_array.findIndex(function (elem) {
nicholas@2535 2204 if (elem == this) {
nicholas@2535 2205 return true;
nicholas@2535 2206 } else {
nicholas@2535 2207 return false;
nicholas@2535 2208 }
nicholas@2535 2209 }, this);
nicholas@2535 2210
n@2421 2211 // Split at the current location to remove the node and shift all the children up
nicholas@2535 2212 var tail = process_array.splice(curr_index + 1);
n@2421 2213 process_array.pop();
n@2421 2214 process_array = process_array.concat(tail);
nicholas@2535 2215
n@2421 2216 //Split at the new location and insert the node
n@2421 2217 tail = process_array.splice(new_index);
n@2421 2218 process_array.push(this);
n@2421 2219 process_array = process_array.concat(tail);
nicholas@2535 2220
n@2421 2221 // Re-attach to the parent.children
n@2421 2222 this.parent.children = this.parent.children.concat(process_array);
nicholas@2535 2223
n@2421 2224 // Re-build the specification
n@2421 2225 this.parent.specification.audioElements = [];
n@2421 2226 for (var obj of process_array) {
n@2421 2227 this.parent.specification.audioElements.push(obj.specification);
n@2421 2228 }
n@2421 2229 this.parent.redrawChildren();
nicholas@2535 2230
nicholas@2535 2231 process_array.forEach(function (obj, index) {
n@2421 2232 obj.moveButtons.disable(index);
n@2421 2233 });
nicholas@2535 2234
n@2421 2235 }
nickjillings@1370 2236 }
nicholas@2535 2237
nicholas@2535 2238 this.commentQuestionNode = function (parent, rootObject) {
nickjillings@1375 2239 this.type = "commentQuestionNode";
nickjillings@1370 2240 this.rootDOM = document.createElement("div");
nickjillings@1370 2241 this.titleDOM = document.createElement("span");
nickjillings@1370 2242 this.attributeDOM = document.createElement("div");
nickjillings@1370 2243 this.attributes = [];
nickjillings@1370 2244 this.childrenDOM = document.createElement("div");
nickjillings@1370 2245 this.children = [];
nickjillings@1370 2246 this.buttonDOM = document.createElement("div");
nickjillings@1370 2247 this.parent = parent;
nickjillings@1370 2248 this.specification = rootObject;
nickjillings@1370 2249 this.schema = specification.schema.getAllElementsByName("page")[0];
n@2421 2250 this.rootDOM.className = "node audio-element";
nickjillings@1370 2251
nickjillings@1370 2252 var titleDiv = document.createElement('div');
nickjillings@1370 2253 titleDiv.className = "node-title";
nickjillings@1370 2254 this.titleDOM.className = "node-title";
nickjillings@1370 2255 this.titleDOM.textContent = "Test Page";
nickjillings@1370 2256 titleDiv.appendChild(this.titleDOM);
nickjillings@1370 2257
nickjillings@1370 2258 this.attributeDOM.className = "node-attributes";
nickjillings@1370 2259 this.childrenDOM.className = "node-children";
nickjillings@1370 2260 this.buttonDOM.className = "node-buttons";
nickjillings@1370 2261
nickjillings@1370 2262 this.rootDOM.appendChild(titleDiv);
nickjillings@1370 2263 this.rootDOM.appendChild(this.attributeDOM);
nickjillings@1370 2264 this.rootDOM.appendChild(this.childrenDOM);
nickjillings@1370 2265 this.rootDOM.appendChild(this.buttonDOM);
nicholas@2535 2266
nickjillings@1370 2267 }
nicholas@2535 2268
nickjillings@1374 2269 // Build the components
nickjillings@1310 2270 if (this.specification.interfaces.length == 0) {
nickjillings@2194 2271 this.specification.interfaces.push(new specification.interfaceNode(specification));
nickjillings@1310 2272 }
nicholas@2535 2273 for (var interfaceObj of this.specification.interfaces) {
nicholas@2535 2274 var newInterface = new this.parent.interfaceNode(this.parent, interfaceObj);
nicholas@2535 2275 newInterface.build("Interface", "" + this.specification.id + "-interface", this.childrenDOM);
nickjillings@1381 2276 this.children.push(newInterface);
nickjillings@1381 2277 this.interfaces.push(newInterface);
nickjillings@1381 2278 }
nicholas@2535 2279
nicholas@2535 2280 for (var elements of this.specification.audioElements) {
nicholas@2535 2281 var audioElementDOM = new this.audioElementNode(this, elements);
nickjillings@1374 2282 this.children.push(audioElementDOM);
nickjillings@1374 2283 this.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1374 2284 }
nicholas@2535 2285
nicholas@2535 2286 this.getAudioElements().forEach(function (elem) {
n@2421 2287 elem.moveButtons.disable();
n@2421 2288 });
nicholas@2535 2289
nickjillings@1370 2290 this.addInterface = {
nickjillings@1370 2291 root: document.createElement("button"),
nickjillings@1370 2292 parent: this,
nicholas@2535 2293 handleEvent: function () {
nickjillings@2194 2294 var InterfaceObj = new specification.interfaceNode(specification);
nicholas@2535 2295 var newInterface = new this.parent.parent.interfaceNode(this.parent.parent, InterfaceObj);
nicholas@2535 2296 newInterface.build("Interface", "" + this.parent.specification.id + "-interface", this.parent.childrenDOM);
nickjillings@1370 2297 this.parent.children.push(newInterface);
nickjillings@1370 2298 this.parent.specification.interfaces.push(InterfaceObj);
nickjillings@1370 2299 this.parent.interfaces.push(newInterface);
nickjillings@1370 2300 }
nickjillings@1370 2301 }
nickjillings@1370 2302 this.addInterface.root.textContent = "Add Interface";
nicholas@2535 2303 this.addInterface.root.addEventListener("click", this.addInterface, false);
nickjillings@1370 2304 this.buttonDOM.appendChild(this.addInterface.root);
nicholas@2535 2305
nickjillings@1370 2306 this.addAudioElement = {
nickjillings@1370 2307 root: document.createElement("button"),
nickjillings@1370 2308 parent: this,
nicholas@2535 2309 handleEvent: function () {
nickjillings@2194 2310 var audioElementObject = new this.parent.specification.audioElementNode(specification);
nicholas@2535 2311 var audioElementDOM = new this.parent.audioElementNode(this.parent, audioElementObject);
nickjillings@1370 2312 this.parent.specification.audioElements.push(audioElementObject);
nickjillings@1370 2313 this.parent.children.push(audioElementDOM);
nickjillings@1370 2314 this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM);
nickjillings@1370 2315 }
nickjillings@1370 2316 }
nickjillings@1370 2317 this.addAudioElement.root.textContent = "Add Audio Element";
nicholas@2535 2318 this.addAudioElement.root.addEventListener("click", this.addAudioElement, false);
nickjillings@1370 2319 this.buttonDOM.appendChild(this.addAudioElement.root);
nickjillings@1370 2320 }
nicholas@2535 2321 }