nickjillings@1370: var interfaceSpecs; nickjillings@1370: var xmlHttp; nickjillings@1370: var popupObject; nickjillings@1370: var popupStateNodes; nickjillings@1370: var specification; nickjillings@1370: var convert; nickjillings@1370: var attributeText; nicholas@2355: var page_lang = "en"; nickjillings@1370: nickjillings@1370: // Firefox does not have an XMLDocument.prototype.getElementsByName nickjillings@1370: // and there is no searchAll style command, this custom function will nickjillings@1370: // search all children recusrively for the name. Used for XSD where all nickjillings@1370: // element nodes must have a name and therefore can pull the schema node nickjillings@1370: XMLDocument.prototype.getAllElementsByName = function(name) nickjillings@1370: { nickjillings@1370: name = String(name); nickjillings@1370: var selected = this.documentElement.getAllElementsByName(name); nickjillings@1370: return selected; nickjillings@1370: } nickjillings@1370: nickjillings@1370: Element.prototype.getAllElementsByName = function(name) nickjillings@1370: { nickjillings@1370: name = String(name); nickjillings@1370: var selected = []; nickjillings@1370: var node = this.firstElementChild; nickjillings@1370: while(node != null) nickjillings@1370: { nickjillings@1370: if (node.getAttribute('name') == name) nickjillings@1370: { nickjillings@1370: selected.push(node); nickjillings@1370: } nickjillings@1370: if (node.childElementCount > 0) nickjillings@1370: { nickjillings@1370: selected = selected.concat(node.getAllElementsByName(name)); nickjillings@1370: } nickjillings@1370: node = node.nextElementSibling; nickjillings@1370: } nickjillings@1370: return selected; nickjillings@1370: } nickjillings@1370: nickjillings@1370: XMLDocument.prototype.getAllElementsByTagName = function(name) nickjillings@1370: { nickjillings@1370: name = String(name); nickjillings@1370: var selected = this.documentElement.getAllElementsByTagName(name); nickjillings@1370: return selected; nickjillings@1370: } nickjillings@1370: nickjillings@1370: Element.prototype.getAllElementsByTagName = function(name) nickjillings@1370: { nickjillings@1370: name = String(name); nickjillings@1370: var selected = []; nickjillings@1370: var node = this.firstElementChild; nickjillings@1370: while(node != null) nickjillings@1370: { nickjillings@1370: if (node.nodeName == name) nickjillings@1370: { nickjillings@1370: selected.push(node); nickjillings@1370: } nickjillings@1370: if (node.childElementCount > 0) nickjillings@1370: { nickjillings@1370: selected = selected.concat(node.getAllElementsByTagName(name)); nickjillings@1370: } nickjillings@1370: node = node.nextElementSibling; nickjillings@1370: } nickjillings@1370: return selected; nickjillings@1370: } nickjillings@1370: nickjillings@1370: // Firefox does not have an XMLDocument.prototype.getElementsByName nickjillings@1370: if (typeof XMLDocument.prototype.getElementsByName != "function") { nickjillings@1370: XMLDocument.prototype.getElementsByName = function(name) nickjillings@1370: { nickjillings@1370: name = String(name); nickjillings@1370: var node = this.documentElement.firstElementChild; nickjillings@1370: var selected = []; nickjillings@1370: while(node != null) nickjillings@1370: { nickjillings@1370: if (node.getAttribute('name') == name) nickjillings@1370: { nickjillings@1370: selected.push(node); nickjillings@1370: } nickjillings@1370: node = node.nextElementSibling; nickjillings@1370: } nickjillings@1370: return selected; nickjillings@1370: } nickjillings@1370: } nickjillings@1370: nickjillings@1370: window.onload = function() nickjillings@1370: { nickjillings@1370: specification = new Specification(); nickjillings@1370: convert = new SpecificationToHTML(); nickjillings@1370: xmlHttp = new XMLHttpRequest(); nicholas@2224: xmlHttp.open("GET","test_create/interface-specs.xml",true); nickjillings@1370: xmlHttp.onload = function() nickjillings@1370: { nickjillings@1370: var parse = new DOMParser(); nickjillings@1370: interfaceSpecs = parse.parseFromString(xmlHttp.response,'text/xml'); nickjillings@1370: buildPage(); nickjillings@1370: popupObject.postNode(popupStateNodes.state[0]) nickjillings@1370: } nickjillings@1370: xmlHttp.send(); nickjillings@1370: nickjillings@1370: var xsdGet = new XMLHttpRequest(); nicholas@2224: xsdGet.open("GET","xml/test-schema.xsd",true); nickjillings@1370: xsdGet.onload = function() nickjillings@1370: { nickjillings@1370: var parse = new DOMParser(); nickjillings@1370: specification.schema = parse.parseFromString(xsdGet.response,'text/xml');; nickjillings@1370: } nickjillings@1370: xsdGet.send(); nickjillings@1370: nickjillings@1370: var jsonAttribute = new XMLHttpRequest(); nicholas@2224: jsonAttribute.open("GET","test_create/attributes.json",true); nickjillings@1370: jsonAttribute.onload = function() nickjillings@1370: { nickjillings@1370: attributeText = JSON.parse(jsonAttribute.response) nickjillings@1370: } nickjillings@1370: jsonAttribute.send(); nickjillings@1370: } nickjillings@1370: nickjillings@1370: function buildPage() nickjillings@1370: { nickjillings@1370: popupObject = new function() { nickjillings@1370: this.object = document.getElementById("popupHolder"); nickjillings@1370: this.blanket = document.getElementById("blanket"); nickjillings@1370: nickjillings@1370: this.popupTitle = document.createElement("div"); nickjillings@1370: this.popupTitle.id = "popup-title-holder"; nickjillings@1370: this.popupTitle.align = "center"; nickjillings@1370: this.titleDOM = document.createElement("span"); nickjillings@1370: this.titleDOM.id = "popup-title"; nickjillings@1370: this.popupTitle.appendChild(this.titleDOM); nickjillings@1370: this.object.appendChild(this.popupTitle); nickjillings@1370: nickjillings@1370: this.popupContent = document.createElement("div"); nickjillings@1370: this.popupContent.id = "popup-content"; nickjillings@1370: this.object.appendChild(this.popupContent); nickjillings@1370: nickjillings@1370: this.proceedButton = document.createElement("button"); nickjillings@1370: this.proceedButton.id = "popup-proceed"; nickjillings@2108: this.proceedButton.className = "popup-button"; nickjillings@1370: this.proceedButton.textContent = "Next"; nickjillings@1370: this.proceedButton.onclick = function() nickjillings@1370: { nickjillings@1370: popupObject.popupContent.innerHTML = null; nickjillings@2110: if(typeof popupObject.shownObject.continue == "function") { nickjillings@2110: popupObject.shownObject.continue(); nickjillings@2110: } else { nickjillings@2110: popupObject.hide(); nickjillings@2110: } nickjillings@1370: }; nickjillings@1370: this.object.appendChild(this.proceedButton); nickjillings@1370: nickjillings@2108: this.backButton = document.createElement("button"); nickjillings@2108: this.backButton.id = "popup-back"; nickjillings@2108: this.backButton.className = "popup-button"; nickjillings@2108: this.backButton.textContent = "Back"; nickjillings@2108: this.backButton.onclick = function() nickjillings@2108: { nickjillings@2108: popupObject.popupContent.innerHTML = null; nickjillings@2108: popupObject.shownObject.back(); nickjillings@2108: }; nickjillings@2108: this.object.appendChild(this.backButton); nickjillings@2108: nickjillings@1370: this.shownObject; nickjillings@1370: nickjillings@1370: this.resize = function() nickjillings@1370: { nickjillings@1370: var w = window.innerWidth; nickjillings@1370: var h = window.innerHeight; nickjillings@1370: this.object.style.left = Math.floor((w-750)/2) + 'px'; nickjillings@1370: this.object.style.top = Math.floor((h-500)/2) + 'px'; nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.show = function() nickjillings@1370: { nickjillings@1370: this.object.style.visibility = "visible"; nickjillings@1370: this.blanket.style.visibility = "visible"; nickjillings@2108: if (typeof this.shownObject.back == "function") { nickjillings@2108: this.backButton.style.visibility = "visible"; nickjillings@2108: } else { nickjillings@2108: this.backButton.style.visibility = "hidden"; nickjillings@2108: } nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.hide = function() nickjillings@1370: { nickjillings@1370: this.object.style.visibility = "hidden"; nickjillings@1370: this.blanket.style.visibility = "hidden"; nickjillings@2108: this.backButton.style.visibility = "hidden"; nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.postNode = function(postObject) nickjillings@1370: { nickjillings@1370: //Passed object must have the following: nickjillings@1370: // Title: text to show in the title nickjillings@1370: // Content: HTML DOM to show on the page nickjillings@1370: // On complete this HTML DOM is destroyed so make sure it is referenced elsewhere for processing nickjillings@1370: this.titleDOM.textContent = postObject.title; nickjillings@1370: this.popupContent.appendChild(postObject.content); nickjillings@1370: this.shownObject = postObject; nickjillings@2108: if (typeof this.shownObject.back == "function") { nickjillings@2108: this.backButton.style.visibility = "visible"; nickjillings@2108: } else { nickjillings@2108: this.backButton.style.visibility = "hidden"; nickjillings@2108: } nickjillings@2110: if (typeof this.shownObject.continue == "function") { nickjillings@2110: this.proceedButton.textContent = "Next"; nickjillings@2110: } else { nickjillings@2110: this.proceedButton.textContent = "Finish"; nickjillings@2110: } nickjillings@2108: this.show(); nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.resize(); nickjillings@1370: this.hide(); nickjillings@1370: }; nickjillings@1370: nickjillings@1370: popupStateNodes = new function() nickjillings@1370: { nickjillings@1370: // This defines the several popup states wanted nickjillings@1370: this.state = []; nickjillings@1370: this.state[0] = new function() nickjillings@1370: { nickjillings@1370: this.title = "Welcome"; nickjillings@1370: this.content = document.createElement("div"); nickjillings@1370: this.content.id = "state-0"; nickjillings@1370: var span = document.createElement("span"); nickjillings@1370: span.textContent = "Welcome to the WAET test creator tool. This will allow you to create a new test from scratch to suit your testing needs. If you wish to update a test file, please drag and drop the XML document into the area below for processing, otherwise press 'Next' to start a new test. This tool generates files for the WAET 1.2.0 version." nickjillings@1370: this.content.appendChild(span); nickjillings@1370: this.dragArea = document.createElement("div"); nickjillings@1373: this.dragArea.className = "drag-area"; nickjillings@1373: this.dragArea.id = "project-drop"; nickjillings@1370: this.content.appendChild(this.dragArea); nickjillings@1373: nickjillings@1374: this.dragArea.addEventListener('dragover',function(e){ nickjillings@1373: e.stopPropagation(); nickjillings@1373: e.preventDefault(); nickjillings@1373: e.dataTransfer.dropEffect = 'copy'; nickjillings@1373: e.currentTarget.className = "drag-area drag-over"; nickjillings@1373: }); nickjillings@1373: nickjillings@1373: this.dragArea.addEventListener('dragexit',function(e){ nickjillings@1373: e.stopPropagation(); nickjillings@1373: e.preventDefault(); nickjillings@1373: e.dataTransfer.dropEffect = 'copy'; nickjillings@1373: e.currentTarget.className = "drag-area"; nickjillings@1373: }); nickjillings@1373: nickjillings@1373: this.dragArea.addEventListener('drop',function(e){ nickjillings@1373: e.stopPropagation(); nickjillings@1373: e.preventDefault(); nickjillings@1373: e.currentTarget.className = "drag-area drag-dropped"; nickjillings@1373: var files = e.dataTransfer.files[0]; nickjillings@1374: var reader = new FileReader(); nickjillings@1374: reader.onload = function(decoded) { nickjillings@1374: var parse = new DOMParser(); nickjillings@1374: specification.decode(parse.parseFromString(decoded.target.result,'text/xml')); nickjillings@1374: popupObject.hide(); nickjillings@1375: popupObject.popupContent.innerHTML = null; nickjillings@1374: convert.convert(document.getElementById('content')); nickjillings@1374: } nickjillings@1374: reader.readAsText(files); nickjillings@1373: }); nickjillings@1373: nickjillings@1370: nickjillings@1370: this.continue = function() nickjillings@1370: { nickjillings@1370: popupObject.postNode(popupStateNodes.state[1]); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.state[1] = new function() nickjillings@1370: { nickjillings@1370: this.title = "Select your interface"; nickjillings@1370: this.content = document.createElement("div"); nickjillings@1370: this.content.id = "state-1"; nickjillings@1370: var spnH = document.createElement('div'); nickjillings@1370: var span = document.createElement("span"); nickjillings@1370: span.textContent = "Please select your interface from the list shown below. This will define the various options which are available. This can later be changed."; nickjillings@1370: spnH.appendChild(span); nickjillings@1370: this.content.appendChild(spnH); nickjillings@1370: this.select = document.createElement("select"); nicholas@2355: this.content.appendChild(this.select); nicholas@2355: this.description = document.createElement("p"); nicholas@2355: this.content.appendChild(this.description); nicholas@2390: this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].getElementsByTagName('test'); nickjillings@1370: for (var i=0; i 0) nickjillings@1370: { nickjillings@1370: testNode = this.testXML[0].getAllElementsByName(checkName); nickjillings@1370: if(testNode.length != 0) {testNode = testNode[0];} nickjillings@1370: else {testNode = undefined;} nickjillings@1370: } else { nickjillings@1370: testNode = undefined; nickjillings@1370: } nickjillings@2108: var obj = { nickjillings@2108: root: document.createElement("div"), nickjillings@2109: text: document.createElement("label"), nickjillings@2108: input: document.createElement("input"), nickjillings@2108: parent: this, nickjillings@2108: name: checkName, nickjillings@2108: handleEvent: function(event) { nickjillings@2108: if (this.input.checked) { nickjillings@2108: // Add to specification.interfaces.option nickjillings@2108: var included = specification.interfaces.options.find(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (included == null) { nickjillings@2108: specification.interfaces.options.push({type:"check",name:this.name}); nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: // Remove from specification.interfaces.option nickjillings@2108: var position = specification.interfaces.options.findIndex(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (position >= 0) { nickjillings@2108: specification.interfaces.options.splice(position,1); nickjillings@2108: } nickjillings@2108: } nickjillings@2108: } nickjillings@1370: } nickjillings@2108: nickjillings@2108: obj.input.addEventListener("click",obj); nickjillings@2108: obj.root.className = "popup-checkbox"; nickjillings@2108: obj.input.type = "checkbox"; nickjillings@2109: obj.input.setAttribute('id',checkName); nickjillings@2109: obj.text.setAttribute("for",checkName); nickjillings@2108: obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; nickjillings@2108: obj.root.appendChild(obj.input); nickjillings@2108: obj.root.appendChild(obj.text); nickjillings@1370: if(testNode != undefined) nickjillings@1370: { nickjillings@2108: if (testNode.getAttribute('default') == 'on') nickjillings@1370: { nickjillings@2108: obj.input.checked = true; nickjillings@1370: } nickjillings@1370: if (testNode.getAttribute('support') == "none") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: }else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: if (interfaceNode.getAttribute('default') == 'on') nickjillings@2108: { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: if (interfaceNode.getAttribute('support') == "none") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: } nickjillings@1370: } nickjillings@2108: var included = specification.interfaces.options.find(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },obj); nickjillings@2108: if (included != undefined) { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: obj.handleEvent(); nickjillings@2108: this.options.push(obj); nickjillings@2108: this.dynamicContent.appendChild(obj.root); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.continue = function() nickjillings@1370: { nickjillings@1370: popupStateNodes.state[3].generate(); nickjillings@1370: popupObject.postNode(popupStateNodes.state[3]); nickjillings@1370: } nickjillings@2108: this.back = function() { nickjillings@2108: popupObject.postNode(popupStateNodes.state[1]); nickjillings@2108: } nickjillings@1370: } nickjillings@1370: this.state[3] = new function() nickjillings@1370: { nickjillings@1370: this.title = "Test Metrics"; nickjillings@1370: this.content = document.createElement("div"); nickjillings@1370: this.content.id = "state-1"; nickjillings@1370: var spnH = document.createElement('div'); nickjillings@1370: var span = document.createElement("span"); nickjillings@1370: span.textContent = "Select which data points to include in the exported results XML. Some of this is required for certain post script analysis. See the documentation for further details"; nickjillings@1370: spnH.appendChild(span); nickjillings@1370: this.content.appendChild(spnH); nickjillings@1370: this.options = []; nickjillings@1370: this.checkText; nickjillings@1370: this.testXML; nickjillings@1370: this.interfaceXML; nickjillings@2108: this.dynamicContent = document.createElement("div"); nickjillings@2108: this.content.appendChild(this.dynamicContent); nickjillings@1370: this.generate = function() nickjillings@1370: { nickjillings@2108: this.options = []; nickjillings@2108: this.dynamicContent.innerHTML = null; nickjillings@1370: var interfaceName = popupStateNodes.state[1].select.value; nickjillings@1370: this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0]; nickjillings@1370: this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0]; nickjillings@1370: this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0]; nickjillings@1370: this.testXML = this.testXML.getAllElementsByTagName("metrics"); nicholas@2390: var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry'); nicholas@2390: for (var i=0; i 0) nickjillings@1370: { nickjillings@1370: testNode = this.testXML[0].getAllElementsByName(checkName); nickjillings@1370: if(testNode.length != 0) {testNode = testNode[0];} nickjillings@1370: else {testNode = undefined;} nickjillings@1370: } else { nickjillings@1370: testNode = undefined; nickjillings@1370: } nickjillings@2108: var obj = { nickjillings@2108: root: document.createElement("div"), nickjillings@2109: text: document.createElement("label"), nickjillings@2108: input: document.createElement("input"), nickjillings@2108: parent: this, nickjillings@2108: name: checkName, nickjillings@2108: handleEvent: function(event) { nickjillings@2108: if (this.input.checked) { nickjillings@2108: // Add to specification.interfaces.option nickjillings@2108: var included = specification.metrics.enabled.find(function(element,index,array){ nickjillings@2108: if (element == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (included == null) { nickjillings@2108: specification.metrics.enabled.push(this.name); nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: // Remove from specification.interfaces.option nickjillings@2108: var position = specification.metrics.enabled.findIndex(function(element,index,array){ nickjillings@2108: if (element == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (position >= 0) { nickjillings@2108: specification.metrics.enabled.splice(position,1); nickjillings@2108: } nickjillings@2108: } nickjillings@2108: } nickjillings@1370: } nickjillings@2108: nickjillings@2108: obj.input.addEventListener("click",obj); nickjillings@2108: obj.root.className = "popup-checkbox"; nickjillings@2108: obj.input.type = "checkbox"; nickjillings@2109: obj.input.setAttribute('id',checkName); nickjillings@2109: obj.text.setAttribute("for",checkName); nickjillings@2108: obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; nickjillings@2108: obj.root.appendChild(obj.input); nickjillings@2108: obj.root.appendChild(obj.text); nickjillings@1370: if(testNode != undefined) nickjillings@1370: { nickjillings@2108: if (testNode.getAttribute('default') == 'on') nickjillings@1370: { nickjillings@2108: obj.input.checked = true; nickjillings@1370: } nickjillings@1370: if (testNode.getAttribute('support') == "none") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: }else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: if (interfaceNode.getAttribute('default') == 'on') nickjillings@2108: { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: if (interfaceNode.getAttribute('support') == "none") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: } nickjillings@1370: } nickjillings@2108: var included = specification.metrics.enabled.find(function(element,index,array){ nickjillings@2108: if (element == this.name) {return true;} else {return false;} nickjillings@2108: },obj); nickjillings@2108: obj.handleEvent(); nickjillings@2108: if (included != undefined) { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: this.options.push(obj); nickjillings@2108: this.dynamicContent.appendChild(obj.root); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.continue = function() nickjillings@1370: { nickjillings@1370: popupStateNodes.state[4].generate(); nickjillings@1370: popupObject.postNode(popupStateNodes.state[4]); nickjillings@1370: } nickjillings@2108: this.back = function() { nickjillings@2108: popupObject.postNode(popupStateNodes.state[2]); nickjillings@2108: } nickjillings@1370: } nickjillings@1370: this.state[4] = new function() nickjillings@1370: { nickjillings@1370: this.title = "Test Visuals"; nickjillings@1370: this.content = document.createElement("div"); nickjillings@1370: this.content.id = "state-1"; nickjillings@1370: var spnH = document.createElement('div'); nickjillings@1370: var span = document.createElement("span"); nickjillings@1370: span.textContent = "You can display extra visual content with your interface for the test user to interact with. Select from the available options below. Greyed out options are unavailable for your selected interface"; nickjillings@1370: spnH.appendChild(span); nickjillings@1370: this.content.appendChild(spnH); nickjillings@1370: this.options = []; nickjillings@1370: this.checkText; nickjillings@1370: this.testXML; nickjillings@1370: this.interfaceXML; nickjillings@2108: this.dynamicContent = document.createElement("div"); nickjillings@2108: this.content.appendChild(this.dynamicContent); nickjillings@1370: this.generate = function() nickjillings@1370: { nickjillings@2108: this.options = []; nickjillings@2108: this.dynamicContent.innerHTML = null; nickjillings@1370: var interfaceName = popupStateNodes.state[1].select.value; nickjillings@1370: this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0]; nickjillings@1370: this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0]; nickjillings@1370: this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0]; nickjillings@2108: this.testXML = this.testXML.getAllElementsByTagName("show"); nicholas@2390: var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry'); nicholas@2390: for (var i=0; i 0) nickjillings@1370: { nickjillings@1370: testNode = this.testXML[0].getAllElementsByName(checkName); nickjillings@1370: if(testNode.length != 0) {testNode = testNode[0];} nickjillings@1370: else {testNode = undefined;} nickjillings@1370: } else { nickjillings@1370: testNode = undefined; nickjillings@1370: } nickjillings@2108: var obj = { nickjillings@2108: root: document.createElement("div"), nickjillings@2109: text: document.createElement("label"), nickjillings@2108: input: document.createElement("input"), nickjillings@2108: parent: this, nickjillings@2108: name: checkName, nickjillings@2108: handleEvent: function(event) { nickjillings@2108: if (this.input.checked) { nickjillings@2108: // Add to specification.interfaces.option nickjillings@2108: var included = specification.interfaces.options.find(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (included == null) { nickjillings@2108: specification.interfaces.options.push({type:"show",name:this.name}); nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: // Remove from specification.interfaces.option nickjillings@2108: var position = specification.interfaces.options.findIndex(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },this); nickjillings@2108: if (position >= 0) { nickjillings@2108: specification.interfaces.options.splice(position,1); nickjillings@2108: } nickjillings@2108: } nickjillings@2108: } nickjillings@1370: } nickjillings@2108: nickjillings@2108: obj.input.addEventListener("click",obj); nickjillings@2108: obj.root.className = "popup-checkbox"; nickjillings@2108: obj.input.type = "checkbox"; nickjillings@2109: obj.input.setAttribute('id',checkName); nickjillings@2109: obj.text.setAttribute("for",checkName); nickjillings@2108: obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent; nickjillings@2108: obj.root.appendChild(obj.input); nickjillings@2108: obj.root.appendChild(obj.text); nickjillings@1370: if(testNode != undefined) nickjillings@1370: { nickjillings@2108: if (testNode.getAttribute('default') == 'on') nickjillings@1370: { nickjillings@2108: obj.input.checked = true; nickjillings@1370: } nickjillings@1370: if (testNode.getAttribute('support') == "none") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: }else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@1370: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } nickjillings@2108: } else { nickjillings@2108: if (interfaceNode.getAttribute('default') == 'on') nickjillings@2108: { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: if (interfaceNode.getAttribute('support') == "none") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = false; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@2108: } else if (interfaceNode.getAttribute('support') == "mandatory") nickjillings@2108: { nickjillings@2108: obj.input.disabled = true; nickjillings@2108: obj.input.checked = true; nickjillings@2108: obj.root.className = "popup-checkbox disabled"; nickjillings@1370: } nickjillings@1370: } nickjillings@2108: var included = specification.interfaces.options.find(function(element,index,array){ nickjillings@2108: if (element.name == this.name) {return true;} else {return false;} nickjillings@2108: },obj); nickjillings@2108: if (included != undefined) { nickjillings@2108: obj.input.checked = true; nickjillings@2108: } nickjillings@2108: obj.handleEvent(); nickjillings@2108: this.options.push(obj); nickjillings@2108: this.dynamicContent.appendChild(obj.root); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.continue = function() nickjillings@1370: { nickjillings@1370: popupObject.hide(); nickjillings@1370: convert.convert(document.getElementById('content')); nickjillings@1370: } nickjillings@2108: this.back = function() { nickjillings@2108: popupObject.postNode(popupStateNodes.state[3]); nickjillings@2108: } nickjillings@1370: } nickjillings@1370: this.state[5] = new function() { nickjillings@1370: this.title = "Add/Edit Survey Element"; nickjillings@1370: this.content = document.createElement("div"); nickjillings@1370: this.content.id = "state-1"; nickjillings@1370: var spnH = document.createElement('div'); nickjillings@1370: var span = document.createElement("span"); nickjillings@1370: span.textContent = "You can configure your survey element here. Press 'Continue' to complete your changes."; nickjillings@1370: spnH.appendChild(span); nickjillings@1370: this.content.appendChild(spnH); nickjillings@1370: this.dynamic = document.createElement("div"); nickjillings@1370: this.option = null; nickjillings@1370: this.parent = null; nickjillings@1375: this.optionLists = []; nickjillings@2158: this.select = document.createElement("select"); nickjillings@2158: this.select.setAttribute("name","type"); nickjillings@2158: this.select.addEventListener("change",this,false); nickjillings@2158: this.content.appendChild(this.select); nickjillings@1370: this.content.appendChild(this.dynamic); nickjillings@1370: this.generate = function(option, parent) nickjillings@1370: { nickjillings@1370: this.option = option; nickjillings@1370: this.parent = parent; nickjillings@2158: if (this.select.childElementCount == 0) { nickjillings@2158: var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("type")[0].getAllElementsByTagName("xs:enumeration"); nickjillings@2158: for (var i=0; i= 0) { nickjillings@2115: this.parent.parent.scaleRoot.scales.splice(index,1); nickjillings@2115: } nickjillings@2115: document.getElementById("popup-option-holder").removeChild(this.parent.root); nickjillings@2115: } nickjillings@2115: } nickjillings@2115: this.deleteMarker.root.addEventListener("click",this.deleteMarker); nickjillings@2115: this.deleteMarker.root.textContent = "Delete Marker" nickjillings@2115: this.root.appendChild(this.deleteMarker.root); nickjillings@2115: } nickjillings@1385: } nickjillings@1370: } nickjillings@1370: } nickjillings@1370: nickjillings@1370: function SpecificationToHTML() nickjillings@1370: { nickjillings@1370: // This takes the specification node and converts it to an on-page HTML object nickjillings@1370: // Each Specification Node is given its own JS object which listens to the XSD for instant verification nickjillings@1370: // Once generated, it directly binds into the specification object to update with changes nickjillings@1370: // Fixed DOM entries nickjillings@1370: this.injectDOM; nickjillings@1370: this.setupDOM; nickjillings@1370: this.pages = []; nickjillings@1370: nickjillings@1370: // Self-contained generators nickjillings@1370: this.createGeneralNodeDOM = function(name,id,parent) nickjillings@1370: { nickjillings@1375: this.type = name; nickjillings@1370: var root = document.createElement('div'); nickjillings@1370: root.id = id; nickjillings@1370: root.className = "node"; nickjillings@1370: nickjillings@1370: var titleDiv = document.createElement('div'); nickjillings@1370: titleDiv.className = "node-title"; nickjillings@1370: var title = document.createElement('span'); nickjillings@1370: title.className = "node-title"; nickjillings@1370: title.textContent = name; nickjillings@1370: titleDiv.appendChild(title); nickjillings@1370: nickjillings@1370: var attributeDiv = document.createElement('div'); nickjillings@1370: attributeDiv.className = "node-attributes"; nickjillings@1370: nickjillings@1370: var childrenDiv = document.createElement('div'); nickjillings@1370: childrenDiv.className = "node-children"; nickjillings@1370: nickjillings@1370: var buttonsDiv = document.createElement('div'); nickjillings@1370: buttonsDiv.className = "node-buttons"; nickjillings@1370: nickjillings@1370: root.appendChild(titleDiv); nickjillings@1370: root.appendChild(attributeDiv); nickjillings@1370: root.appendChild(childrenDiv); nickjillings@1370: root.appendChild(buttonsDiv); nickjillings@1370: nickjillings@1370: var obj = { nickjillings@1370: rootDOM: root, nickjillings@1370: titleDOM: title, nickjillings@1370: attributeDOM: attributeDiv, nickjillings@1370: attributes: [], nickjillings@1370: childrenDOM: childrenDiv, nickjillings@1370: children: [], nickjillings@1370: buttonDOM: buttonsDiv, nickjillings@1370: parent: parent nickjillings@1370: } nickjillings@1370: return obj; nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.convertAttributeToDOM = function(node,schema) nickjillings@1370: { nickjillings@1370: // This takes an attribute schema node and returns an object with the input node and any bindings nickjillings@1370: if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) nickjillings@1370: { nickjillings@1370: schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; nickjillings@1370: } nickjillings@1370: var obj = new function() nickjillings@1370: { nickjillings@1370: this.input; nickjillings@1370: this.name; nickjillings@1370: this.owner; nickjillings@1370: this.holder; nickjillings@1370: nickjillings@1370: this.name = schema.getAttribute('name'); nickjillings@1370: this.default = schema.getAttribute('default'); nickjillings@1370: this.dataType = schema.getAttribute('type'); nickjillings@2158: if (this.dataType == undefined) { nickjillings@2158: if (schema.childElementCount > 0) { nicholas@2390: if (schema.firstElementChild.nodeName == "xs:simpleType") { nickjillings@2158: this.dataType = schema.getAllElementsByTagName("xs:restriction")[0].getAttribute("base"); nickjillings@2158: } nickjillings@2158: } nickjillings@2158: } nickjillings@1370: if (typeof this.dataType == "string") { this.dataType = this.dataType.substr(3);} nickjillings@1370: else {this.dataType = "string";} nickjillings@1370: var minVar = undefined; nickjillings@1370: var maxVar = undefined; nickjillings@1370: switch(this.dataType) nickjillings@1370: { nickjillings@1370: case "negativeInteger": nickjillings@1370: maxVar = -1; nickjillings@1370: break; nickjillings@1370: case "positiveInteger": nickjillings@1370: minVar = 1; nickjillings@1370: break; nickjillings@1370: case "nonNegativeInteger": nickjillings@1370: minVar = 0; nickjillings@1370: break; nickjillings@1370: case "nonPositiveInteger": nickjillings@1370: maxVar = 0; nickjillings@1370: break; nickjillings@1370: case "byte": nickjillings@1370: minVar = 0; nickjillings@1370: maxVar = 256; nickjillings@1370: break; nickjillings@1370: case "short": nickjillings@1370: minVar = 0; nickjillings@1370: maxVar = 65536; nickjillings@1370: break; nickjillings@1370: default: nickjillings@1370: break; nickjillings@1370: } nickjillings@2174: nickjillings@2174: this.enumeration = schema.getAllElementsByTagName("xs:enumeration"); nickjillings@2174: if (this.enumeration.length == 0) { nickjillings@2174: this.input = document.createElement('input'); nickjillings@2174: switch(this.dataType) nickjillings@2174: { nickjillings@2174: case "boolean": nickjillings@2174: this.input.type = "checkbox"; nickjillings@2174: break; nickjillings@2174: case "negativeInteger": nickjillings@2174: case "positiveInteger": nickjillings@2174: case "nonNegativeInteger": nickjillings@2174: case "nonPositiveInteger": nickjillings@2174: case "integer": nickjillings@2174: case "short": nickjillings@2174: case "byte": nickjillings@2174: this.input.step = 1; nickjillings@2174: case "decimal": nickjillings@2174: this.input.type = "number"; nickjillings@2174: this.input.min = minVar; nickjillings@2174: this.input.max = maxVar; nickjillings@2174: break; nickjillings@2174: default: nickjillings@2174: break; nickjillings@2174: } nickjillings@2174: } else { nickjillings@2174: this.input = document.createElement("select"); nickjillings@2174: for (var i=0; i node: nicholas@2243: this.titleNode = { nicholas@2243: root: document.createElement("div"), nicholas@2243: label: document.createElement("span"), nicholas@2243: input: document.createElement("input"), nicholas@2243: parent: this, nicholas@2243: handleEvent: function(event) { nicholas@2243: this.parent.specification.title = event.currentTarget.value; nicholas@2243: } nicholas@2243: } nicholas@2243: this.titleNode.label.textContent = "Axis Title:"; nicholas@2243: this.titleNode.root.className = "node-children"; nicholas@2243: this.titleNode.root.appendChild(this.titleNode.label); nicholas@2243: this.titleNode.root.appendChild(this.titleNode.input); nicholas@2243: this.titleNode.input.addEventListener("change",this.titleNode,false); nicholas@2243: this.titleNode.input.value = this.specification.title; nicholas@2243: this.children.push(this.titleNode); nicholas@2243: this.childrenDOM.appendChild(this.titleNode.root); nicholas@2243: } nicholas@2243: nickjillings@1370: // Put in the check / show options as individual children nickjillings@1370: var checks = this.parent.createGeneralNodeDOM("Checks","setup-interface-checks",this); nickjillings@1370: nickjillings@1370: var interfaceName = popupStateNodes.state[1].select.value; nickjillings@1370: var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0]; nickjillings@1370: var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0]; nickjillings@1370: var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0]; nickjillings@1370: testXML = testXML.getAllElementsByTagName("checks"); nicholas@2390: var interfaceXMLChild = interfaceXML.firstElementChild; nicholas@2390: while (interfaceXMLChild) nickjillings@1370: { nicholas@2390: var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"),this.specification,this,"check"); nickjillings@1370: for (var option of this.specification.options) nickjillings@1370: { nickjillings@1370: if (option.name == obj.name) nickjillings@1370: { nickjillings@1370: obj.input.checked = true; nickjillings@1370: break; nickjillings@1370: } nickjillings@1370: } nickjillings@1370: if (parent.id != "setup") { nickjillings@1370: var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode,obj); nickjillings@1381: if (node != undefined) { nickjillings@1381: if (node.input.checked) { nickjillings@1381: obj.input.checked = false; nickjillings@1381: obj.input.disabled = true; nickjillings@1381: } nickjillings@1370: } nickjillings@1370: } nickjillings@1370: var text = document.createElement('span'); nicholas@2390: text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent; nickjillings@1370: obj.root.appendChild(text); nickjillings@1370: checks.attributeDOM.appendChild(obj.root); nickjillings@1370: checks.attributes.push(obj); nicholas@2390: interfaceXMLChild = interfaceXMLChild.nextElementSibling; nickjillings@1370: } nickjillings@1370: this.children.push(checks); nickjillings@1370: this.childrenDOM.appendChild(checks.rootDOM); nickjillings@1370: nickjillings@1370: var show = this.parent.createGeneralNodeDOM("Show","setup-interface-show",this); nickjillings@1370: interfaceName = popupStateNodes.state[1].select.value; nickjillings@1370: checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0]; nickjillings@1370: testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0]; nickjillings@1370: interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0]; nickjillings@1370: testXML = testXML.getAllElementsByTagName("show"); nicholas@2390: interfaceXMLChild = interfaceXML.firstElementChild; nicholas@2390: while(interfaceXMLChild) nickjillings@1370: { nicholas@2390: var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"),this.specification,this,"show"); nickjillings@1370: for (var option of this.specification.options) nickjillings@1370: { nickjillings@1370: if (option.name == obj.name) nickjillings@1370: { nickjillings@1370: obj.input.checked = true; nickjillings@1370: break; nickjillings@1370: } nickjillings@1370: } nickjillings@1370: if (parent.id != "setup") { nickjillings@1370: var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode,obj); nickjillings@1381: if (node != undefined) { nickjillings@1381: if (node.input.checked) { nickjillings@1381: obj.input.checked = false; nickjillings@1381: obj.input.disabled = true; nickjillings@1381: } nickjillings@1370: } nickjillings@1370: } nickjillings@1370: var text = document.createElement('span'); nicholas@2390: text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent; nickjillings@1370: obj.root.appendChild(text); nickjillings@1370: show.attributeDOM.appendChild(obj.root); nickjillings@1370: show.attributes.push(obj); nicholas@2390: interfaceXMLChild = interfaceXMLChild.nextElementSibling; nickjillings@1370: } nickjillings@1370: this.children.push(show); nickjillings@1370: this.childrenDOM.appendChild(show.rootDOM); nickjillings@1370: nickjillings@1370: if (parent.id == "setup") nickjillings@1370: { nickjillings@1370: } else { nickjillings@1370: var nameAttr = this.parent.convertAttributeToDOM(this,specification.schema.getAllElementsByName("name")[0]); nickjillings@1370: this.attributeDOM.appendChild(nameAttr.holder); nickjillings@1370: this.attributes.push(nameAttr); nickjillings@1385: var scales = new this.scalesNode(this,this.specification); nickjillings@1385: this.children.push(scales); nickjillings@1385: this.childrenDOM.appendChild(scales.rootDOM); nickjillings@1370: } nickjillings@1370: if (parent != undefined) nickjillings@1370: { nickjillings@1370: parent.appendChild(this.rootDOM); nickjillings@1370: } nickjillings@1370: } nickjillings@1385: nickjillings@1385: this.scalesNode = function(parent,rootObject) nickjillings@1385: { nickjillings@1385: this.type = "scalesNode"; nickjillings@1385: this.rootDOM = document.createElement("div"); nickjillings@1385: this.titleDOM = document.createElement("span"); nickjillings@1385: this.attributeDOM = document.createElement("div"); nickjillings@1385: this.attributes = []; nickjillings@1385: this.childrenDOM = document.createElement("div"); nickjillings@1385: this.children = []; nickjillings@1385: this.buttonDOM = document.createElement("div"); nickjillings@1385: this.parent = parent; nickjillings@1385: this.specification = rootObject; nickjillings@1385: this.schema = specification.schema.getAllElementsByName("page")[0]; nickjillings@1385: this.rootDOM.className = "node"; nickjillings@1385: nickjillings@1385: var titleDiv = document.createElement('div'); nickjillings@1385: titleDiv.className = "node-title"; nickjillings@1385: this.titleDOM.className = "node-title"; nickjillings@1385: this.titleDOM.textContent = "Interface Scales"; nickjillings@1385: titleDiv.appendChild(this.titleDOM); nickjillings@1385: nickjillings@1385: this.attributeDOM.className = "node-attributes"; nickjillings@1385: this.childrenDOM.className = "node-children"; nickjillings@1385: this.buttonDOM.className = "node-buttons"; nickjillings@1385: nickjillings@1385: this.rootDOM.appendChild(titleDiv); nickjillings@1385: this.rootDOM.appendChild(this.attributeDOM); nickjillings@1385: this.rootDOM.appendChild(this.childrenDOM); nickjillings@1385: this.rootDOM.appendChild(this.buttonDOM); nickjillings@1385: nickjillings@1385: this.editButton = { nickjillings@1385: button: document.createElement("button"), nickjillings@1385: parent: this, nickjillings@1385: handleEvent: function(event) { nickjillings@1385: popupObject.show(); nickjillings@1385: popupObject.postNode(popupStateNodes.state[6]); nickjillings@1385: popupStateNodes.state[6].generate(this.parent.specification,this.parent); nickjillings@1385: } nickjillings@1385: }; nickjillings@1385: this.editButton.button.textContent = "Edit Scales/Markers"; nickjillings@1385: this.editButton.button.addEventListener("click",this.editButton,false); nickjillings@1385: this.buttonDOM.appendChild(this.editButton.button); nickjillings@1385: } nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.surveyNode = function(parent,rootObject,location) nickjillings@1370: { nickjillings@1375: this.type = "surveyNode"; nickjillings@1370: this.rootDOM = document.createElement("div"); nickjillings@1370: this.titleDOM = document.createElement("span"); nickjillings@1370: this.attributeDOM = document.createElement("div"); nickjillings@1370: this.attributes = []; nickjillings@1370: this.childrenDOM = document.createElement("div"); nickjillings@1370: this.children = []; nickjillings@1370: this.buttonDOM = document.createElement("div"); nickjillings@1370: this.parent = parent; nickjillings@1370: this.specification = rootObject; nickjillings@1370: this.schema = specification.schema.getAllElementsByName("survey")[1]; nickjillings@1370: this.rootDOM.className = "node"; nickjillings@1370: nickjillings@1370: var titleDiv = document.createElement('div'); nickjillings@1370: titleDiv.className = "node-title"; nickjillings@1370: this.titleDOM.className = "node-title"; nickjillings@1370: this.titleDOM.textContent = "Survey"; nickjillings@1370: titleDiv.appendChild(this.titleDOM); nickjillings@1370: nickjillings@1370: this.attributeDOM.className = "node-attributes"; nickjillings@1370: var locationAttr = document.createElement("span"); nickjillings@1370: this.attributeDOM.appendChild(locationAttr); nickjillings@1370: if (location == "Pre" || location == "pre") { nickjillings@1370: locationAttr.textContent = "Location: Before"; nickjillings@1370: } else { nickjillings@1370: locationAttr.textContent = "Location: After"; nickjillings@1370: } nickjillings@1370: this.childrenDOM.className = "node-children"; nickjillings@1370: this.buttonDOM.className = "node-buttons"; nickjillings@1370: nickjillings@1370: this.rootDOM.appendChild(titleDiv); nickjillings@1370: this.rootDOM.appendChild(this.attributeDOM); nickjillings@1370: this.rootDOM.appendChild(this.childrenDOM); nickjillings@1370: this.rootDOM.appendChild(this.buttonDOM); nickjillings@1370: nickjillings@1370: this.surveyEntryNode = function(parent,rootObject) nickjillings@1370: { nickjillings@1375: this.type = "surveyEntryNode"; nickjillings@1370: this.rootDOM = document.createElement("div"); nickjillings@1370: this.titleDOM = document.createElement("span"); nickjillings@1370: this.attributeDOM = document.createElement("div"); nickjillings@1370: this.attributes = []; nickjillings@1370: this.childrenDOM = document.createElement("div"); nickjillings@1370: this.children = []; nickjillings@1370: this.buttonDOM = document.createElement("div"); nickjillings@1370: this.parent = parent; nickjillings@1370: this.specification = rootObject; nickjillings@1370: this.schema = specification.schema.getAllElementsByName("surveyentry")[1]; nickjillings@1370: nickjillings@1370: this.rootDOM.className = "node"; nickjillings@1370: this.rootDOM.style.minWidth = "50%"; nickjillings@1370: nickjillings@1370: var titleDiv = document.createElement('div'); nickjillings@1370: titleDiv.className = "node-title"; nickjillings@1370: this.titleDOM.className = "node-title"; nickjillings@1370: titleDiv.appendChild(this.titleDOM); nickjillings@1370: nickjillings@1370: this.attributeDOM.className = "node-attributes"; nickjillings@1370: this.childrenDOM.className = "node-children"; nickjillings@1370: this.buttonDOM.className = "node-buttons"; nickjillings@1370: nickjillings@1370: this.rootDOM.appendChild(titleDiv); nickjillings@1370: this.rootDOM.appendChild(this.attributeDOM); nickjillings@1370: this.rootDOM.appendChild(this.childrenDOM); nickjillings@1370: this.rootDOM.appendChild(this.buttonDOM); nickjillings@1370: nickjillings@1375: this.build = function() nickjillings@1375: { nickjillings@1375: this.attributeDOM.innerHTML = null; nickjillings@1375: this.childrenDOM.innerHTML = null; nickjillings@1375: var statementRoot = document.createElement("div"); nickjillings@1375: var statement = document.createElement("span"); nickjillings@1375: statement.textContent = "Statement / Question: "+this.specification.statement; nickjillings@1375: statementRoot.appendChild(statement); nickjillings@1375: this.children.push(statementRoot); nickjillings@1375: this.childrenDOM.appendChild(statementRoot); nickjillings@1375: switch(this.specification.type) nickjillings@1375: { nickjillings@1375: case "statement": nickjillings@1375: this.titleDOM.textContent = "Statement"; nickjillings@1375: break; nickjillings@1375: case "question": nickjillings@1375: this.titleDOM.textContent = "Question"; nickjillings@1375: var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); nickjillings@1375: var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); nickjillings@1375: var boxsize = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("boxsize")[0]); nickjillings@1375: this.attributeDOM.appendChild(id.holder); nickjillings@1375: this.attributes.push(id); nickjillings@1375: this.attributeDOM.appendChild(mandatory.holder); nickjillings@1375: this.attributes.push(mandatory); nickjillings@1375: this.attributeDOM.appendChild(boxsize.holder); nickjillings@1375: this.attributes.push(boxsize); nickjillings@1375: break; nickjillings@1375: case "number": nickjillings@1375: this.titleDOM.textContent = "Number"; nickjillings@1375: var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); nickjillings@1375: var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); nickjillings@1375: var min = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("min")[0]); nickjillings@1375: var max = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("max")[0]); nickjillings@1375: this.attributeDOM.appendChild(id.holder); nickjillings@1375: this.attributes.push(id); nickjillings@1375: this.attributeDOM.appendChild(min.holder); nickjillings@1375: this.attributes.push(min); nickjillings@1375: this.attributeDOM.appendChild(max.holder); nickjillings@1375: this.attributes.push(max); nickjillings@1375: break; nickjillings@1375: case "checkbox": nickjillings@1375: this.titleDOM.textContent = "Checkbox"; nickjillings@1375: var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); nickjillings@1375: this.attributeDOM.appendChild(id.holder); nickjillings@1375: this.attributes.push(id); nickjillings@1375: break; nickjillings@1375: case "radio": nickjillings@1375: this.titleDOM.textContent = "Radio"; nickjillings@1375: var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); nickjillings@1375: this.attributeDOM.appendChild(id.holder); nickjillings@1375: this.attributes.push(id); nickjillings@1375: break; nickjillings@1375: } nickjillings@1370: } nickjillings@1375: this.build(); nickjillings@1370: nickjillings@1370: this.editNode = { nickjillings@1370: root: document.createElement("button"), nickjillings@1370: parent: this, nickjillings@1370: handleEvent: function() nickjillings@1370: { nickjillings@1370: popupObject.show(); nickjillings@1375: popupStateNodes.state[5].generate(this.parent.specification,this.parent); nickjillings@1370: popupObject.postNode(popupStateNodes.state[5]); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.editNode.root.textContent = "Edit Entry"; nickjillings@1370: this.editNode.root.addEventListener("click",this.editNode,false); nickjillings@1370: this.buttonDOM.appendChild(this.editNode.root); nickjillings@1370: nickjillings@1370: this.deleteNode = { nickjillings@1370: root: document.createElement("button"), nickjillings@1370: parent: this, nickjillings@1370: handleEvent: function() nickjillings@1370: { nickjillings@1370: var optionList = this.parent.parent.specification.options; nickjillings@1370: var childList = this.parent.parent.children; nickjillings@1370: for (var i=0; i = 0) { nickjillings@1370: var aeList = this.parent.parent.specification.audioElements; nickjillings@1370: if (i < aeList.length-1) { nickjillings@1370: aeList = aeList.slice(0,i).concat(aeList.slice(i+1)); nickjillings@1370: } else { nickjillings@1370: aeList = aeList.slice(0,i); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: i = this.parent.parent.children.findIndex(function(element,index,array){ nickjillings@1370: if (element == this.parent) nickjillings@1370: return true; nickjillings@1370: else nickjillings@1370: return false; nickjillings@1370: },this); nickjillings@1370: if (i >= 0) { nickjillings@1370: var childList = this.parent.children; nickjillings@1370: if (i < aeList.length-1) { nickjillings@1370: childList = childList.slice(0,i).concat(childList.slice(i+1)); nickjillings@1370: } else { nickjillings@1370: childList = childList.slice(0,i); nickjillings@1370: } nickjillings@1370: this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM); nickjillings@1370: } nickjillings@1370: }, nickjillings@1370: findNode: function(element,index,array){ nickjillings@1370: if (element == this.parent.specification) nickjillings@1370: return true; nickjillings@1370: else nickjillings@1370: return false; nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.deleteNode.root.textContent = "Delete Entry"; nickjillings@1370: this.deleteNode.root.addEventListener("click",this.deleteNode,false); nickjillings@1370: this.buttonDOM.appendChild(this.deleteNode.root); n@2421: n@2421: this.moveButtons = { n@2421: root_up: document.createElement("button"), n@2421: root_down: document.createElement("button"), n@2421: parent: this, n@2421: handleEvent: function(event) { n@2421: var index = this.parent.parent.getAudioElements().indexOf(this.parent); n@2421: if (event.currentTarget.getAttribute("direction") == "up") { n@2421: index = Math.max(index-1,0); n@2421: } else if (event.currentTarget.getAttribute("direction") == "down") { n@2421: index = Math.min(index+1,this.parent.parent.getAudioElements().length-1); n@2421: } n@2421: this.parent.moveToPosition(index); n@2421: this.disable(index); n@2421: }, n@2421: disable: function(index) { n@2421: if (index == 0) { n@2421: this.root_up.disabled = true; n@2421: } else { n@2421: this.root_up.disabled = false; n@2421: } n@2421: if (index == this.parent.parent.getAudioElements().length-1) { n@2421: this.root_down.disabled = true; n@2421: } else { n@2421: this.root_down.disabled = false; n@2421: } n@2421: } n@2421: } n@2421: this.moveButtons.root_up.setAttribute("direction","up"); n@2421: this.moveButtons.root_down.setAttribute("direction","down"); n@2421: this.moveButtons.root_up.addEventListener("click",this.moveButtons,false); n@2421: this.moveButtons.root_down.addEventListener("click",this.moveButtons,false); n@2421: this.moveButtons.root_up.textContent = "Move Up"; n@2421: this.moveButtons.root_down.textContent = "Move Down"; n@2421: this.buttonDOM.appendChild(this.moveButtons.root_up); n@2421: this.buttonDOM.appendChild(this.moveButtons.root_down); n@2421: n@2421: this.moveToPosition = function(new_index) { n@2421: n@2421: // Get the zero-th Object n@2421: var zero_object = this.parent.getAudioElements()[0]; n@2421: var parent_children_root_index = this.parent.children.indexOf(zero_object); n@2421: // splice out the array for processing n@2421: var process_array = this.parent.children.splice(parent_children_root_index); n@2421: n@2421: n@2421: new_index = Math.min(new_index, process_array.length); n@2421: var curr_index = process_array.findIndex(function(elem){ n@2421: if (elem == this) {return true;} else {return false;} n@2421: },this); n@2421: n@2421: // Split at the current location to remove the node and shift all the children up n@2421: var tail = process_array.splice(curr_index+1); n@2421: process_array.pop(); n@2421: process_array = process_array.concat(tail); n@2421: n@2421: //Split at the new location and insert the node n@2421: tail = process_array.splice(new_index); n@2421: process_array.push(this); n@2421: process_array = process_array.concat(tail); n@2421: n@2421: // Re-attach to the parent.children n@2421: this.parent.children = this.parent.children.concat(process_array); n@2421: n@2421: // Re-build the specification n@2421: this.parent.specification.audioElements = []; n@2421: for (var obj of process_array) { n@2421: this.parent.specification.audioElements.push(obj.specification); n@2421: } n@2421: this.parent.redrawChildren(); n@2421: n@2421: process_array.forEach(function(obj,index){ n@2421: obj.moveButtons.disable(index); n@2421: }); n@2421: n@2421: } nickjillings@1370: } nickjillings@1370: nickjillings@1370: this.commentQuestionNode = function(parent,rootObject) nickjillings@1370: { nickjillings@1375: this.type = "commentQuestionNode"; nickjillings@1370: this.rootDOM = document.createElement("div"); nickjillings@1370: this.titleDOM = document.createElement("span"); nickjillings@1370: this.attributeDOM = document.createElement("div"); nickjillings@1370: this.attributes = []; nickjillings@1370: this.childrenDOM = document.createElement("div"); nickjillings@1370: this.children = []; nickjillings@1370: this.buttonDOM = document.createElement("div"); nickjillings@1370: this.parent = parent; nickjillings@1370: this.specification = rootObject; nickjillings@1370: this.schema = specification.schema.getAllElementsByName("page")[0]; n@2421: this.rootDOM.className = "node audio-element"; nickjillings@1370: nickjillings@1370: var titleDiv = document.createElement('div'); nickjillings@1370: titleDiv.className = "node-title"; nickjillings@1370: this.titleDOM.className = "node-title"; nickjillings@1370: this.titleDOM.textContent = "Test Page"; nickjillings@1370: titleDiv.appendChild(this.titleDOM); nickjillings@1370: nickjillings@1370: this.attributeDOM.className = "node-attributes"; nickjillings@1370: this.childrenDOM.className = "node-children"; nickjillings@1370: this.buttonDOM.className = "node-buttons"; nickjillings@1370: nickjillings@1370: this.rootDOM.appendChild(titleDiv); nickjillings@1370: this.rootDOM.appendChild(this.attributeDOM); nickjillings@1370: this.rootDOM.appendChild(this.childrenDOM); nickjillings@1370: this.rootDOM.appendChild(this.buttonDOM); nickjillings@1370: nickjillings@1370: } nickjillings@1370: nickjillings@1374: // Build the components nickjillings@1310: if (this.specification.interfaces.length == 0) { nickjillings@2194: this.specification.interfaces.push(new specification.interfaceNode(specification)); nickjillings@1310: } nickjillings@1381: for (var interfaceObj of this.specification.interfaces) nickjillings@1381: { nickjillings@1381: var newInterface = new this.parent.interfaceNode(this.parent,interfaceObj); nickjillings@1381: newInterface.build("Interface",""+this.specification.id+"-interface",this.childrenDOM); nickjillings@1381: this.children.push(newInterface); nickjillings@1381: this.interfaces.push(newInterface); nickjillings@1381: } nickjillings@1381: nickjillings@1374: for (var elements of this.specification.audioElements) nickjillings@1374: { nickjillings@1374: var audioElementDOM = new this.audioElementNode(this,elements); nickjillings@1374: this.children.push(audioElementDOM); nickjillings@1374: this.childrenDOM.appendChild(audioElementDOM.rootDOM); nickjillings@1374: } nickjillings@1374: n@2421: this.getAudioElements().forEach(function(elem){ n@2421: elem.moveButtons.disable(); n@2421: }); n@2421: nickjillings@1370: this.addInterface = { nickjillings@1370: root: document.createElement("button"), nickjillings@1370: parent: this, nickjillings@1370: handleEvent: function() { nickjillings@2194: var InterfaceObj = new specification.interfaceNode(specification); nickjillings@1370: var newInterface = new this.parent.parent.interfaceNode(this.parent.parent,InterfaceObj); nickjillings@1370: newInterface.build("Interface",""+this.parent.specification.id+"-interface",this.parent.childrenDOM); nickjillings@1370: this.parent.children.push(newInterface); nickjillings@1370: this.parent.specification.interfaces.push(InterfaceObj); nickjillings@1370: this.parent.interfaces.push(newInterface); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.addInterface.root.textContent = "Add Interface"; nickjillings@1370: this.addInterface.root.addEventListener("click",this.addInterface,false); nickjillings@1370: this.buttonDOM.appendChild(this.addInterface.root); nickjillings@1370: nickjillings@1370: this.addAudioElement = { nickjillings@1370: root: document.createElement("button"), nickjillings@1370: parent: this, nickjillings@1370: handleEvent: function() { nickjillings@2194: var audioElementObject = new this.parent.specification.audioElementNode(specification); nickjillings@1370: var audioElementDOM = new this.parent.audioElementNode(this.parent,audioElementObject); nickjillings@1370: this.parent.specification.audioElements.push(audioElementObject); nickjillings@1370: this.parent.children.push(audioElementDOM); nickjillings@1370: this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM); nickjillings@1370: } nickjillings@1370: } nickjillings@1370: this.addAudioElement.root.textContent = "Add Audio Element"; nickjillings@1370: this.addAudioElement.root.addEventListener("click",this.addAudioElement,false); nickjillings@1370: this.buttonDOM.appendChild(this.addAudioElement.root); nickjillings@1370: } nickjillings@1370: }