Mercurial > hg > webaudioevaluationtool
comparison core.js @ 2165:e75107c82178
Fixed errors caused by specifcation nesting, specifically if <page> interface nodes have <interfaceoption> nodes.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Fri, 18 Mar 2016 14:52:30 +0000 |
parents | 894d9bfd4177 |
children | 96a830d58da7 |
comparison
equal
deleted
inserted
replaced
2164:ce24c304f93c | 2165:e75107c82178 |
---|---|
1810 this.interfaces = null; | 1810 this.interfaces = null; |
1811 this.loudness = null; | 1811 this.loudness = null; |
1812 this.errors = []; | 1812 this.errors = []; |
1813 this.schema = null; | 1813 this.schema = null; |
1814 | 1814 |
1815 this.processAttribute = function(attribute,schema) | 1815 this.processAttribute = function(attribute,schema,schemaRoot) |
1816 { | 1816 { |
1817 // attribute is the string returned from getAttribute on the XML | 1817 // attribute is the string returned from getAttribute on the XML |
1818 // schema is the <xs:attribute> node | 1818 // schema is the <xs:attribute> node |
1819 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) | 1819 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) |
1820 { | 1820 { |
1821 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; | 1821 schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0]; |
1822 } | 1822 } |
1823 var defaultOpt = schema.getAttribute('default'); | 1823 var defaultOpt = schema.getAttribute('default'); |
1824 if (attribute == null) { | 1824 if (attribute == null) { |
1825 attribute = defaultOpt; | 1825 attribute = defaultOpt; |
1826 } | 1826 } |
1862 // First decode the attributes | 1862 // First decode the attributes |
1863 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); | 1863 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); |
1864 for (var i in attributes) | 1864 for (var i in attributes) |
1865 { | 1865 { |
1866 if (isNaN(Number(i)) == true){break;} | 1866 if (isNaN(Number(i)) == true){break;} |
1867 var attributeName = attributes[i].getAttribute('name'); | 1867 var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref'); |
1868 var projectAttr = setupNode.getAttribute(attributeName); | 1868 var projectAttr = setupNode.getAttribute(attributeName); |
1869 projectAttr = this.processAttribute(projectAttr,attributes[i]); | 1869 projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema); |
1870 switch(typeof projectAttr) | 1870 switch(typeof projectAttr) |
1871 { | 1871 { |
1872 case "number": | 1872 case "number": |
1873 case "boolean": | 1873 case "boolean": |
1874 eval('this.'+attributeName+' = '+projectAttr); | 1874 eval('this.'+attributeName+' = '+projectAttr); |
1964 }; | 1964 }; |
1965 | 1965 |
1966 this.surveyNode = function() { | 1966 this.surveyNode = function() { |
1967 this.location = null; | 1967 this.location = null; |
1968 this.options = []; | 1968 this.options = []; |
1969 this.parent = null; | |
1969 this.schema = specification.schema.getAllElementsByName('survey')[0]; | 1970 this.schema = specification.schema.getAllElementsByName('survey')[0]; |
1970 | 1971 |
1971 this.OptionNode = function() { | 1972 this.OptionNode = function() { |
1972 this.type = undefined; | 1973 this.type = undefined; |
1973 this.schema = specification.schema.getAllElementsByName('surveyentry')[0]; | 1974 this.schema = specification.schema.getAllElementsByName('surveyentry')[0]; |
1986 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | 1987 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
1987 for (var i in attributeMap){ | 1988 for (var i in attributeMap){ |
1988 if(isNaN(Number(i)) == true){break;} | 1989 if(isNaN(Number(i)) == true){break;} |
1989 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 1990 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
1990 var projectAttr = child.getAttribute(attributeName); | 1991 var projectAttr = child.getAttribute(attributeName); |
1991 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); | 1992 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema); |
1992 switch(typeof projectAttr) | 1993 switch(typeof projectAttr) |
1993 { | 1994 { |
1994 case "number": | 1995 case "number": |
1995 case "boolean": | 1996 case "boolean": |
1996 eval('this.'+attributeName+' = '+projectAttr); | 1997 eval('this.'+attributeName+' = '+projectAttr); |
2056 } | 2057 } |
2057 return node; | 2058 return node; |
2058 }; | 2059 }; |
2059 }; | 2060 }; |
2060 this.decode = function(parent,xml) { | 2061 this.decode = function(parent,xml) { |
2062 this.parent = parent; | |
2061 this.location = xml.getAttribute('location'); | 2063 this.location = xml.getAttribute('location'); |
2062 if (this.location == 'before'){this.location = 'pre';} | 2064 if (this.location == 'before'){this.location = 'pre';} |
2063 else if (this.location == 'after'){this.location = 'post';} | 2065 else if (this.location == 'after'){this.location = 'post';} |
2064 for (var i in xml.children) | 2066 for (var i in xml.children) |
2065 { | 2067 { |
2105 var option = {}; | 2107 var option = {}; |
2106 for (var j=0; j<attributeMap.length; j++) | 2108 for (var j=0; j<attributeMap.length; j++) |
2107 { | 2109 { |
2108 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref'); | 2110 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref'); |
2109 var projectAttr = ioNode.getAttribute(attributeName); | 2111 var projectAttr = ioNode.getAttribute(attributeName); |
2110 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]); | 2112 if(parent.processAttribute) { |
2113 parent.processAttribute(projectAttr, attributeMap[j], parent.schema) | |
2114 } else { | |
2115 parent.parent.processAttribute(projectAttr, attributeMap[j], parent.parent.schema) | |
2116 } | |
2111 switch(typeof projectAttr) | 2117 switch(typeof projectAttr) |
2112 { | 2118 { |
2113 case "number": | 2119 case "number": |
2114 case "boolean": | 2120 case "boolean": |
2115 eval('option.'+attributeName+' = '+projectAttr); | 2121 eval('option.'+attributeName+' = '+projectAttr); |
2199 this.interfaces = []; | 2205 this.interfaces = []; |
2200 this.commentBoxPrefix = "Comment on track"; | 2206 this.commentBoxPrefix = "Comment on track"; |
2201 this.audioElements = []; | 2207 this.audioElements = []; |
2202 this.commentQuestions = []; | 2208 this.commentQuestions = []; |
2203 this.schema = specification.schema.getAllElementsByName("page")[0]; | 2209 this.schema = specification.schema.getAllElementsByName("page")[0]; |
2210 this.parent = null; | |
2204 | 2211 |
2205 this.decode = function(parent,xml) | 2212 this.decode = function(parent,xml) |
2206 { | 2213 { |
2214 this.parent = parent; | |
2207 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | 2215 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
2208 for (var i=0; i<attributeMap.length; i++) | 2216 for (var i=0; i<attributeMap.length; i++) |
2209 { | 2217 { |
2210 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 2218 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
2211 var projectAttr = xml.getAttribute(attributeName); | 2219 var projectAttr = xml.getAttribute(attributeName); |
2212 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); | 2220 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema); |
2213 switch(typeof projectAttr) | 2221 switch(typeof projectAttr) |
2214 { | 2222 { |
2215 case "number": | 2223 case "number": |
2216 case "boolean": | 2224 case "boolean": |
2217 eval('this.'+attributeName+' = '+projectAttr); | 2225 eval('this.'+attributeName+' = '+projectAttr); |
2380 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | 2388 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
2381 for (var i=0; i<attributeMap.length; i++) | 2389 for (var i=0; i<attributeMap.length; i++) |
2382 { | 2390 { |
2383 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 2391 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
2384 var projectAttr = xml.getAttribute(attributeName); | 2392 var projectAttr = xml.getAttribute(attributeName); |
2385 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]); | 2393 projectAttr = parent.parent.processAttribute(projectAttr,attributeMap[i],parent.parent.schema); |
2386 switch(typeof projectAttr) | 2394 switch(typeof projectAttr) |
2387 { | 2395 { |
2388 case "number": | 2396 case "number": |
2389 case "boolean": | 2397 case "boolean": |
2390 eval('this.'+attributeName+' = '+projectAttr); | 2398 eval('this.'+attributeName+' = '+projectAttr); |