# HG changeset patch # User Nicholas Jillings # Date 1479125688 0 # Node ID cc2364d8bc171bb494638b55f82058102f0338f3 # Parent bc5c449c97e192fc8955b59f98f22c14cca46b8d# Parent fddfb7c0b4fa790d05bbae35e92f1c8ccc6f480d Merge branch 'vnext' into Dev_main diff -r bc5c449c97e1 -r cc2364d8bc17 test_create/test_core.js --- a/test_create/test_core.js Thu Nov 10 16:48:08 2016 +0000 +++ b/test_create/test_core.js Mon Nov 14 12:14:48 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 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 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 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= 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); } @@ -1173,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 @@ -1182,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; @@ -1224,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'); @@ -1249,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; @@ -1278,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; @@ -1305,34 +1230,32 @@ } } else { this.input = document.createElement("select"); - for (var i=0; i= 0) { - this.parent.parent.children.splice(index,1); - } - index = this.parent.parent.specification.conditions.findIndex(function(element){ - if (this == element) {return true;} return false; - },this.parent.specification); - if (index >= 0) { - this.parent.parent.specification.conditions.splice(index); - } - } - } - this.deleteNode.root.textContent = "Delete"; - this.deleteNode.root.addEventListener("click",this.deleteNode); - - this.buttonDOM.appendChild(this.deleteNode.root); - } - - this.addConditional = { - root: document.createElement("button"), - parent: this, - handleEvent: function(event) { - var spec = { - check: null, - value: null, - jumpToOnPass: null, - jumpToOnFail: null - }; - this.parent.specification.conditions.push(spec); - var condition = new Conditional(this.parent,spec); - this.parent.children.push(condition); - this.parent.childrenDOM.appendChild(condition.rootDOM); - } - } - this.addConditional.root.addEventListener("click",this.addConditional); - this.addConditional.root.textContent = "Add Condition"; - this.buttonDOM.appendChild(this.addConditional.root); - 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 = 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 @@ -2400,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"); @@ -2509,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 +}