Mercurial > hg > webaudioevaluationtool
changeset 2537:f775c27852e1
Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool
author | www-data <www-data@sucuk.dcs.qmul.ac.uk> |
---|---|
date | Mon, 14 Nov 2016 12:20:58 +0000 |
parents | 56847aaebc9b (current diff) 527020a63203 (diff) |
children | bc9a025e7e10 |
files | |
diffstat | 1 files changed, 605 insertions(+), 671 deletions(-) [+] |
line wrap: on
line diff
--- a/test_create/test_core.js Thu Nov 10 14:22:54 2016 +0000 +++ b/test_create/test_core.js Mon Nov 14 12:20:58 2016 +0000 @@ -11,26 +11,21 @@ // and there is no searchAll style command, this custom function will // search all children recusrively for the name. Used for XSD where all // element nodes must have a name and therefore can pull the schema node -XMLDocument.prototype.getAllElementsByName = function(name) -{ +XMLDocument.prototype.getAllElementsByName = function (name) { name = String(name); var selected = this.documentElement.getAllElementsByName(name); return selected; } -Element.prototype.getAllElementsByName = function(name) -{ +Element.prototype.getAllElementsByName = function (name) { name = String(name); var selected = []; var node = this.firstElementChild; - while(node != null) - { - if (node.getAttribute('name') == name) - { + while (node != null) { + if (node.getAttribute('name') == name) { selected.push(node); } - if (node.childElementCount > 0) - { + if (node.childElementCount > 0) { selected = selected.concat(node.getAllElementsByName(name)); } node = node.nextElementSibling; @@ -38,26 +33,21 @@ return selected; } -XMLDocument.prototype.getAllElementsByTagName = function(name) -{ +XMLDocument.prototype.getAllElementsByTagName = function (name) { name = String(name); var selected = this.documentElement.getAllElementsByTagName(name); return selected; } -Element.prototype.getAllElementsByTagName = function(name) -{ +Element.prototype.getAllElementsByTagName = function (name) { name = String(name); var selected = []; var node = this.firstElementChild; - while(node != null) - { - if (node.nodeName == name) - { + while (node != null) { + if (node.nodeName == name) { selected.push(node); } - if (node.childElementCount > 0) - { + if (node.childElementCount > 0) { selected = selected.concat(node.getAllElementsByTagName(name)); } node = node.nextElementSibling; @@ -67,15 +57,12 @@ // Firefox does not have an XMLDocument.prototype.getElementsByName if (typeof XMLDocument.prototype.getElementsByName != "function") { - XMLDocument.prototype.getElementsByName = function(name) - { + XMLDocument.prototype.getElementsByName = function (name) { name = String(name); var node = this.documentElement.firstElementChild; var selected = []; - while(node != null) - { - if (node.getAttribute('name') == name) - { + while (node != null) { + if (node.getAttribute('name') == name) { selected.push(node); } node = node.nextElementSibling; @@ -84,42 +71,37 @@ } } -window.onload = function() -{ +window.onload = function () { specification = new Specification(); convert = new SpecificationToHTML(); xmlHttp = new XMLHttpRequest(); - xmlHttp.open("GET","test_create/interface-specs.xml",true); - xmlHttp.onload = function() - { + xmlHttp.open("GET", "test_create/interface-specs.xml", true); + xmlHttp.onload = function () { var parse = new DOMParser(); - interfaceSpecs = parse.parseFromString(xmlHttp.response,'text/xml'); + interfaceSpecs = parse.parseFromString(xmlHttp.response, 'text/xml'); buildPage(); popupObject.postNode(popupStateNodes.state[0]) } xmlHttp.send(); - + var xsdGet = new XMLHttpRequest(); - xsdGet.open("GET","xml/test-schema.xsd",true); - xsdGet.onload = function() - { + xsdGet.open("GET", "xml/test-schema.xsd", true); + xsdGet.onload = function () { var parse = new DOMParser(); - specification.schema = parse.parseFromString(xsdGet.response,'text/xml');; + specification.schema = parse.parseFromString(xsdGet.response, 'text/xml');; } xsdGet.send(); - + var jsonAttribute = new XMLHttpRequest(); - jsonAttribute.open("GET","test_create/attributes.json",true); - jsonAttribute.onload = function() - { + jsonAttribute.open("GET", "test_create/attributes.json", true); + jsonAttribute.onload = function () { attributeText = JSON.parse(jsonAttribute.response) } jsonAttribute.send(); } -function buildPage() -{ - popupObject = new function() { +function buildPage() { + popupObject = new function () { this.object = document.getElementById("popupHolder"); this.blanket = document.getElementById("blanket"); @@ -134,45 +116,41 @@ this.popupContent = document.createElement("div"); this.popupContent.id = "popup-content"; this.object.appendChild(this.popupContent); - + this.proceedButton = document.createElement("button"); this.proceedButton.id = "popup-proceed"; this.proceedButton.className = "popup-button"; this.proceedButton.textContent = "Next"; - this.proceedButton.onclick = function() - { + this.proceedButton.onclick = function () { popupObject.popupContent.innerHTML = null; - if(typeof popupObject.shownObject.continue == "function") { + if (typeof popupObject.shownObject.continue == "function") { popupObject.shownObject.continue(); } else { popupObject.hide(); } }; this.object.appendChild(this.proceedButton); - + this.backButton = document.createElement("button"); this.backButton.id = "popup-back"; this.backButton.className = "popup-button"; this.backButton.textContent = "Back"; - this.backButton.onclick = function() - { + this.backButton.onclick = function () { popupObject.popupContent.innerHTML = null; popupObject.shownObject.back(); }; this.object.appendChild(this.backButton); - + this.shownObject; - this.resize = function() - { + this.resize = function () { var w = window.innerWidth; var h = window.innerHeight; - this.object.style.left = Math.floor((w-750)/2) + 'px'; - this.object.style.top = Math.floor((h-500)/2) + 'px'; + this.object.style.left = Math.floor((w - 750) / 2) + 'px'; + this.object.style.top = Math.floor((h - 500) / 2) + 'px'; } - this.show = function() - { + this.show = function () { this.object.style.visibility = "visible"; this.blanket.style.visibility = "visible"; if (typeof this.shownObject.back == "function") { @@ -182,15 +160,13 @@ } } - this.hide = function() - { + this.hide = function () { this.object.style.visibility = "hidden"; this.blanket.style.visibility = "hidden"; this.backButton.style.visibility = "hidden"; } - this.postNode = function(postObject) - { + this.postNode = function (postObject) { //Passed object must have the following: // Title: text to show in the title // Content: HTML DOM to show on the page @@ -214,13 +190,11 @@ this.resize(); this.hide(); }; - - popupStateNodes = new function() - { + + popupStateNodes = new function () { // This defines the several popup states wanted this.state = []; - this.state[0] = new function() - { + this.state[0] = new function () { this.title = "Welcome"; this.content = document.createElement("div"); this.content.id = "state-0"; @@ -231,45 +205,43 @@ this.dragArea.className = "drag-area"; this.dragArea.id = "project-drop"; this.content.appendChild(this.dragArea); - - this.dragArea.addEventListener('dragover',function(e){ + + this.dragArea.addEventListener('dragover', function (e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; e.currentTarget.className = "drag-area drag-over"; }); - - this.dragArea.addEventListener('dragexit',function(e){ + + this.dragArea.addEventListener('dragexit', function (e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; e.currentTarget.className = "drag-area"; }); - - this.dragArea.addEventListener('drop',function(e){ + + this.dragArea.addEventListener('drop', function (e) { e.stopPropagation(); e.preventDefault(); e.currentTarget.className = "drag-area drag-dropped"; var files = e.dataTransfer.files[0]; var reader = new FileReader(); - reader.onload = function(decoded) { + reader.onload = function (decoded) { var parse = new DOMParser(); - specification.decode(parse.parseFromString(decoded.target.result,'text/xml')); + specification.decode(parse.parseFromString(decoded.target.result, 'text/xml')); popupObject.hide(); popupObject.popupContent.innerHTML = null; convert.convert(document.getElementById('content')); } reader.readAsText(files); }); - - this.continue = function() - { + + this.continue = function () { popupObject.postNode(popupStateNodes.state[1]); } } - this.state[1] = new function() - { + this.state[1] = new function () { this.title = "Select your interface"; this.content = document.createElement("div"); this.content.id = "state-1"; @@ -283,45 +255,41 @@ this.description = document.createElement("p"); this.content.appendChild(this.description); this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].getElementsByTagName('test'); - for (var i=0; i<this.testsXML.length; i++) - { + for (var i = 0; i < this.testsXML.length; i++) { var option = document.createElement('option'); option.value = this.testsXML[i].getAttribute('name'); option.textContent = this.testsXML[i].getAttribute('name'); this.select.appendChild(option); } - this.handleEvent = function(event) { + this.handleEvent = function (event) { var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0]; var descriptors = testXML.getAllElementsByTagName("description"); this.description.textContent = ""; - for (var i=0; i<descriptors.length; i++) { + for (var i = 0; i < descriptors.length; i++) { if (descriptors[i].getAttribute("lang") == page_lang) { this.description.textContent = descriptors[i].textContent; } } } - this.select.addEventListener("change",this); + this.select.addEventListener("change", this); this.handleEvent(); - this.continue = function() - { + this.continue = function () { var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0]; specification.interface = testXML.getAttribute("interface"); - if (specification.interfaces == null) - { + if (specification.interfaces == null) { specification.interfaces = new specification.interfaceNode(specification); } - if (specification.metrics == null) { + if (specification.metrics == null) { specification.metrics = new specification.metricNode(); } popupStateNodes.state[2].generate(); popupObject.postNode(popupStateNodes.state[2]); } - this.back = function() { + this.back = function () { popupObject.postNode(popupStateNodes.state[0]); } } - this.state[2] = new function() - { + this.state[2] = new function () { this.title = "Test Checks & Restrictions"; this.content = document.createElement("div"); this.content.id = "state-1"; @@ -336,8 +304,7 @@ this.interfaceXML = null; this.dynamicContent = document.createElement("div"); this.content.appendChild(this.dynamicContent); - this.generate = function() - { + this.generate = function () { this.options = []; this.dynamicContent.innerHTML = null; var interfaceName = popupStateNodes.state[1].select.value; @@ -346,16 +313,17 @@ this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0]; this.testXML = this.testXML.getAllElementsByTagName("checks"); var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry'); - for (var i=0; i<interfaceXMLChildren.length; i++) - { + for (var i = 0; i < interfaceXMLChildren.length; i++) { var interfaceNode = interfaceXMLChildren[i]; var checkName = interfaceNode.getAttribute('name'); var testNode - if (this.testXML.length > 0) - { + if (this.testXML.length > 0) { testNode = this.testXML[0].getAllElementsByName(checkName); - if(testNode.length != 0) {testNode = testNode[0];} - else {testNode = undefined;} + if (testNode.length != 0) { + testNode = testNode[0]; + } else { + testNode = undefined; + } } else { testNode = undefined; } @@ -365,72 +333,80 @@ input: document.createElement("input"), parent: this, name: checkName, - handleEvent: function(event) { + handleEvent: function (event) { if (this.input.checked) { // Add to specification.interfaces.option - var included = specification.interfaces.options.find(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },this); + var included = specification.interfaces.options.find(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, this); if (included == null) { - specification.interfaces.options.push({type:"check",name:this.name}); + specification.interfaces.options.push({ + type: "check", + name: this.name + }); } } else { // Remove from specification.interfaces.option - var position = specification.interfaces.options.findIndex(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },this); + var position = specification.interfaces.options.findIndex(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, this); if (position >= 0) { - specification.interfaces.options.splice(position,1); + specification.interfaces.options.splice(position, 1); } } } } - - obj.input.addEventListener("click",obj); + + obj.input.addEventListener("click", obj); obj.root.className = "popup-checkbox"; obj.input.type = "checkbox"; - obj.input.setAttribute('id',checkName); - obj.text.setAttribute("for",checkName); + obj.input.setAttribute('id', checkName); + obj.text.setAttribute("for", checkName); obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; obj.root.appendChild(obj.input); obj.root.appendChild(obj.text); - if(testNode != undefined) - { - if (testNode.getAttribute('default') == 'on') - { + if (testNode != undefined) { + if (testNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (testNode.getAttribute('support') == "none") - { + if (testNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - }else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } else { - if (interfaceNode.getAttribute('default') == 'on') - { + if (interfaceNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (interfaceNode.getAttribute('support') == "none") - { + if (interfaceNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - } else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } - var included = specification.interfaces.options.find(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },obj); + var included = specification.interfaces.options.find(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, obj); if (included != undefined) { obj.input.checked = true; } @@ -439,17 +415,15 @@ this.dynamicContent.appendChild(obj.root); } } - this.continue = function() - { + this.continue = function () { popupStateNodes.state[3].generate(); popupObject.postNode(popupStateNodes.state[3]); } - this.back = function() { + this.back = function () { popupObject.postNode(popupStateNodes.state[1]); } } - this.state[3] = new function() - { + this.state[3] = new function () { this.title = "Test Metrics"; this.content = document.createElement("div"); this.content.id = "state-1"; @@ -464,8 +438,7 @@ this.interfaceXML; this.dynamicContent = document.createElement("div"); this.content.appendChild(this.dynamicContent); - this.generate = function() - { + this.generate = function () { this.options = []; this.dynamicContent.innerHTML = null; var interfaceName = popupStateNodes.state[1].select.value; @@ -474,16 +447,17 @@ this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0]; this.testXML = this.testXML.getAllElementsByTagName("metrics"); var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry'); - for (var i=0; i<interfaceXMLChildren.length; i++) - { + for (var i = 0; i < interfaceXMLChildren.length; i++) { var interfaceNode = interfaceXMLChildren[i]; var checkName = interfaceNode.getAttribute('name'); var testNode - if (this.testXML.length > 0) - { + if (this.testXML.length > 0) { testNode = this.testXML[0].getAllElementsByName(checkName); - if(testNode.length != 0) {testNode = testNode[0];} - else {testNode = undefined;} + if (testNode.length != 0) { + testNode = testNode[0]; + } else { + testNode = undefined; + } } else { testNode = undefined; } @@ -493,72 +467,77 @@ input: document.createElement("input"), parent: this, name: checkName, - handleEvent: function(event) { + handleEvent: function (event) { if (this.input.checked) { // Add to specification.interfaces.option - var included = specification.metrics.enabled.find(function(element,index,array){ - if (element == this.name) {return true;} else {return false;} - },this); + var included = specification.metrics.enabled.find(function (element, index, array) { + if (element == this.name) { + return true; + } else { + return false; + } + }, this); if (included == null) { specification.metrics.enabled.push(this.name); } } else { // Remove from specification.interfaces.option - var position = specification.metrics.enabled.findIndex(function(element,index,array){ - if (element == this.name) {return true;} else {return false;} - },this); + var position = specification.metrics.enabled.findIndex(function (element, index, array) { + if (element == this.name) { + return true; + } else { + return false; + } + }, this); if (position >= 0) { - specification.metrics.enabled.splice(position,1); + specification.metrics.enabled.splice(position, 1); } } } } - - obj.input.addEventListener("click",obj); + + obj.input.addEventListener("click", obj); obj.root.className = "popup-checkbox"; obj.input.type = "checkbox"; - obj.input.setAttribute('id',checkName); - obj.text.setAttribute("for",checkName); + obj.input.setAttribute('id', checkName); + obj.text.setAttribute("for", checkName); obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; obj.root.appendChild(obj.input); obj.root.appendChild(obj.text); - if(testNode != undefined) - { - if (testNode.getAttribute('default') == 'on') - { + if (testNode != undefined) { + if (testNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (testNode.getAttribute('support') == "none") - { + if (testNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - }else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } else { - if (interfaceNode.getAttribute('default') == 'on') - { + if (interfaceNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (interfaceNode.getAttribute('support') == "none") - { + if (interfaceNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - } else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } - var included = specification.metrics.enabled.find(function(element,index,array){ - if (element == this.name) {return true;} else {return false;} - },obj); + var included = specification.metrics.enabled.find(function (element, index, array) { + if (element == this.name) { + return true; + } else { + return false; + } + }, obj); obj.handleEvent(); if (included != undefined) { obj.input.checked = true; @@ -567,17 +546,15 @@ this.dynamicContent.appendChild(obj.root); } } - this.continue = function() - { + this.continue = function () { popupStateNodes.state[4].generate(); popupObject.postNode(popupStateNodes.state[4]); } - this.back = function() { + this.back = function () { popupObject.postNode(popupStateNodes.state[2]); } } - this.state[4] = new function() - { + this.state[4] = new function () { this.title = "Test Visuals"; this.content = document.createElement("div"); this.content.id = "state-1"; @@ -592,8 +569,7 @@ this.interfaceXML; this.dynamicContent = document.createElement("div"); this.content.appendChild(this.dynamicContent); - this.generate = function() - { + this.generate = function () { this.options = []; this.dynamicContent.innerHTML = null; var interfaceName = popupStateNodes.state[1].select.value; @@ -602,16 +578,17 @@ this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0]; this.testXML = this.testXML.getAllElementsByTagName("show"); var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry'); - for (var i=0; i<interfaceXMLChildren.length; i++) - { + for (var i = 0; i < interfaceXMLChildren.length; i++) { var interfaceNode = interfaceXMLChildren[i]; var checkName = interfaceNode.getAttribute('name'); var testNode - if (this.testXML.length > 0) - { + if (this.testXML.length > 0) { testNode = this.testXML[0].getAllElementsByName(checkName); - if(testNode.length != 0) {testNode = testNode[0];} - else {testNode = undefined;} + if (testNode.length != 0) { + testNode = testNode[0]; + } else { + testNode = undefined; + } } else { testNode = undefined; } @@ -621,72 +598,80 @@ input: document.createElement("input"), parent: this, name: checkName, - handleEvent: function(event) { + handleEvent: function (event) { if (this.input.checked) { // Add to specification.interfaces.option - var included = specification.interfaces.options.find(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },this); + var included = specification.interfaces.options.find(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, this); if (included == null) { - specification.interfaces.options.push({type:"show",name:this.name}); + specification.interfaces.options.push({ + type: "show", + name: this.name + }); } } else { // Remove from specification.interfaces.option - var position = specification.interfaces.options.findIndex(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },this); + var position = specification.interfaces.options.findIndex(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, this); if (position >= 0) { - specification.interfaces.options.splice(position,1); + specification.interfaces.options.splice(position, 1); } } } } - - obj.input.addEventListener("click",obj); + + obj.input.addEventListener("click", obj); obj.root.className = "popup-checkbox"; obj.input.type = "checkbox"; - obj.input.setAttribute('id',checkName); - obj.text.setAttribute("for",checkName); + obj.input.setAttribute('id', checkName); + obj.text.setAttribute("for", checkName); obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; obj.root.appendChild(obj.input); obj.root.appendChild(obj.text); - if(testNode != undefined) - { - if (testNode.getAttribute('default') == 'on') - { + if (testNode != undefined) { + if (testNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (testNode.getAttribute('support') == "none") - { + if (testNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - }else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } else { - if (interfaceNode.getAttribute('default') == 'on') - { + if (interfaceNode.getAttribute('default') == 'on') { obj.input.checked = true; } - if (interfaceNode.getAttribute('support') == "none") - { + if (interfaceNode.getAttribute('support') == "none") { obj.input.disabled = true; obj.input.checked = false; obj.root.className = "popup-checkbox disabled"; - } else if (interfaceNode.getAttribute('support') == "mandatory") - { + } else if (interfaceNode.getAttribute('support') == "mandatory") { obj.input.disabled = true; obj.input.checked = true; obj.root.className = "popup-checkbox disabled"; } } - var included = specification.interfaces.options.find(function(element,index,array){ - if (element.name == this.name) {return true;} else {return false;} - },obj); + var included = specification.interfaces.options.find(function (element, index, array) { + if (element.name == this.name) { + return true; + } else { + return false; + } + }, obj); if (included != undefined) { obj.input.checked = true; } @@ -695,16 +680,15 @@ this.dynamicContent.appendChild(obj.root); } } - this.continue = function() - { + this.continue = function () { popupObject.hide(); convert.convert(document.getElementById('content')); } - this.back = function() { + this.back = function () { popupObject.postNode(popupStateNodes.state[3]); } } - this.state[5] = new function() { + this.state[5] = new function () { this.title = "Add/Edit Survey Element"; this.content = document.createElement("div"); this.content.id = "state-1"; @@ -718,31 +702,29 @@ this.parent = null; this.optionLists = []; this.select = document.createElement("select"); - this.select.setAttribute("name","type"); - this.select.addEventListener("change",this,false); + this.select.setAttribute("name", "type"); + this.select.addEventListener("change", this, false); this.content.appendChild(this.select); this.content.appendChild(this.dynamic); - this.generate = function(option, parent) - { + this.generate = function (option, parent) { this.option = option; this.parent = parent; if (this.select.childElementCount == 0) { var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("type")[0].getAllElementsByTagName("xs:enumeration"); - for (var i=0; i<optionList.length; i++) - { + for (var i = 0; i < optionList.length; i++) { var selectOption = document.createElement("option"); selectOption.value = optionList[i].getAttribute("value"); selectOption.textContent = selectOption.value; this.select.appendChild(selectOption); } } - if (this.option.type != undefined){ + if (this.option.type != undefined) { this.select.value = this.option.type } else { this.select.value = "statement"; this.option.type = "statement"; } - + this.dynamic.innerHTML = null; var statement = document.createElement("div"); var statementText = document.createElement("span"); @@ -752,11 +734,11 @@ statement.className = "survey-entry-attribute"; statementText.textContent = "Statement/Question"; statementEntry.style.width = "500px"; - statementEntry.addEventListener("change",this,false); - statementEntry.setAttribute("name","statement"); + statementEntry.addEventListener("change", this, false); + statementEntry.setAttribute("name", "statement"); statementEntry.value = this.option.statement; this.dynamic.appendChild(statement); - + var id = document.createElement("div"); var idText = document.createElement("span"); var idEntry = document.createElement("input"); @@ -764,34 +746,32 @@ id.appendChild(idEntry); id.className = "survey-entry-attribute"; idText.textContent = "ID: "; - idEntry.addEventListener("change",this,false); - idEntry.setAttribute("name","id"); + idEntry.addEventListener("change", this, false); + idEntry.setAttribute("name", "id"); idEntry.value = this.option.id; - + this.dynamic.appendChild(id); - - switch(this.option.type) - { + + switch (this.option.type) { case "statement": break; case "question": var boxsizeSelect = document.createElement("select"); var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration"); - for (var i=0; i<optionList.length; i++) - { + for (var i = 0; i < optionList.length; i++) { var selectOption = document.createElement("option"); selectOption.value = optionList[i].getAttribute("value"); selectOption.textContent = selectOption.value; boxsizeSelect.appendChild(selectOption); } - if(this.option.boxsize != undefined) { + if (this.option.boxsize != undefined) { boxsizeSelect.value = this.option.boxsize; } else { boxsizeSelect.value = "normal"; this.option.boxsize = "normal"; } - boxsizeSelect.setAttribute("name","boxsize"); - boxsizeSelect.addEventListener("change",this,false); + boxsizeSelect.setAttribute("name", "boxsize"); + boxsizeSelect.addEventListener("change", this, false); var boxsize = document.createElement("div"); var boxsizeText = document.createElement("span"); boxsizeText.textContent = "Entry Size: "; @@ -799,7 +779,7 @@ boxsize.appendChild(boxsizeSelect); boxsize.className = "survey-entry-attribute"; this.dynamic.appendChild(boxsize); - + var mandatory = document.createElement("div"); var mandatoryInput = document.createElement("input"); var mandatoryText = document.createElement("span"); @@ -808,14 +788,18 @@ mandatory.appendChild(mandatoryInput); mandatory.className = "survey-entry-attribute"; mandatoryInput.type = "checkbox"; - if (this.option.mandatory) {mandatoryInput.checked = true;} else {mandatoryInput.checked = false;} - mandatoryInput.setAttribute("name","mandatory"); - mandatoryInput.addEventListener("change",this,false); + if (this.option.mandatory) { + mandatoryInput.checked = true; + } else { + mandatoryInput.checked = false; + } + mandatoryInput.setAttribute("name", "mandatory"); + mandatoryInput.addEventListener("change", this, false); this.dynamic.appendChild(mandatory); break; case "number": this.dynamic.appendChild(id); - + var mandatory = document.createElement("div"); var mandatoryInput = document.createElement("input"); var mandatoryText = document.createElement("span"); @@ -824,11 +808,15 @@ mandatory.appendChild(mandatoryInput); mandatory.className = "survey-entry-attribute"; mandatoryInput.type = "checkbox"; - if (this.option.mandatory) {mandatoryInput.checked = true;} else {mandatoryInput.checked = false;} - mandatoryInput.setAttribute("name","mandatory"); - mandatoryInput.addEventListener("change",this,false); + if (this.option.mandatory) { + mandatoryInput.checked = true; + } else { + mandatoryInput.checked = false; + } + mandatoryInput.setAttribute("name", "mandatory"); + mandatoryInput.addEventListener("change", this, false); this.dynamic.appendChild(mandatory); - + var minimum = document.createElement("div"); var minimumEntry = document.createElement("input"); var minimumText = document.createElement("span"); @@ -837,11 +825,11 @@ minimum.appendChild(minimumEntry); minimum.className = "survey-entry-attribute"; minimumEntry.type = "number"; - minimumEntry.setAttribute("name","min"); - minimumEntry.addEventListener("change",this,false); + minimumEntry.setAttribute("name", "min"); + minimumEntry.addEventListener("change", this, false); minimumEntry.value = this.option.min; this.dynamic.appendChild(minimum); - + var maximum = document.createElement("div"); var maximumEntry = document.createElement("input"); var maximumText = document.createElement("span"); @@ -850,8 +838,8 @@ maximum.appendChild(maximumEntry); maximum.className = "survey-entry-attribute"; maximumEntry.type = "number"; - maximumEntry.setAttribute("name","max"); - maximumEntry.addEventListener("change",this,false); + maximumEntry.setAttribute("name", "max"); + maximumEntry.addEventListener("change", this, false); maximumEntry.value = this.option.max; this.dynamic.appendChild(maximum); break; @@ -861,21 +849,20 @@ var optionHolder = document.createElement("div"); optionHolder.className = 'node'; optionHolder.id = 'popup-option-holder'; - var optionObject = function(parent,option) { + var optionObject = function (parent, option) { this.rootDOM = document.createElement("div"); this.rootDOM.className = "popup-option-entry"; this.inputName = document.createElement("input"); - this.inputName.setAttribute("name","name"); + this.inputName.setAttribute("name", "name"); this.inputLabel = document.createElement("input"); - this.inputLabel.setAttribute("name","text"); + this.inputLabel.setAttribute("name", "text"); this.specification = option; this.parent = parent; - this.handleEvent = function() - { + this.handleEvent = function () { var target = event.currentTarget.getAttribute("name"); - eval("this.specification."+target+" = event.currentTarget.value"); + eval("this.specification." + target + " = event.currentTarget.value"); }; - + var nameText = document.createElement("span"); nameText.textContent = "Name: "; var labelText = document.createElement("span"); @@ -884,87 +871,85 @@ this.rootDOM.appendChild(this.inputName); this.rootDOM.appendChild(labelText); this.rootDOM.appendChild(this.inputLabel); - this.inputName.addEventListener("change",this,false); - this.inputLabel.addEventListener("change",this,false); + this.inputName.addEventListener("change", this, false); + this.inputLabel.addEventListener("change", this, false); this.inputName.value = this.specification.name; this.inputLabel.value = this.specification.text; this.inputLabel.style.width = "350px"; - + this.deleteEntry = { root: document.createElement("button"), parent: this, - handleEvent: function() { + handleEvent: function () { document.getElementById("popup-option-holder").removeChild(this.parent.rootDOM); - var index = this.parent.parent.option.options.findIndex(function(element,index,array){ + var index = this.parent.parent.option.options.findIndex(function (element, index, array) { if (element == this.parent.specification) return true; else return false; - },this); + }, this); var optionList = this.parent.parent.option.options; - if (index == optionList.length-1) { - optionList = optionList.slice(0,index); + if (index == optionList.length - 1) { + optionList = optionList.slice(0, index); } else { - optionList = optionList.slice(0,index).concat(optionList.slice(index+1)); + optionList = optionList.slice(0, index).concat(optionList.slice(index + 1)); } this.parent.parent.option.options = optionList; } }; this.deleteEntry.root.textContent = "Delete Option"; - this.deleteEntry.root.addEventListener("click",this.deleteEntry,false); + this.deleteEntry.root.addEventListener("click", this.deleteEntry, false); this.rootDOM.appendChild(this.deleteEntry.root); } this.addEntry = { parent: this, root: document.createElement("button"), - handleEvent: function() { - var node = {name: "name", text: "text"}; + handleEvent: function () { + var node = { + name: "name", + text: "text" + }; var optionsList = this.parent.option.options; optionsList.push(node); - var obj = new optionObject(this.parent,optionsList[optionsList.length-1]); + var obj = new optionObject(this.parent, optionsList[optionsList.length - 1]); this.parent.optionLists.push(obj); document.getElementById("popup-option-holder").appendChild(obj.rootDOM); } } this.addEntry.root.textContent = "Add Option"; - this.addEntry.root.addEventListener("click",this.addEntry); + this.addEntry.root.addEventListener("click", this.addEntry); this.dynamic.appendChild(this.addEntry.root); - for (var i=0; i<this.option.options.length; i++) - { - var obj = new optionObject(this,this.option.options[i]); + for (var i = 0; i < this.option.options.length; i++) { + var obj = new optionObject(this, this.option.options[i]); this.optionLists.push(obj); optionHolder.appendChild(obj.rootDOM); } this.dynamic.appendChild(optionHolder); } } - this.handleEvent = function() - { + this.handleEvent = function (event) { var name = event.currentTarget.getAttribute("name"); var nodeName = event.currentTarget.nodeName; if (name == "type" && nodeName == "SELECT") { // If type has changed, we may need to rebuild the entire state node - if (event.currentTarget.value != this.option.name) - { + if (event.currentTarget.value != this.option.name) { this.option.type = event.currentTarget.value; - this.generate(this.option,this.parent); + this.generate(this.option, this.parent); } return; } - switch(event.currentTarget.getAttribute("type")) { + switch (event.currentTarget.getAttribute("type")) { case "checkbox": - eval("this.option."+name+" = event.currentTarget.checked"); + eval("this.option." + name + " = event.currentTarget.checked"); break; default: - eval("this.option."+name+" = event.currentTarget.value"); + eval("this.option." + name + " = event.currentTarget.value"); break; } } - this.continue = function() - { - if (this.parent.type == "surveyNode") - { - var newNode = new this.parent.surveyEntryNode(this.parent,this.option); + this.continue = function () { + if (this.parent.type == "surveyNode") { + var newNode = new this.parent.surveyEntryNode(this.parent, this.option); this.parent.children.push(newNode); this.parent.childrenDOM.appendChild(newNode.rootDOM); } else if (this.parent.type == "surveyEntryNode") { @@ -973,7 +958,7 @@ popupObject.hide(); } } - this.state[6] = new function() { + this.state[6] = new function () { this.title = "Edit Scale Markers"; this.content = document.createElement("div"); this.content.id = "state-6"; @@ -983,16 +968,15 @@ spnH.appendChild(span); this.scaleRoot; this.parent; - this.markerNodes =[]; + this.markerNodes = []; this.preset = { input: document.createElement("select"), parent: this, - handleEvent: function(event) { + handleEvent: function (event) { this.parent.scaleRoot.scales = []; var protoScale = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getAllElementsByName(event.currentTarget.value)[0]; var protoMarkers = protoScale.getElementsByTagName("scale"); - for (var i=0; i<protoMarkers.length; i++) - { + for (var i = 0; i < protoMarkers.length; i++) { var marker = { position: protoMarkers[i].getAttribute("position"), text: protoMarkers[i].textContent @@ -1002,81 +986,77 @@ this.parent.buildMarkerList(); } } - this.preset.input.addEventListener("change",this.preset); + this.preset.input.addEventListener("change", this.preset); this.content.appendChild(this.preset.input); var optionHolder = document.createElement("div"); optionHolder.className = 'node'; optionHolder.id = 'popup-option-holder'; this.content.appendChild(optionHolder); - this.generate = function(scaleRoot,parent) - { + this.generate = function (scaleRoot, parent) { this.scaleRoot = scaleRoot; this.parent = parent; - + // Generate Pre-Set dropdown var protoScales = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getElementsByTagName("scale"); this.preset.input.innerHTML = ""; - - for (var i=0; i<protoScales.length; i++) - { + + for (var i = 0; i < protoScales.length; i++) { var selectOption = document.createElement("option"); var scaleName = protoScales[i].getAttribute("name"); - selectOption.setAttribute("name",scaleName); + selectOption.setAttribute("name", scaleName); selectOption.textContent = scaleName; this.preset.input.appendChild(selectOption); } - + this.addMarker = { root: document.createElement("button"), parent: this, - handleEvent: function() { + handleEvent: function () { var marker = { position: 0, text: "text" }; this.parent.scaleRoot.scales.push(marker); - var markerNode = new this.parent.buildMarkerNode(this.parent,marker); + var markerNode = new this.parent.buildMarkerNode(this.parent, marker); document.getElementById("popup-option-holder").appendChild(markerNode.root); this.parent.markerNodes.push(markerNode); } }; this.addMarker.root.textContent = "Add Marker"; - this.addMarker.root.addEventListener("click",this.addMarker); + this.addMarker.root.addEventListener("click", this.addMarker); this.content.appendChild(this.addMarker.root); - + // Create Marker List this.buildMarkerList(); } - this.buildMarkerList = function() { + this.buildMarkerList = function () { var markerInject = document.getElementById("popup-option-holder"); markerInject.innerHTML = ""; this.markerNodes = []; - for (var i=0; i<this.scaleRoot.scales.length; i++) - { - var markerNode = new this.buildMarkerNode(this,this.scaleRoot.scales[i]); + for (var i = 0; i < this.scaleRoot.scales.length; i++) { + var markerNode = new this.buildMarkerNode(this, this.scaleRoot.scales[i]); markerInject.appendChild(markerNode.root); this.markerNodes.push(markerNode); - + } } - - this.buildMarkerNode = function(parent,specification) { + + this.buildMarkerNode = function (parent, specification) { this.root = document.createElement("div"); this.root.className = "popup-option-entry"; this.positionInput = document.createElement("input"); this.positionInput.min = 0; this.positionInput.max = 100; this.positionInput.value = specification.position; - this.positionInput.setAttribute("name","position"); + this.positionInput.setAttribute("name", "position"); this.textInput = document.createElement("input"); - this.textInput.setAttribute("name","text"); + this.textInput.setAttribute("name", "text"); this.textInput.style.width = "300px"; this.textInput.value = specification.text; this.specification = specification; this.parent = parent; - this.handleEvent = function(event) { - switch(event.currentTarget.getAttribute("name")) - { + this.handleEvent = function (event) { + switch (event.currentTarget.getAttribute("name")) { case "position": this.specification.position = Number(event.currentTarget.value); break; @@ -1085,8 +1065,8 @@ break; } } - this.positionInput.addEventListener("change",this,false); - this.textInput.addEventListener("change",this,false); + this.positionInput.addEventListener("change", this, false); + this.textInput.addEventListener("change", this, false); var posText = document.createElement("span"); posText.textContent = "Position: "; @@ -1100,17 +1080,21 @@ this.deleteMarker = { root: document.createElement("button"), parent: this, - handleEvent: function() { - var index = this.parent.parent.scaleRoot.scales.findIndex(function(element,index,array){ - if (element == this) {return true;} else {return false;} - },this.parent.specification) + handleEvent: function () { + var index = this.parent.parent.scaleRoot.scales.findIndex(function (element, index, array) { + if (element == this) { + return true; + } else { + return false; + } + }, this.parent.specification) if (index >= 0) { - this.parent.parent.scaleRoot.scales.splice(index,1); + this.parent.parent.scaleRoot.scales.splice(index, 1); } document.getElementById("popup-option-holder").removeChild(this.parent.root); } } - this.deleteMarker.root.addEventListener("click",this.deleteMarker); + this.deleteMarker.root.addEventListener("click", this.deleteMarker); this.deleteMarker.root.textContent = "Delete Marker" this.root.appendChild(this.deleteMarker.root); } @@ -1118,8 +1102,7 @@ } } -function SpecificationToHTML() -{ +function SpecificationToHTML() { // This takes the specification node and converts it to an on-page HTML object // Each Specification Node is given its own JS object which listens to the XSD for instant verification // Once generated, it directly binds into the specification object to update with changes @@ -1127,10 +1110,9 @@ this.injectDOM; this.setupDOM; this.pages = []; - + // Self-contained generators - this.createGeneralNodeDOM = function(name,id,parent) - { + this.createGeneralNodeDOM = function (name, id, parent) { this.type = name; var root = document.createElement('div'); root.id = id; @@ -1169,21 +1151,18 @@ } return obj; } - - this.convertAttributeToDOM = function(node,schema) - { + + this.convertAttributeToDOM = function (node, schema) { // This takes an attribute schema node and returns an object with the input node and any bindings - if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) - { - schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; - } - var obj = new function() - { + if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) { + schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; + } + var obj = new function () { this.input; this.name; this.owner; this.holder; - + this.name = schema.getAttribute('name'); this.default = schema.getAttribute('default'); this.dataType = schema.getAttribute('type'); @@ -1194,12 +1173,14 @@ } } } - if (typeof this.dataType == "string") { this.dataType = this.dataType.substr(3);} - else {this.dataType = "string";} + if (typeof this.dataType == "string") { + this.dataType = this.dataType.substr(3); + } else { + this.dataType = "string"; + } var minVar = undefined; var maxVar = undefined; - switch(this.dataType) - { + switch (this.dataType) { case "negativeInteger": maxVar = -1; break; @@ -1223,12 +1204,11 @@ default: break; } - + this.enumeration = schema.getAllElementsByTagName("xs:enumeration"); if (this.enumeration.length == 0) { this.input = document.createElement('input'); - switch(this.dataType) - { + switch (this.dataType) { case "boolean": this.input.type = "checkbox"; break; @@ -1250,34 +1230,32 @@ } } else { this.input = document.createElement("select"); - for (var i=0; i<this.enumeration.length; i++) - { + for (var i = 0; i < this.enumeration.length; i++) { var option = document.createElement("option"); var value = this.enumeration[i].getAttribute("value"); - option.setAttribute("value",value); + option.setAttribute("value", value); option.textContent = value; this.input.appendChild(option); } } var value; - eval("value = node."+this.name) - if (this.default != undefined && value == undefined) - { + eval("value = node." + this.name) + if (this.default != undefined && value == undefined) { value = this.default; } if (this.input.type == "checkbox") { - if (value == "true" || value == "True") {this.input.checked = false;} - else {this.input.checked = false;} + if (value == "true" || value == "True") { + this.input.checked = false; + } else { + this.input.checked = false; + } } else { this.input.value = value; } - this.handleEvent = function(event) - { + this.handleEvent = function (event) { var value; - if (this.input.nodeName == "INPUT") - { - switch(this.input.type) - { + if (this.input.nodeName == "INPUT") { + switch (this.input.type) { case "checkbox": value = event.currentTarget.checked; break; @@ -1294,40 +1272,37 @@ } else { value = undefined; } - break; + break; } } else if (this.input.nodeName == "SELECT") { value = event.currentTarget.value; } - eval("this.owner."+this.name+" = value"); + eval("this.owner." + this.name + " = value"); } this.holder = document.createElement('div'); this.holder.className = "attribute"; - this.holder.setAttribute('name',this.name); + this.holder.setAttribute('name', this.name); var text = document.createElement('span'); - eval("text.textContent = attributeText."+this.name+"+': '"); + eval("text.textContent = attributeText." + this.name + "+': '"); this.holder.appendChild(text); this.holder.appendChild(this.input); this.owner = node; - this.input.addEventListener("change",this,false); + this.input.addEventListener("change", this, false); } - if (obj.attribute != null) - { + if (obj.attribute != null) { obj.input.value = obj.attribute; } return obj; } - - this.convert = function(root) - { + + this.convert = function (root) { //Performs the actual conversion using the given root DOM as the root this.injectDOM = root; - + // Build the export button var exportButton = document.createElement("button"); exportButton.textContent = "Export to XML"; - exportButton.onclick = function() - { + exportButton.onclick = function () { var doc = specification.encode(); var obj = {}; obj.title = "Export"; @@ -1342,7 +1317,9 @@ var link = document.createElement("div"); link.appendChild(doc.firstChild); var file = [link.innerHTML]; - var bb = new Blob(file,{type : 'application/xml'}); + var bb = new Blob(file, { + type: 'application/xml' + }); var dnlk = window.URL.createObjectURL(bb); var a = document.createElement("a"); a.hidden = ''; @@ -1354,22 +1331,21 @@ popupObject.postNode(obj); } this.injectDOM.appendChild(exportButton); - + // First perform the setupNode; var setupSchema = specification.schema.getAllElementsByName('setup')[0]; - this.setupDOM = new this.createGeneralNodeDOM('Global Configuration','setup',null); + this.setupDOM = new this.createGeneralNodeDOM('Global Configuration', 'setup', null); this.injectDOM.appendChild(this.setupDOM.rootDOM); var setupAttributes = setupSchema.getAllElementsByTagName('xs:attribute'); - for (var i=0; i<setupAttributes.length; i++) - { + for (var i = 0; i < setupAttributes.length; i++) { var attributeName = setupAttributes[i].getAttribute('name'); - var attrObject = this.convertAttributeToDOM(specification,setupAttributes[i]); + var attrObject = this.convertAttributeToDOM(specification, setupAttributes[i]); this.setupDOM.attributeDOM.appendChild(attrObject.holder); this.setupDOM.attributes.push(attrObject); } - + // Build the exit Text node - var exitText = new this.createGeneralNodeDOM("Exit Text","exit-test",this.setupDOM); + var exitText = new this.createGeneralNodeDOM("Exit Text", "exit-test", this.setupDOM); exitText.rootDOM.removeChild(exitText.attributeDOM); this.setupDOM.children.push(exitText); this.setupDOM.childrenDOM.appendChild(exitText.rootDOM); @@ -1379,7 +1355,7 @@ inputDOM: document.createElement("textarea"), parent: exitText, specification: specification, - handleEvent: function(event) { + handleEvent: function (event) { this.specification.exitText = this.inputDOM.value; } } @@ -1390,16 +1366,16 @@ obj.rootDOM.appendChild(obj.inputDOM); obj.labelDOM.textContent = "Text: "; obj.inputDOM.value = obj.specification.exitText; - obj.inputDOM.addEventListener("change",obj); + obj.inputDOM.addEventListener("change", obj); exitText.children.push(obj); exitText.childrenDOM.appendChild(obj.rootDOM); - + // Now we must build the interface Node - this.interfaceDOM = new this.interfaceNode(this,specification.interfaces); - this.interfaceDOM.build("Interface","setup-interface",this.setupDOM.rootDOM); - + this.interfaceDOM = new this.interfaceNode(this, specification.interfaces); + this.interfaceDOM.build("Interface", "setup-interface", this.setupDOM.rootDOM); + // Now build the Metrics selection node - var metric = this.createGeneralNodeDOM("Session Metrics","setup-metric",this.setupDOM); + var metric = this.createGeneralNodeDOM("Session Metrics", "setup-metric", this.setupDOM); metric.rootDOM.removeChild(metric.attributeDOM); this.setupDOM.children.push(metric); this.setupDOM.childrenDOM.appendChild(metric.rootDOM); @@ -1409,26 +1385,22 @@ var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0]; testXML = testXML.getAllElementsByTagName("metrics"); var interfaceXMLChild = interfaceXML.firstElementChild; - while(interfaceXMLChild) - { + while (interfaceXMLChild) { var obj = { input: document.createElement('input'), root: document.createElement('div'), text: document.createElement('span'), specification: specification.metrics.enabled, name: interfaceXMLChild.getAttribute("name"), - handleEvent: function() - { - for (var i=0; i<this.specification.length; i++) - { - if (this.specification[i] == this.name) - { + handleEvent: function () { + for (var i = 0; i < this.specification.length; i++) { + if (this.specification[i] == this.name) { var options = this.specification; if (this.input.checked == false) { - if (i == options.length) - {options = options.slice(0,i);} - else { - options = options.slice(0,i).concat(options.slice(i+1)); + if (i == options.length) { + options = options.slice(0, i); + } else { + options = options.slice(0, i).concat(options.slice(i + 1)); } } else { return; @@ -1449,42 +1421,39 @@ obj.text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent; metric.children.push(obj); metric.childrenDOM.appendChild(obj.root); - for (var j=0; j<specification.metrics.enabled.length; j++) - { - if (specification.metrics.enabled[j] == obj.name) - { + for (var j = 0; j < specification.metrics.enabled.length; j++) { + if (specification.metrics.enabled[j] == obj.name) { obj.input.checked = true; break; } } interfaceXMLChild = interfaceXMLChild.nextElementSibling; } - + // Now both before and after surveys - if (specification.preTest == undefined){ + if (specification.preTest == undefined) { specification.preTest = new specification.surveyNode(specification); specification.preTest.location = "pre"; } - if (specification.postTest == undefined){ + if (specification.postTest == undefined) { specification.postTest = new specification.surveyNode(specification); specification.postTest.location = "post"; } - var surveyBefore = new this.surveyNode(this,specification.preTest,"Pre"); - var surveyAfter = new this.surveyNode(this,specification.postTest,"Post"); + var surveyBefore = new this.surveyNode(this, specification.preTest, "Pre"); + var surveyAfter = new this.surveyNode(this, specification.postTest, "Post"); this.setupDOM.children.push(surveyBefore); this.setupDOM.children.push(surveyAfter); this.setupDOM.childrenDOM.appendChild(surveyBefore.rootDOM); this.setupDOM.childrenDOM.appendChild(surveyAfter.rootDOM); - + // Add in the page creator button this.addPage = { root: document.createElement("button"), parent: this, - handleEvent: function() - { + handleEvent: function () { var pageObj = new specification.page(specification); specification.pages.push(pageObj); - var newPage = new this.parent.pageNode(this.parent,pageObj); + var newPage = new this.parent.pageNode(this.parent, pageObj); document.getElementById("page-holder").appendChild(newPage.rootDOM); this.parent.pages.push(newPage); } @@ -1492,25 +1461,23 @@ this.addPage.root.textContent = "Add Page"; this.addPage.root.id = "new-page-button"; this.addPage.root.style.float = "left"; - this.addPage.root.addEventListener("click",this.addPage,false); - + this.addPage.root.addEventListener("click", this.addPage, false); + var pageHolder = document.createElement("div"); - pageHolder.id ="page-holder"; + pageHolder.id = "page-holder"; this.injectDOM.appendChild(pageHolder); - + // Build each page - for (var page of specification.pages) - { - var newPage = new this.pageNode(this,page); + for (var page of specification.pages) { + var newPage = new this.pageNode(this, page); pageHolder.appendChild(newPage.rootDOM); this.pages.push(newPage); } - + this.injectDOM.appendChild(this.addPage.root); } - - this.interfaceNode = function(parent,rootObject) - { + + this.interfaceNode = function (parent, rootObject) { this.type = "interfaceNode"; this.rootDOM; this.titleDOM; @@ -1523,25 +1490,23 @@ this.HTMLPoint; this.specification = rootObject; this.schema = specification.schema.getAllElementsByName("interface")[1]; - - this.createIOasAttr = function(name,specification,parent,type) { + + this.createIOasAttr = function (name, specification, parent, type) { this.root = document.createElement('div'); this.input = document.createElement("input"); this.name = name; this.type = type; this.parent = parent; this.specification = specification; - this.handleEvent = function(event) { - for (var i=0; i<this.specification.options.length; i++) - { - if (this.specification.options[i].name == this.name) - { + this.handleEvent = function (event) { + for (var i = 0; i < this.specification.options.length; i++) { + if (this.specification.options[i].name == this.name) { var options = this.specification.options; if (this.input.checked == false) { - if (i == options.length) - {options = options.slice(0,i);} - else { - options = options.slice(0,i).concat(options.slice(i+1)); + if (i == options.length) { + options = options.slice(0, i); + } else { + options = options.slice(0, i).concat(options.slice(i + 1)); } } else { return; @@ -1557,17 +1522,12 @@ }; this.specification.options.push(obj); } - if (this.parent.HTMLPoint.id == "setup") - { + if (this.parent.HTMLPoint.id == "setup") { // We've changed a global setting, must update all child 'interfaces' and disable them - for (pages of convert.pages) - { - for (interface of pages.interfaces) - { - if (this.type == "check") - { - for (node of interface.children[0].attributes) - { + for (pages of convert.pages) { + for (interface of pages.interfaces) { + if (this.type == "check") { + for (node of interface.children[0].attributes) { if (node.name == this.name) { if (this.input.checked) { node.input.disabled = true; @@ -1578,10 +1538,8 @@ break; } } - } else if (this.type == "show") - { - for (node of interface.children[1].attributes) - { + } else if (this.type == "show") { + for (node of interface.children[1].attributes) { if (node.name == this.name) { if (this.input.checked) { node.input.disabled = true; @@ -1596,30 +1554,29 @@ } } }; - this.findIndex = function(element,index,array){ + this.findIndex = function (element, index, array) { if (element.name == this.name) return true; else return false; }; - this.findNode = function(element,index,array){ + this.findNode = function (element, index, array) { if (element.name == this.name) return true; else return false; }; this.input.type = "checkbox"; - this.input.setAttribute("name",name); - this.input.addEventListener("change",this,false); + this.input.setAttribute("name", name); + this.input.addEventListener("change", this, false); this.root.appendChild(this.input); this.root.className = "attribute"; return this; } - - this.build = function(name,id,parent) - { - var obj = this.parent.createGeneralNodeDOM(name,id,parent); - + + this.build = function (name, id, parent) { + var obj = this.parent.createGeneralNodeDOM(name, id, parent); + this.rootDOM = obj.rootDOM; this.titleDOM = obj.titleDOM; this.attributeDOM = obj.attributeDOM; @@ -1634,7 +1591,7 @@ label: document.createElement("span"), input: document.createElement("input"), parent: this, - handleEvent: function(event) { + handleEvent: function (event) { this.parent.specification.title = event.currentTarget.value; } } @@ -1642,14 +1599,14 @@ this.titleNode.root.className = "node-children"; this.titleNode.root.appendChild(this.titleNode.label); this.titleNode.root.appendChild(this.titleNode.input); - this.titleNode.input.addEventListener("change",this.titleNode,false); + this.titleNode.input.addEventListener("change", this.titleNode, false); this.titleNode.input.value = this.specification.title; this.children.push(this.titleNode); this.childrenDOM.appendChild(this.titleNode.root); } - + // Put in the check / show options as individual children - var checks = this.parent.createGeneralNodeDOM("Checks","setup-interface-checks",this); + var checks = this.parent.createGeneralNodeDOM("Checks", "setup-interface-checks", this); var interfaceName = popupStateNodes.state[1].select.value; var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0]; @@ -1657,19 +1614,16 @@ var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0]; testXML = testXML.getAllElementsByTagName("checks"); var interfaceXMLChild = interfaceXML.firstElementChild; - while (interfaceXMLChild) - { - var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"),this.specification,this,"check"); - for (var option of this.specification.options) - { - if (option.name == obj.name) - { + while (interfaceXMLChild) { + var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "check"); + for (var option of this.specification.options) { + if (option.name == obj.name) { obj.input.checked = true; break; } } if (parent.id != "setup") { - var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode,obj); + var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj); if (node != undefined) { if (node.input.checked) { obj.input.checked = false; @@ -1687,26 +1641,23 @@ this.children.push(checks); this.childrenDOM.appendChild(checks.rootDOM); - var show = this.parent.createGeneralNodeDOM("Show","setup-interface-show",this); + var show = this.parent.createGeneralNodeDOM("Show", "setup-interface-show", this); interfaceName = popupStateNodes.state[1].select.value; checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0]; testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0]; interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0]; testXML = testXML.getAllElementsByTagName("show"); interfaceXMLChild = interfaceXML.firstElementChild; - while(interfaceXMLChild) - { - var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"),this.specification,this,"show"); - for (var option of this.specification.options) - { - if (option.name == obj.name) - { + while (interfaceXMLChild) { + var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "show"); + for (var option of this.specification.options) { + if (option.name == obj.name) { obj.input.checked = true; break; } } if (parent.id != "setup") { - var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode,obj); + var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj); if (node != undefined) { if (node.input.checked) { obj.input.checked = false; @@ -1723,25 +1674,21 @@ } this.children.push(show); this.childrenDOM.appendChild(show.rootDOM); - - if (parent.id == "setup") - { - } else { - var nameAttr = this.parent.convertAttributeToDOM(this,specification.schema.getAllElementsByName("name")[0]); + + if (parent.id == "setup") {} else { + var nameAttr = this.parent.convertAttributeToDOM(this, specification.schema.getAllElementsByName("name")[0]); this.attributeDOM.appendChild(nameAttr.holder); this.attributes.push(nameAttr); - var scales = new this.scalesNode(this,this.specification); + var scales = new this.scalesNode(this, this.specification); this.children.push(scales); this.childrenDOM.appendChild(scales.rootDOM); } - if (parent != undefined) - { + if (parent != undefined) { parent.appendChild(this.rootDOM); } } - - this.scalesNode = function(parent,rootObject) - { + + this.scalesNode = function (parent, rootObject) { this.type = "scalesNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -1769,24 +1716,23 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - + this.editButton = { button: document.createElement("button"), parent: this, - handleEvent: function(event) { + handleEvent: function (event) { popupObject.show(); popupObject.postNode(popupStateNodes.state[6]); - popupStateNodes.state[6].generate(this.parent.specification,this.parent); + popupStateNodes.state[6].generate(this.parent.specification, this.parent); } }; this.editButton.button.textContent = "Edit Scales/Markers"; - this.editButton.button.addEventListener("click",this.editButton,false); + this.editButton.button.addEventListener("click", this.editButton, false); this.buttonDOM.appendChild(this.editButton.button); } } - - this.surveyNode = function(parent,rootObject,location) - { + + this.surveyNode = function (parent, rootObject, location) { this.type = "surveyNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -1805,7 +1751,7 @@ this.titleDOM.className = "node-title"; this.titleDOM.textContent = "Survey"; titleDiv.appendChild(this.titleDOM); - + this.attributeDOM.className = "node-attributes"; var locationAttr = document.createElement("span"); this.attributeDOM.appendChild(locationAttr); @@ -1821,9 +1767,8 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - - this.surveyEntryNode = function(parent,rootObject) - { + + this.surveyEntryNode = function (parent, rootObject) { this.type = "surveyEntryNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -1852,27 +1797,25 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - - this.build = function() - { + + this.build = function () { this.attributeDOM.innerHTML = null; this.childrenDOM.innerHTML = null; var statementRoot = document.createElement("div"); var statement = document.createElement("span"); - statement.textContent = "Statement / Question: "+this.specification.statement; + statement.textContent = "Statement / Question: " + this.specification.statement; statementRoot.appendChild(statement); this.children.push(statementRoot); this.childrenDOM.appendChild(statementRoot); - switch(this.specification.type) - { + switch (this.specification.type) { case "statement": this.titleDOM.textContent = "Statement"; break; case "question": this.titleDOM.textContent = "Question"; - var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); - var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); - var boxsize = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("boxsize")[0]); + var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]); + var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]); + var boxsize = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("boxsize")[0]); this.attributeDOM.appendChild(id.holder); this.attributes.push(id); this.attributeDOM.appendChild(mandatory.holder); @@ -1882,10 +1825,10 @@ break; case "number": this.titleDOM.textContent = "Number"; - var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); - var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); - var min = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("min")[0]); - var max = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("max")[0]); + var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]); + var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]); + var min = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("min")[0]); + var max = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("max")[0]); this.attributeDOM.appendChild(id.holder); this.attributes.push(id); this.attributeDOM.appendChild(min.holder); @@ -1895,55 +1838,49 @@ break; case "checkbox": this.titleDOM.textContent = "Checkbox"; - var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); + var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]); this.attributeDOM.appendChild(id.holder); this.attributes.push(id); break; case "radio": this.titleDOM.textContent = "Radio"; - var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); + var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]); this.attributeDOM.appendChild(id.holder); this.attributes.push(id); break; } } this.build(); - + this.editNode = { root: document.createElement("button"), parent: this, - handleEvent: function() - { + handleEvent: function () { popupObject.show(); - popupStateNodes.state[5].generate(this.parent.specification,this.parent); + popupStateNodes.state[5].generate(this.parent.specification, this.parent); popupObject.postNode(popupStateNodes.state[5]); } } this.editNode.root.textContent = "Edit Entry"; - this.editNode.root.addEventListener("click",this.editNode,false); + this.editNode.root.addEventListener("click", this.editNode, false); this.buttonDOM.appendChild(this.editNode.root); - + this.deleteNode = { root: document.createElement("button"), parent: this, - handleEvent: function() - { + handleEvent: function () { var optionList = this.parent.parent.specification.options; var childList = this.parent.parent.children; - for (var i=0; i <this.parent.parent.specification.options.length; i++) - { + for (var i = 0; i < this.parent.parent.specification.options.length; i++) { var option = this.parent.parent.specification.options[i]; - if (option == this.parent.specification) - { + if (option == this.parent.specification) { this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM); - if (i == this.parent.parent.specification.options.length-1) - { - optionList = optionList.slice(0,i); - childList = childList.slice(0,i); - } - else { - optionList = optionList.slice(0,i).concat(optionList.slice(i+1)); - childList = childList.slice(0,i).concat(childList.slice(i+1)); + if (i == this.parent.parent.specification.options.length - 1) { + optionList = optionList.slice(0, i); + childList = childList.slice(0, i); + } else { + optionList = optionList.slice(0, i).concat(optionList.slice(i + 1)); + childList = childList.slice(0, i).concat(childList.slice(i + 1)); } this.parent.parent.specification.options = optionList; this.parent.parent.children = childList; @@ -1952,24 +1889,28 @@ } } this.deleteNode.root.textContent = "Delete Entry"; - this.deleteNode.root.addEventListener("click",this.deleteNode,false); + this.deleteNode.root.addEventListener("click", this.deleteNode, false); this.buttonDOM.appendChild(this.deleteNode.root); - - this.moveToPosition = function(new_index){ - new_index = Math.min(new_index,this.parent.children.length); - var curr_index = this.parent.children.findIndex(function(elem){ - if (elem == this) {return true;} else {return false;} - },this); + + this.moveToPosition = function (new_index) { + new_index = Math.min(new_index, this.parent.children.length); + var curr_index = this.parent.children.findIndex(function (elem) { + if (elem == this) { + return true; + } else { + return false; + } + }, this); // Split at the current location to remove the node and shift all the children up - var tail = this.parent.children.splice(curr_index+1); + var tail = this.parent.children.splice(curr_index + 1); this.parent.children.pop(); this.parent.children = this.parent.children.concat(tail); - + //Split at the new location and insert the node tail = this.parent.children.splice(new_index); this.parent.children.push(this); this.parent.children = this.parent.children.concat(tail); - + // Re-build the specification this.parent.specification.options = []; this.parent.childrenDOM.innerHTML = ""; @@ -1977,42 +1918,42 @@ this.parent.specification.options.push(obj.specification); this.parent.childrenDOM.appendChild(obj.rootDOM); } - this.parent.children.forEach(function(obj,index){ + this.parent.children.forEach(function (obj, index) { obj.moveButtons.disable(index); }); } - + this.moveButtons = { root_up: document.createElement("button"), root_down: document.createElement("button"), parent: this, - handleEvent: function(event) { + handleEvent: function (event) { var index = this.parent.parent.children.indexOf(this.parent); if (event.currentTarget.getAttribute("direction") == "up") { - index = Math.max(index-1,0); + index = Math.max(index - 1, 0); } else if (event.currentTarget.getAttribute("direction") == "down") { - index = Math.min(index+1,this.parent.parent.children.length-1); + index = Math.min(index + 1, this.parent.parent.children.length - 1); } this.parent.moveToPosition(index); this.disable(index); }, - disable: function(index) { + disable: function (index) { if (index == 0) { this.root_up.disabled = true; } else { this.root_up.disabled = false; } - if (index == this.parent.parent.children.length-1) { + if (index == this.parent.parent.children.length - 1) { this.root_down.disabled = true; } else { this.root_down.disabled = false; } } } - this.moveButtons.root_up.setAttribute("direction","up"); - this.moveButtons.root_down.setAttribute("direction","down"); - this.moveButtons.root_up.addEventListener("click",this.moveButtons,false); - this.moveButtons.root_down.addEventListener("click",this.moveButtons,false); + this.moveButtons.root_up.setAttribute("direction", "up"); + this.moveButtons.root_down.setAttribute("direction", "down"); + this.moveButtons.root_up.addEventListener("click", this.moveButtons, false); + this.moveButtons.root_down.addEventListener("click", this.moveButtons, false); this.moveButtons.root_up.textContent = "Move Up"; this.moveButtons.root_down.textContent = "Move Down"; this.buttonDOM.appendChild(this.moveButtons.root_up); @@ -2021,33 +1962,30 @@ this.addNode = { root: document.createElement("button"), parent: this, - handleEvent: function() - { + handleEvent: function () { var newNode = new this.parent.specification.OptionNode(this.parent.specification); this.parent.specification.options.push(newNode); popupObject.show(); - popupStateNodes.state[5].generate(newNode,this.parent); + popupStateNodes.state[5].generate(newNode, this.parent); popupObject.postNode(popupStateNodes.state[5]); } } this.addNode.root.textContent = "Add Survey Entry"; - this.addNode.root.addEventListener("click",this.addNode,false); + this.addNode.root.addEventListener("click", this.addNode, false); this.buttonDOM.appendChild(this.addNode.root); - - for (var option of this.specification.options) - { - var newNode = new this.surveyEntryNode(this,option); + + for (var option of this.specification.options) { + var newNode = new this.surveyEntryNode(this, option); this.children.push(newNode); this.childrenDOM.appendChild(newNode.rootDOM); } - - this.children.forEach(function(obj,index){ + + this.children.forEach(function (obj, index) { obj.moveButtons.disable(index); }); } - - this.pageNode = function(parent,rootObject) - { + + this.pageNode = function (parent, rootObject) { this.type = "pageNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -2066,7 +2004,7 @@ this.titleDOM.className = "node-title"; this.titleDOM.textContent = "Test Page"; titleDiv.appendChild(this.titleDOM); - + this.attributeDOM.className = "node-attributes"; this.childrenDOM.className = "node-children"; this.buttonDOM.className = "node-buttons"; @@ -2075,74 +2013,71 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - + // Do the comment prefix node - var cpn = this.parent.createGeneralNodeDOM("Comment Prefix",""+this.specification.id+"-commentprefix",this.parent); + var cpn = this.parent.createGeneralNodeDOM("Comment Prefix", "" + this.specification.id + "-commentprefix", this.parent); cpn.rootDOM.removeChild(cpn.attributeDOM); var obj = { root: document.createElement("div"), input: document.createElement("input"), parent: this, - handleEvent: function() - { + handleEvent: function () { this.parent.specification.commentBoxPrefix = event.currentTarget.value; } } cpn.children.push(obj); cpn.childrenDOM.appendChild(obj.root); obj.root.appendChild(obj.input); - obj.input.addEventListener("change",obj,false); + obj.input.addEventListener("change", obj, false); obj.input.value = this.specification.commentBoxPrefix; this.childrenDOM.appendChild(cpn.rootDOM); this.children.push(cpn); - + // Now both before and after surveys - if (this.specification.preTest == undefined){ + if (this.specification.preTest == undefined) { this.specification.preTest = new specification.surveyNode(specification); this.specification.preTest.location = "pre"; } - if (this.specification.postTest == undefined){ + if (this.specification.postTest == undefined) { this.specification.postTest = new specification.surveyNode(specification); this.specification.postTest.location = "post"; } - var surveyBefore = new this.parent.surveyNode(this,this.specification.preTest,"Pre"); - var surveyAfter = new this.parent.surveyNode(this,this.specification.postTest,"Post"); + var surveyBefore = new this.parent.surveyNode(this, this.specification.preTest, "Pre"); + var surveyAfter = new this.parent.surveyNode(this, this.specification.postTest, "Post"); this.children.push(surveyBefore); this.children.push(surveyAfter); this.childrenDOM.appendChild(surveyBefore.rootDOM); this.childrenDOM.appendChild(surveyAfter.rootDOM); - + // Build the attributes var attributeList = this.schema.getAllElementsByTagName("xs:attribute"); - for (var i=0; i<attributeList.length; i++) - { + for (var i = 0; i < attributeList.length; i++) { var attributeName = attributeList[i].getAttribute('name'); - var attrObject = this.parent.convertAttributeToDOM(rootObject,attributeList[i]); + var attrObject = this.parent.convertAttributeToDOM(rootObject, attributeList[i]); this.attributeDOM.appendChild(attrObject.holder); this.attributes.push(attrObject); } - + this.interfaces = []; - - this.getAudioElements = function() { + + this.getAudioElements = function () { var array = []; - for (var i=0; i<this.children.length; i++) { + for (var i = 0; i < this.children.length; i++) { if (this.children[i].type == "audioElementNode") { array[array.length] = this.children[i]; } } return array; } - - this.redrawChildren = function() { + + this.redrawChildren = function () { this.childrenDOM.innerHTML = ""; - for(var child of this.children) { + for (var child of this.children) { this.childrenDOM.appendChild(child.rootDOM); } } - - this.audioElementNode = function(parent,rootObject) - { + + this.audioElementNode = function (parent, rootObject) { this.type = "audioElementNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -2170,48 +2105,46 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - + // Build the attributes var attributeList = this.schema.getAllElementsByTagName("xs:attribute"); - for (var i=0; i<attributeList.length; i++) - { + for (var i = 0; i < attributeList.length; i++) { var attributeName = attributeList[i].getAttribute('name'); - var attrObject = this.parent.parent.convertAttributeToDOM(rootObject,attributeList[i]); + var attrObject = this.parent.parent.convertAttributeToDOM(rootObject, attributeList[i]); this.attributeDOM.appendChild(attrObject.holder); this.attributes.push(attrObject); } - + this.deleteNode = { root: document.createElement("button"), parent: this, - handleEvent: function() - { - var i = this.parent.parent.specification.audioElements.findIndex(this.findNode,this); + handleEvent: function () { + var i = this.parent.parent.specification.audioElements.findIndex(this.findNode, this); if (i >= 0) { var aeList = this.parent.parent.specification.audioElements; - if (i < aeList.length-1) { - aeList = aeList.slice(0,i).concat(aeList.slice(i+1)); + if (i < aeList.length - 1) { + aeList = aeList.slice(0, i).concat(aeList.slice(i + 1)); } else { - aeList = aeList.slice(0,i); + aeList = aeList.slice(0, i); } } - i = this.parent.parent.children.findIndex(function(element,index,array){ + i = this.parent.parent.children.findIndex(function (element, index, array) { if (element == this.parent) return true; else return false; - },this); + }, this); if (i >= 0) { var childList = this.parent.children; - if (i < aeList.length-1) { - childList = childList.slice(0,i).concat(childList.slice(i+1)); + if (i < aeList.length - 1) { + childList = childList.slice(0, i).concat(childList.slice(i + 1)); } else { - childList = childList.slice(0,i); + childList = childList.slice(0, i); } this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM); } }, - findNode: function(element,index,array){ + findNode: function (element, index, array) { if (element == this.parent.specification) return true; else @@ -2219,88 +2152,91 @@ } } this.deleteNode.root.textContent = "Delete Entry"; - this.deleteNode.root.addEventListener("click",this.deleteNode,false); + this.deleteNode.root.addEventListener("click", this.deleteNode, false); this.buttonDOM.appendChild(this.deleteNode.root); - + this.moveButtons = { root_up: document.createElement("button"), root_down: document.createElement("button"), parent: this, - handleEvent: function(event) { + handleEvent: function (event) { var index = this.parent.parent.getAudioElements().indexOf(this.parent); if (event.currentTarget.getAttribute("direction") == "up") { - index = Math.max(index-1,0); + index = Math.max(index - 1, 0); } else if (event.currentTarget.getAttribute("direction") == "down") { - index = Math.min(index+1,this.parent.parent.getAudioElements().length-1); + index = Math.min(index + 1, this.parent.parent.getAudioElements().length - 1); } this.parent.moveToPosition(index); this.disable(index); }, - disable: function(index) { + disable: function (index) { if (index == 0) { this.root_up.disabled = true; } else { this.root_up.disabled = false; } - if (index == this.parent.parent.getAudioElements().length-1) { + if (index == this.parent.parent.getAudioElements().length - 1) { this.root_down.disabled = true; } else { this.root_down.disabled = false; } } } - this.moveButtons.root_up.setAttribute("direction","up"); - this.moveButtons.root_down.setAttribute("direction","down"); - this.moveButtons.root_up.addEventListener("click",this.moveButtons,false); - this.moveButtons.root_down.addEventListener("click",this.moveButtons,false); + this.moveButtons.root_up.setAttribute("direction", "up"); + this.moveButtons.root_down.setAttribute("direction", "down"); + this.moveButtons.root_up.addEventListener("click", this.moveButtons, false); + this.moveButtons.root_down.addEventListener("click", this.moveButtons, false); this.moveButtons.root_up.textContent = "Move Up"; this.moveButtons.root_down.textContent = "Move Down"; this.buttonDOM.appendChild(this.moveButtons.root_up); this.buttonDOM.appendChild(this.moveButtons.root_down); - - this.moveToPosition = function(new_index) { - + + this.moveToPosition = function (new_index) { + // Get the zero-th Object var zero_object = this.parent.getAudioElements()[0]; var parent_children_root_index = this.parent.children.indexOf(zero_object); // splice out the array for processing var process_array = this.parent.children.splice(parent_children_root_index); - - + + new_index = Math.min(new_index, process_array.length); - var curr_index = process_array.findIndex(function(elem){ - if (elem == this) {return true;} else {return false;} - },this); - + var curr_index = process_array.findIndex(function (elem) { + if (elem == this) { + return true; + } else { + return false; + } + }, this); + // Split at the current location to remove the node and shift all the children up - var tail = process_array.splice(curr_index+1); + var tail = process_array.splice(curr_index + 1); process_array.pop(); process_array = process_array.concat(tail); - + //Split at the new location and insert the node tail = process_array.splice(new_index); process_array.push(this); process_array = process_array.concat(tail); - + // Re-attach to the parent.children this.parent.children = this.parent.children.concat(process_array); - + // Re-build the specification this.parent.specification.audioElements = []; for (var obj of process_array) { this.parent.specification.audioElements.push(obj.specification); } this.parent.redrawChildren(); - - process_array.forEach(function(obj,index){ + + process_array.forEach(function (obj, index) { obj.moveButtons.disable(index); }); - + } } - - this.commentQuestionNode = function(parent,rootObject) - { + + this.commentQuestionNode = function (parent, rootObject) { this.type = "commentQuestionNode"; this.rootDOM = document.createElement("div"); this.titleDOM = document.createElement("span"); @@ -2328,61 +2264,59 @@ this.rootDOM.appendChild(this.attributeDOM); this.rootDOM.appendChild(this.childrenDOM); this.rootDOM.appendChild(this.buttonDOM); - + } - + // Build the components if (this.specification.interfaces.length == 0) { this.specification.interfaces.push(new specification.interfaceNode(specification)); } - for (var interfaceObj of this.specification.interfaces) - { - var newInterface = new this.parent.interfaceNode(this.parent,interfaceObj); - newInterface.build("Interface",""+this.specification.id+"-interface",this.childrenDOM); + for (var interfaceObj of this.specification.interfaces) { + var newInterface = new this.parent.interfaceNode(this.parent, interfaceObj); + newInterface.build("Interface", "" + this.specification.id + "-interface", this.childrenDOM); this.children.push(newInterface); this.interfaces.push(newInterface); } - - for (var elements of this.specification.audioElements) - { - var audioElementDOM = new this.audioElementNode(this,elements); + + for (var elements of this.specification.audioElements) { + var audioElementDOM = new this.audioElementNode(this, elements); this.children.push(audioElementDOM); this.childrenDOM.appendChild(audioElementDOM.rootDOM); } - - this.getAudioElements().forEach(function(elem){ + + this.getAudioElements().forEach(function (elem) { elem.moveButtons.disable(); }); - + this.addInterface = { root: document.createElement("button"), parent: this, - handleEvent: function() { + handleEvent: function () { var InterfaceObj = new specification.interfaceNode(specification); - var newInterface = new this.parent.parent.interfaceNode(this.parent.parent,InterfaceObj); - newInterface.build("Interface",""+this.parent.specification.id+"-interface",this.parent.childrenDOM); + var newInterface = new this.parent.parent.interfaceNode(this.parent.parent, InterfaceObj); + newInterface.build("Interface", "" + this.parent.specification.id + "-interface", this.parent.childrenDOM); this.parent.children.push(newInterface); this.parent.specification.interfaces.push(InterfaceObj); this.parent.interfaces.push(newInterface); } } this.addInterface.root.textContent = "Add Interface"; - this.addInterface.root.addEventListener("click",this.addInterface,false); + this.addInterface.root.addEventListener("click", this.addInterface, false); this.buttonDOM.appendChild(this.addInterface.root); - + this.addAudioElement = { root: document.createElement("button"), parent: this, - handleEvent: function() { + handleEvent: function () { var audioElementObject = new this.parent.specification.audioElementNode(specification); - var audioElementDOM = new this.parent.audioElementNode(this.parent,audioElementObject); + var audioElementDOM = new this.parent.audioElementNode(this.parent, audioElementObject); this.parent.specification.audioElements.push(audioElementObject); this.parent.children.push(audioElementDOM); this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM); } } this.addAudioElement.root.textContent = "Add Audio Element"; - this.addAudioElement.root.addEventListener("click",this.addAudioElement,false); + this.addAudioElement.root.addEventListener("click", this.addAudioElement, false); this.buttonDOM.appendChild(this.addAudioElement.root); } -} \ No newline at end of file +}