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; 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(); nickjillings@1370: xmlHttp.open("GET","./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(); nickjillings@1370: xsdGet.open("GET","../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(); nickjillings@1370: jsonAttribute.open("GET","./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"); nickjillings@1370: this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].children; 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"); 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.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"); 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:"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) { nickjillings@2158: if (schema.children[0].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= 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); 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]; 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 = "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: 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: }