# HG changeset patch # User Nicholas Jillings # Date 1449254044 0 # Node ID 5ec4279bf8465136fab6b4c3fdcb7e3cabd418b5 # Parent fe049caed3aeac3ced36a0800eccd58344537391 test_create: Specification Node handles complete XML to DOM and DOM to XML conversions diff -r fe049caed3ae -r 5ec4279bf846 test_create/test_create.html --- a/test_create/test_create.html Fri Dec 04 10:38:13 2015 +0000 +++ b/test_create/test_create.html Fri Dec 04 18:34:04 2015 +0000 @@ -104,6 +104,38 @@ dnd.style.width = "100%"; dnd.style.height = "50px"; dnd.className = "dragndrop"; + dnd.ondragover = function(e) { + e.stopPropagation(); + e.preventDefault(); + }; + dnd.ondragenter = function(e) { + e.stopPropagation(); + e.preventDefault(); + this.style.backgroundColor = '#AAFFAA'; + }; + dnd.ondragleave = function(e) { + e.stopPropagation(); + e.preventDefault(); + this.style.backgroundColor = "#FFFFFF"; + }; + dnd.ondrop = function(e) { + e.stopPropagation(); + e.preventDefault(); + + var file = e.dataTransfer.files[0]; + + // Uses HTML5 FileAPI - https://w3c.github.io/FileAPI/#filereader-interface + var reader = new FileReader(); + reader.onload = function() { + var parse = new DOMParser(); + var xml = parse.parseFromString(reader.result,'text/xml'); + specificationNode.decode(xml); + popupInstance.hidePopup(); + SpecificationToHTML(); + }; + reader.readAsText(file); + + }; this.popupBody.appendChild(text); this.popupBody.appendChild(dnd); this.showPopup(); @@ -1511,7 +1543,7 @@ case 8: this.hidePopup(); this.state = 0; - SpecficationToHTML(); + SpecificationToHTML (); } this.state++; }; @@ -1592,7 +1624,7 @@ this.audioHolders = []; this.metrics = []; - this.decode = function() { + this.decode = function(projectXML) { // projectXML - DOM Parsed document this.projectXML = projectXML.childNodes[0]; var setupNode = projectXML.getElementsByTagName('setup')[0]; @@ -1614,8 +1646,19 @@ } var metricCollection = setupNode.getElementsByTagName('Metric'); - this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); - this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); + var setupPreTestNode = setupNode.getElementsByTagName('PreTest'); + if (setupPreTestNode.length != 0) + { + setupPreTestNode = setupPreTestNode[0]; + this.preTest.construct(setupPreTestNode); + } + + var setupPostTestNode = setupNode.getElementsByTagName('PostTest'); + if (setupPostTestNode.length != 0) + { + setupPostTestNode = setupPostTestNode[0]; + this.postTest.construct(setupPostTestNode); + } if (metricCollection.length > 0) { metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); @@ -1675,7 +1718,9 @@ var audioHolders = projectXML.getElementsByTagName('audioHolder'); for (var i=0; i tags for (var ahIndex = 0; ahIndex < this.audioHolders.length; ahIndex++) { - var AHObj = this.audioHolders[ahIndex]; - var AHNode = root.createElement("audioHolder"); - AHNode.id = AHObj.id; - AHNode.setAttribute("hostURL",AHObj.hostURL); - AHNode.setAttribute("sampleRate",AHObj.samplerate); - AHNode.setAttribute("randomiseOrder",AHObj.randomiseOrder); - AHNode.setAttribute("repeatCount",AHObj.repeatCount); - AHNode.setAttribute("loop",AHObj.loop); - AHNode.setAttribute("elementComments",AHObj.elementComments); - - // Create tag - for (var i=0; i - for (var aeIndex = 0; aeIndex < AHObj.audioElements.length; aeIndex++) - { - var AEObj = AHObj.audioElements[aeIndex]; - var AENode = root.createElement("audioElements"); - AENode.id = AEObj.id; - AENode.setAttribute("url",AEObj.url); - AENode.setAttribute("type",AEObj.type); - if (AEObj.marker != undefined && AEObj.enforce) - { - AENode.setAttribute("marker",AEObj.marker*100); - } - AHNode.appendChild(AENode); - } - - // Create - for (var i=0; i - var AHPreTest = document.createElement("PreTest"); - for (var i=0; i + for (var i=0; i + var AHPreTest = root.createElement("PreTest"); + for (var i=0; i 1) + { this.marker /= 100.0;} + if (this.marker >= 0 && this.marker <= 1) + { + this.enforce = true; + return; + } else { + console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!"); + console.log("ERROR - Marker not enforced!"); + } + } else { + console.log("ERROR - Marker of audioElement "+this.id+" is not a number!"); + console.log("ERROR - Marker not enforced!"); + } + } + } + }; + this.encode = function(root) + { + var AENode = root.createElement("audioElements"); + AENode.id = this.id; + AENode.setAttribute("url",this.url); + AENode.setAttribute("type",this.type); + if (this.marker != false) + { + AENode.setAttribute("marker",this.marker*100); + } + return AENode; + }; }; this.commentQuestionNode = function(xml) { + this.id = null; + this.type = undefined; + this.question = undefined; + this.options = []; + this.statement = undefined; + + this.childOption = function() { + this.type = 'option'; + this.name = null; + this.text = null; + }; this.exportXML = function(root) { var CQNode = root.createElement("CommentQuestion"); @@ -1974,12 +2212,12 @@ CQNode.textContent = this.question; break; case "radio" || "checkbox": - var statement = document.createElement("statement"); + var statement = root.createElement("statement"); statement.textContent = this.statement; CQNode.appendChild(statement); for (var i=0; i