annotate test_create/test_create.html @ 1898:db85dec2b0b0

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 37c5e99ef828
children 2dd5f7071e3f
rev   line source
nickjillings@1370 1 <html>
nickjillings@1370 2 <head>
nickjillings@1370 3 <!-- This defines the test creator tool for the Web Audio Evaluation Toolbox -->
nickjillings@1370 4 <link rel='stylesheet' type="text/css" href="style.css"/>
giuliomoro@1304 5 <link rel='stylesheet' type="text/css" href="custom.css"/>
nickjillings@1370 6 <script type="text/javascript">
giuliomoro@1304 7 window.onbeforeunload = function (e) {var message = 'If you leave the page now, any unsaved changes will be lost', e = e || window.event; if (e) { e.returnValue = message;}return message;};
nickjillings@1370 8 // Copy of Specifiation node from Core.js
nickjillings@1370 9 function Specification() {
nickjillings@1370 10 // Handles the decoding of the project specification XML into a simple JavaScript Object.
nickjillings@1370 11
nickjillings@1370 12 this.interface = null;
nickjillings@1373 13 this.projectReturn = "null";
nickjillings@1370 14 this.randomiseOrder = null;
nickjillings@1370 15 this.testPages = null;
nickjillings@1370 16 this.pages = [];
nickjillings@1370 17 this.metrics = null;
nickjillings@1370 18 this.interfaces = null;
nickjillings@1370 19 this.loudness = null;
nickjillings@1370 20 this.errors = [];
nickjillings@1370 21 this.schema = null;
nickjillings@1370 22
nickjillings@1898 23 this.processAttribute = function(attribute,schema,schemaRoot)
nickjillings@1370 24 {
nickjillings@1370 25 // attribute is the string returned from getAttribute on the XML
nickjillings@1370 26 // schema is the <xs:attribute> node
nickjillings@1370 27 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
nickjillings@1370 28 {
nickjillings@1898 29 schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0];
nickjillings@1370 30 }
nickjillings@1370 31 var defaultOpt = schema.getAttribute('default');
nickjillings@1370 32 if (attribute == null) {
nickjillings@1370 33 attribute = defaultOpt;
nickjillings@1370 34 }
nickjillings@1370 35 var dataType = schema.getAttribute('type');
nickjillings@1370 36 if (typeof dataType == "string") { dataType = dataType.substr(3);}
nickjillings@1370 37 else {dataType = "string";}
nickjillings@1370 38 if (attribute == null)
nickjillings@1370 39 {
nickjillings@1370 40 return attribute;
nickjillings@1370 41 }
nickjillings@1370 42 switch(dataType)
nickjillings@1370 43 {
nickjillings@1370 44 case "boolean":
nickjillings@1370 45 if (attribute == 'true'){attribute = true;}else{attribute=false;}
nickjillings@1370 46 break;
nickjillings@1370 47 case "negativeInteger":
nickjillings@1370 48 case "positiveInteger":
nickjillings@1370 49 case "nonNegativeInteger":
nickjillings@1370 50 case "nonPositiveInteger":
nickjillings@1370 51 case "integer":
nickjillings@1370 52 case "decimal":
nickjillings@1370 53 case "short":
nickjillings@1370 54 attribute = Number(attribute);
nickjillings@1370 55 break;
nickjillings@1370 56 case "string":
nickjillings@1370 57 default:
nickjillings@1370 58 attribute = String(attribute);
nickjillings@1370 59 break;
nickjillings@1370 60 }
nickjillings@1370 61 return attribute;
nickjillings@1370 62 };
nickjillings@1370 63
nickjillings@1370 64 this.decode = function(projectXML) {
nickjillings@1370 65 this.errors = [];
nickjillings@1370 66 // projectXML - DOM Parsed document
nickjillings@1370 67 this.projectXML = projectXML.childNodes[0];
nickjillings@1370 68 var setupNode = projectXML.getElementsByTagName('setup')[0];
nickjillings@1370 69 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@1370 70 // First decode the attributes
nickjillings@1370 71 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@1370 72 for (var i in attributes)
nickjillings@1370 73 {
nickjillings@1370 74 if (isNaN(Number(i)) == true){break;}
nickjillings@1898 75 var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref');
nickjillings@1370 76 var projectAttr = setupNode.getAttribute(attributeName);
nickjillings@1898 77 projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema);
nickjillings@1370 78 switch(typeof projectAttr)
nickjillings@1370 79 {
nickjillings@1370 80 case "number":
nickjillings@1370 81 case "boolean":
nickjillings@1370 82 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 83 break;
nickjillings@1370 84 case "string":
nickjillings@1370 85 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 86 break;
nickjillings@1370 87 }
nickjillings@1370 88
nickjillings@1370 89 }
nickjillings@1370 90
nickjillings@1370 91 this.metrics = new this.metricNode();
nickjillings@1370 92
nickjillings@1370 93 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
nickjillings@1370 94
nickjillings@1370 95 // Now process the survey node options
nickjillings@1370 96 var survey = setupNode.getElementsByTagName('survey');
nickjillings@1370 97 for (var i in survey) {
nickjillings@1370 98 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 99 var location = survey[i].getAttribute('location');
nickjillings@1370 100 if (location == 'pre' || location == 'before')
nickjillings@1370 101 {
nickjillings@1370 102 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@1370 103 else {
nickjillings@1370 104 this.preTest = new this.surveyNode();
nickjillings@1370 105 this.preTest.decode(this,survey[i]);
nickjillings@1370 106 }
nickjillings@1370 107 } else if (location == 'post' || location == 'after') {
nickjillings@1370 108 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@1370 109 else {
nickjillings@1370 110 this.postTest = new this.surveyNode();
nickjillings@1370 111 this.postTest.decode(this,survey[i]);
nickjillings@1370 112 }
nickjillings@1370 113 }
nickjillings@1370 114 }
nickjillings@1370 115
nickjillings@1370 116 var interfaceNode = setupNode.getElementsByTagName('interface');
nickjillings@1370 117 if (interfaceNode.length > 1)
nickjillings@1370 118 {
nickjillings@1370 119 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
nickjillings@1370 120 }
nickjillings@1370 121 this.interfaces = new this.interfaceNode();
nickjillings@1370 122 if (interfaceNode.length != 0)
nickjillings@1370 123 {
nickjillings@1370 124 interfaceNode = interfaceNode[0];
nickjillings@1370 125 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
nickjillings@1370 126 }
nickjillings@1370 127
nickjillings@1370 128 // Page tags
nickjillings@1370 129 var pageTags = projectXML.getElementsByTagName('page');
nickjillings@1370 130 var pageSchema = this.schema.getAllElementsByName('page')[0];
nickjillings@1370 131 for (var i=0; i<pageTags.length; i++)
nickjillings@1370 132 {
nickjillings@1370 133 var node = new this.page();
nickjillings@1370 134 node.decode(this,pageTags[i],pageSchema);
nickjillings@1370 135 this.pages.push(node);
nickjillings@1370 136 }
nickjillings@1370 137 };
nickjillings@1370 138
nickjillings@1370 139 this.encode = function()
nickjillings@1370 140 {
nickjillings@1372 141 var RootDocument = document.implementation.createDocument(null,"waet");
nickjillings@1372 142 var root = RootDocument.children[0];
nickjillings@1372 143 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
nickjillings@1372 144 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
nickjillings@1370 145 // Build setup node
nickjillings@1372 146 var setup = RootDocument.createElement("setup");
nickjillings@1372 147 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@1372 148 // First decode the attributes
nickjillings@1372 149 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@1372 150 for (var i=0; i<attributes.length; i++)
nickjillings@1372 151 {
nickjillings@1372 152 var name = attributes[i].getAttribute("name");
nickjillings@1372 153 if (name == undefined) {
nickjillings@1372 154 name = attributes[i].getAttribute("ref");
nickjillings@1372 155 }
nickjillings@1372 156 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 157 {
nickjillings@1372 158 eval("setup.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 159 }
nickjillings@1372 160 }
nickjillings@1372 161 root.appendChild(setup);
nickjillings@1372 162 // Survey node
nickjillings@1372 163 setup.appendChild(this.preTest.encode(RootDocument));
nickjillings@1372 164 setup.appendChild(this.postTest.encode(RootDocument));
nickjillings@1372 165 setup.appendChild(this.metrics.encode(RootDocument));
nickjillings@1372 166 setup.appendChild(this.interfaces.encode(RootDocument));
nickjillings@1372 167 for (var page of this.pages)
nickjillings@1372 168 {
nickjillings@1372 169 root.appendChild(page.encode(RootDocument));
nickjillings@1372 170 }
nickjillings@1372 171 return RootDocument;
nickjillings@1370 172 };
nickjillings@1370 173
nickjillings@1370 174 this.surveyNode = function() {
nickjillings@1370 175 this.location = null;
nickjillings@1370 176 this.options = [];
nickjillings@1898 177 this.parent = null;
nickjillings@1370 178 this.schema = specification.schema.getAllElementsByName('survey')[0];
nickjillings@1370 179
nickjillings@1370 180 this.OptionNode = function() {
nickjillings@1370 181 this.type = undefined;
nickjillings@1370 182 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
nickjillings@1370 183 this.id = undefined;
nickjillings@1889 184 this.name = undefined;
nickjillings@1370 185 this.mandatory = undefined;
nickjillings@1370 186 this.statement = undefined;
nickjillings@1370 187 this.boxsize = undefined;
nickjillings@1370 188 this.options = [];
nickjillings@1370 189 this.min = undefined;
nickjillings@1370 190 this.max = undefined;
nickjillings@1370 191 this.step = undefined;
nickjillings@1370 192
nickjillings@1370 193 this.decode = function(parent,child)
nickjillings@1370 194 {
nickjillings@1370 195 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 196 for (var i in attributeMap){
nickjillings@1370 197 if(isNaN(Number(i)) == true){break;}
nickjillings@1370 198 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 199 var projectAttr = child.getAttribute(attributeName);
nickjillings@1898 200 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
nickjillings@1370 201 switch(typeof projectAttr)
nickjillings@1370 202 {
nickjillings@1370 203 case "number":
nickjillings@1370 204 case "boolean":
nickjillings@1370 205 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 206 break;
nickjillings@1370 207 case "string":
nickjillings@1370 208 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 209 break;
nickjillings@1370 210 }
nickjillings@1370 211 }
nickjillings@1370 212 this.statement = child.getElementsByTagName('statement')[0].textContent;
nickjillings@1370 213 if (this.type == "checkbox" || this.type == "radio") {
nickjillings@1370 214 var children = child.getElementsByTagName('option');
nickjillings@1370 215 if (children.length == null) {
nickjillings@1370 216 console.log('Malformed' +child.nodeName+ 'entry');
nickjillings@1370 217 this.statement = 'Malformed' +child.nodeName+ 'entry';
nickjillings@1370 218 this.type = 'statement';
nickjillings@1370 219 } else {
nickjillings@1370 220 this.options = [];
nickjillings@1370 221 for (var i in children)
nickjillings@1370 222 {
nickjillings@1370 223 if (isNaN(Number(i))==true){break;}
nickjillings@1370 224 this.options.push({
nickjillings@1370 225 name: children[i].getAttribute('name'),
nickjillings@1370 226 text: children[i].textContent
nickjillings@1370 227 });
nickjillings@1370 228 }
nickjillings@1370 229 }
nickjillings@1370 230 }
nickjillings@1370 231 };
nickjillings@1370 232
nickjillings@1372 233 this.exportXML = function(doc)
nickjillings@1370 234 {
nickjillings@1844 235 var node = doc.createElement('surveyentry');
nickjillings@1370 236 node.setAttribute('type',this.type);
nickjillings@1372 237 var statement = doc.createElement('statement');
nickjillings@1370 238 statement.textContent = this.statement;
nickjillings@1370 239 node.appendChild(statement);
nickjillings@1895 240 node.id = this.id;
nickjillings@1895 241 if (this.name != undefined) { node.setAttribute("name",this.name);}
nickjillings@1895 242 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
nickjillings@1895 243 node.id = this.id;
nickjillings@1895 244 if (this.name != undefined) {node.setAttribute("name",this.name);}
nickjillings@1895 245 switch(this.type)
nickjillings@1895 246 {
nickjillings@1889 247 case "checkbox":
nickjillings@1889 248 case "radio":
nickjillings@1889 249 for (var i=0; i<this.options.length; i++)
nickjillings@1889 250 {
nickjillings@1889 251 var option = this.options[i];
nickjillings@1889 252 var optionNode = doc.createElement("option");
nickjillings@1889 253 optionNode.setAttribute("name",option.name);
nickjillings@1889 254 optionNode.textContent = option.text;
nickjillings@1889 255 node.appendChild(optionNode);
nickjillings@1889 256 }
nickjillings@1895 257 case "number":
nickjillings@1895 258 if (this.min != undefined) {node.setAttribute("min", this.min);}
nickjillings@1895 259 if (this.max != undefined) {node.setAttribute("max", this.max);}
nickjillings@1895 260 case "question":
nickjillings@1895 261 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
nickjillings@1895 262 if (this.mandatory != undefined) {node.setAttribute("mandatory",this.mandatory);}
nickjillings@1895 263 default:
nickjillings@1889 264 break;
nickjillings@1370 265 }
nickjillings@1370 266 return node;
nickjillings@1370 267 };
nickjillings@1370 268 };
nickjillings@1370 269 this.decode = function(parent,xml) {
nickjillings@1898 270 this.parent = parent;
nickjillings@1370 271 this.location = xml.getAttribute('location');
nickjillings@1370 272 if (this.location == 'before'){this.location = 'pre';}
nickjillings@1370 273 else if (this.location == 'after'){this.location = 'post';}
nickjillings@1370 274 for (var i in xml.children)
nickjillings@1370 275 {
nickjillings@1370 276 if(isNaN(Number(i))==true){break;}
nickjillings@1370 277 var node = new this.OptionNode();
nickjillings@1370 278 node.decode(parent,xml.children[i]);
nickjillings@1370 279 this.options.push(node);
nickjillings@1370 280 }
nickjillings@1370 281 };
nickjillings@1372 282 this.encode = function(doc) {
nickjillings@1372 283 var node = doc.createElement('survey');
nickjillings@1370 284 node.setAttribute('location',this.location);
nickjillings@1370 285 for (var i=0; i<this.options.length; i++)
nickjillings@1370 286 {
nickjillings@1372 287 node.appendChild(this.options[i].exportXML(doc));
nickjillings@1370 288 }
nickjillings@1370 289 return node;
nickjillings@1370 290 };
nickjillings@1370 291 };
nickjillings@1370 292
nickjillings@1370 293 this.interfaceNode = function()
nickjillings@1370 294 {
nickjillings@1370 295 this.title = null;
nickjillings@1370 296 this.name = null;
nickjillings@1370 297 this.options = [];
nickjillings@1370 298 this.scales = [];
nickjillings@1370 299 this.schema = specification.schema.getAllElementsByName('interface')[1];
nickjillings@1370 300
nickjillings@1370 301 this.decode = function(parent,xml) {
nickjillings@1370 302 this.name = xml.getAttribute('name');
nickjillings@1370 303 var titleNode = xml.getElementsByTagName('title');
nickjillings@1370 304 if (titleNode.length == 1)
nickjillings@1370 305 {
nickjillings@1370 306 this.title = titleNode[0].textContent;
nickjillings@1370 307 }
nickjillings@1370 308 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
nickjillings@1370 309 // Extract interfaceoption node schema
nickjillings@1370 310 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
nickjillings@1370 311 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 312 for (var i=0; i<interfaceOptionNodes.length; i++)
nickjillings@1370 313 {
nickjillings@1370 314 var ioNode = interfaceOptionNodes[i];
nickjillings@1370 315 var option = {};
nickjillings@1370 316 for (var j=0; j<attributeMap.length; j++)
nickjillings@1370 317 {
nickjillings@1370 318 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
nickjillings@1370 319 var projectAttr = ioNode.getAttribute(attributeName);
nickjillings@1898 320 if(parent.processAttribute) {
nickjillings@1898 321 parent.processAttribute(projectAttr, attributeMap[j], parent.schema)
nickjillings@1898 322 } else {
nickjillings@1898 323 parent.parent.processAttribute(projectAttr, attributeMap[j], parent.parent.schema)
nickjillings@1898 324 }
nickjillings@1370 325 switch(typeof projectAttr)
nickjillings@1370 326 {
nickjillings@1370 327 case "number":
nickjillings@1370 328 case "boolean":
nickjillings@1370 329 eval('option.'+attributeName+' = '+projectAttr);
nickjillings@1370 330 break;
nickjillings@1370 331 case "string":
nickjillings@1370 332 eval('option.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 333 break;
nickjillings@1370 334 }
nickjillings@1370 335 }
nickjillings@1370 336 this.options.push(option);
nickjillings@1370 337 }
nickjillings@1370 338
nickjillings@1370 339 // Now the scales nodes
nickjillings@1370 340 var scaleParent = xml.getElementsByTagName('scales');
nickjillings@1370 341 if (scaleParent.length == 1) {
nickjillings@1370 342 scaleParent = scaleParent[0];
nickjillings@1370 343 for (var i=0; i<scaleParent.children.length; i++) {
nickjillings@1370 344 var child = scaleParent.children[i];
nickjillings@1370 345 this.scales.push({
nickjillings@1370 346 text: child.textContent,
nickjillings@1370 347 position: Number(child.getAttribute('position'))
nickjillings@1370 348 });
nickjillings@1370 349 }
nickjillings@1370 350 }
nickjillings@1370 351 };
nickjillings@1370 352
nickjillings@1372 353 this.encode = function(doc) {
nickjillings@1372 354 var node = doc.createElement("interface");
nickjillings@1372 355 if (typeof name == "string")
nickjillings@1372 356 node.setAttribute("name",this.name);
nickjillings@1372 357 for (var option of this.options)
nickjillings@1372 358 {
nickjillings@1372 359 var child = doc.createElement("interfaceoption");
nickjillings@1372 360 child.setAttribute("type",option.type);
nickjillings@1372 361 child.setAttribute("name",option.name);
nickjillings@1372 362 node.appendChild(child);
nickjillings@1372 363 }
nickjillings@1372 364 if (this.scales.length != 0) {
nickjillings@1372 365 var scales = doc.createElement("scales");
nickjillings@1372 366 for (var scale of this.scales)
nickjillings@1372 367 {
nickjillings@1372 368 var child = doc.createElement("scalelabel");
nickjillings@1372 369 child.setAttribute("position",scale.position);
nickjillings@1372 370 child.textContent = scale.text;
nickjillings@1372 371 scales.appendChild(child);
nickjillings@1372 372 }
nickjillings@1372 373 node.appendChild(scales);
nickjillings@1372 374 }
nickjillings@1372 375 return node;
nickjillings@1370 376 };
nickjillings@1370 377 };
nickjillings@1370 378
nickjillings@1370 379 this.metricNode = function() {
nickjillings@1370 380 this.enabled = [];
nickjillings@1370 381 this.decode = function(parent, xml) {
nickjillings@1370 382 var children = xml.getElementsByTagName('metricenable');
nickjillings@1370 383 for (var i in children) {
nickjillings@1370 384 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 385 this.enabled.push(children[i].textContent);
nickjillings@1370 386 }
nickjillings@1370 387 }
nickjillings@1372 388 this.encode = function(doc) {
nickjillings@1372 389 var node = doc.createElement('metric');
nickjillings@1370 390 for (var i in this.enabled)
nickjillings@1370 391 {
nickjillings@1370 392 if (isNaN(Number(i)) == true){break;}
nickjillings@1372 393 var child = doc.createElement('metricenable');
nickjillings@1370 394 child.textContent = this.enabled[i];
nickjillings@1370 395 node.appendChild(child);
nickjillings@1370 396 }
nickjillings@1370 397 return node;
nickjillings@1370 398 }
nickjillings@1370 399 }
nickjillings@1370 400
nickjillings@1370 401 this.page = function() {
nickjillings@1370 402 this.presentedId = undefined;
nickjillings@1370 403 this.id = undefined;
nickjillings@1370 404 this.hostURL = undefined;
nickjillings@1370 405 this.randomiseOrder = undefined;
nickjillings@1370 406 this.loop = undefined;
nickjillings@1370 407 this.showElementComments = undefined;
nickjillings@1370 408 this.outsideReference = null;
nickjillings@1370 409 this.loudness = null;
nickjillings@1898 410 this.label = null;
nickjillings@1370 411 this.preTest = null;
nickjillings@1370 412 this.postTest = null;
nickjillings@1370 413 this.interfaces = [];
nickjillings@1370 414 this.commentBoxPrefix = "Comment on track";
nickjillings@1370 415 this.audioElements = [];
nickjillings@1370 416 this.commentQuestions = [];
nickjillings@1370 417 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1898 418 this.parent = null;
nickjillings@1370 419
nickjillings@1370 420 this.decode = function(parent,xml)
nickjillings@1370 421 {
nickjillings@1898 422 this.parent = parent;
nickjillings@1370 423 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 424 for (var i=0; i<attributeMap.length; i++)
nickjillings@1370 425 {
nickjillings@1370 426 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 427 var projectAttr = xml.getAttribute(attributeName);
nickjillings@1898 428 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
nickjillings@1370 429 switch(typeof projectAttr)
nickjillings@1370 430 {
nickjillings@1370 431 case "number":
nickjillings@1370 432 case "boolean":
nickjillings@1370 433 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 434 break;
nickjillings@1370 435 case "string":
nickjillings@1370 436 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 437 break;
nickjillings@1370 438 }
nickjillings@1370 439 }
nickjillings@1370 440
nickjillings@1370 441 // Get the Comment Box Prefix
nickjillings@1370 442 var CBP = xml.getElementsByTagName('commentboxprefix');
nickjillings@1370 443 if (CBP.length != 0) {
nickjillings@1370 444 this.commentBoxPrefix = CBP[0].textContent;
nickjillings@1370 445 }
nickjillings@1370 446
nickjillings@1370 447 // Now decode the interfaces
nickjillings@1370 448 var interfaceNode = xml.getElementsByTagName('interface');
nickjillings@1370 449 for (var i=0; i<interfaceNode.length; i++)
nickjillings@1370 450 {
nickjillings@1370 451 var node = new parent.interfaceNode();
nickjillings@1370 452 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
nickjillings@1370 453 this.interfaces.push(node);
nickjillings@1370 454 }
nickjillings@1370 455
nickjillings@1370 456 // Now process the survey node options
nickjillings@1370 457 var survey = xml.getElementsByTagName('survey');
nickjillings@1370 458 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
nickjillings@1370 459 for (var i in survey) {
nickjillings@1370 460 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 461 var location = survey[i].getAttribute('location');
nickjillings@1370 462 if (location == 'pre' || location == 'before')
nickjillings@1370 463 {
nickjillings@1370 464 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@1370 465 else {
nickjillings@1370 466 this.preTest = new parent.surveyNode();
nickjillings@1370 467 this.preTest.decode(parent,survey[i],surveySchema);
nickjillings@1370 468 }
nickjillings@1370 469 } else if (location == 'post' || location == 'after') {
nickjillings@1370 470 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@1370 471 else {
nickjillings@1370 472 this.postTest = new parent.surveyNode();
nickjillings@1370 473 this.postTest.decode(parent,survey[i],surveySchema);
nickjillings@1370 474 }
nickjillings@1370 475 }
nickjillings@1370 476 }
nickjillings@1370 477
nickjillings@1370 478 // Now process the audioelement tags
nickjillings@1370 479 var audioElements = xml.getElementsByTagName('audioelement');
nickjillings@1370 480 for (var i=0; i<audioElements.length; i++)
nickjillings@1370 481 {
nickjillings@1370 482 var node = new this.audioElementNode();
nickjillings@1370 483 node.decode(this,audioElements[i]);
nickjillings@1370 484 this.audioElements.push(node);
nickjillings@1370 485 }
nickjillings@1370 486
nickjillings@1370 487 // Now decode the commentquestions
nickjillings@1370 488 var commentQuestions = xml.getElementsByTagName('commentquestion');
nickjillings@1370 489 for (var i=0; i<commentQuestions.length; i++)
nickjillings@1370 490 {
nickjillings@1370 491 var node = new this.commentQuestionNode();
nickjillings@1370 492 node.decode(parent,commentQuestions[i]);
nickjillings@1370 493 this.commentQuestions.push(node);
nickjillings@1370 494 }
nickjillings@1370 495 };
nickjillings@1370 496
nickjillings@1370 497 this.encode = function(root)
nickjillings@1370 498 {
nickjillings@1372 499 var AHNode = root.createElement("page");
nickjillings@1372 500 // First decode the attributes
nickjillings@1372 501 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1372 502 for (var i=0; i<attributes.length; i++)
nickjillings@1372 503 {
nickjillings@1372 504 var name = attributes[i].getAttribute("name");
nickjillings@1372 505 if (name == undefined) {
nickjillings@1372 506 name = attributes[i].getAttribute("ref");
nickjillings@1372 507 }
nickjillings@1372 508 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 509 {
nickjillings@1372 510 eval("AHNode.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 511 }
nickjillings@1372 512 }
nickjillings@1370 513 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
nickjillings@1372 514 // <commentboxprefix>
nickjillings@1372 515 var commentboxprefix = root.createElement("commentboxprefix");
nickjillings@1372 516 commentboxprefix.textContent = this.commentBoxPrefix;
nickjillings@1372 517 AHNode.appendChild(commentboxprefix);
nickjillings@1372 518
nickjillings@1370 519 for (var i=0; i<this.interfaces.length; i++)
nickjillings@1370 520 {
nickjillings@1370 521 AHNode.appendChild(this.interfaces[i].encode(root));
nickjillings@1370 522 }
nickjillings@1370 523
nickjillings@1370 524 for (var i=0; i<this.audioElements.length; i++) {
nickjillings@1370 525 AHNode.appendChild(this.audioElements[i].encode(root));
nickjillings@1370 526 }
nickjillings@1370 527 // Create <CommentQuestion>
nickjillings@1370 528 for (var i=0; i<this.commentQuestions.length; i++)
nickjillings@1370 529 {
nickjillings@1372 530 AHNode.appendChild(this.commentQuestions[i].encode(root));
nickjillings@1370 531 }
nickjillings@1370 532
nickjillings@1372 533 AHNode.appendChild(this.preTest.encode(root));
nickjillings@1372 534 AHNode.appendChild(this.postTest.encode(root));
nickjillings@1370 535 return AHNode;
nickjillings@1370 536 };
nickjillings@1370 537
nickjillings@1370 538 this.commentQuestionNode = function() {
nickjillings@1370 539 this.id = null;
nickjillings@1889 540 this.name = undefined;
nickjillings@1370 541 this.type = undefined;
nickjillings@1370 542 this.options = [];
nickjillings@1370 543 this.statement = undefined;
nickjillings@1370 544 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
nickjillings@1370 545 this.decode = function(parent,xml)
nickjillings@1370 546 {
nickjillings@1370 547 this.id = xml.id;
nickjillings@1889 548 this.name = xml.getAttribute('name');
nickjillings@1370 549 this.type = xml.getAttribute('type');
nickjillings@1370 550 this.statement = xml.getElementsByTagName('statement')[0].textContent;
nickjillings@1370 551 var optNodes = xml.getElementsByTagName('option');
nickjillings@1370 552 for (var i=0; i<optNodes.length; i++)
nickjillings@1370 553 {
nickjillings@1370 554 var optNode = optNodes[i];
nickjillings@1370 555 this.options.push({
nickjillings@1370 556 name: optNode.getAttribute('name'),
nickjillings@1370 557 text: optNode.textContent
nickjillings@1370 558 });
nickjillings@1370 559 }
nickjillings@1370 560 };
nickjillings@1370 561
nickjillings@1370 562 this.encode = function(root)
nickjillings@1370 563 {
nickjillings@1372 564 var node = root.createElement("commentquestion");
nickjillings@1372 565 node.id = this.id;
nickjillings@1372 566 node.setAttribute("type",this.type);
nickjillings@1889 567 if (this.name != undefined){node.setAttribute("name",this.name);}
nickjillings@1372 568 var statement = root.createElement("statement");
nickjillings@1372 569 statement.textContent = this.statement;
nickjillings@1372 570 node.appendChild(statement);
nickjillings@1372 571 for (var option of this.options)
nickjillings@1372 572 {
nickjillings@1372 573 var child = root.createElement("option");
nickjillings@1372 574 child.setAttribute("name",option.name);
nickjillings@1372 575 child.textContent = option.text;
nickjillings@1372 576 node.appendChild(child);
nickjillings@1372 577 }
nickjillings@1372 578 return node;
nickjillings@1370 579 };
nickjillings@1370 580 };
nickjillings@1370 581
nickjillings@1370 582 this.audioElementNode = function() {
nickjillings@1370 583 this.url = null;
nickjillings@1370 584 this.id = null;
nickjillings@1889 585 this.name = null;
nickjillings@1370 586 this.parent = null;
nickjillings@1370 587 this.type = null;
nickjillings@1310 588 this.marker = null;
nickjillings@1370 589 this.enforce = false;
nickjillings@1863 590 this.gain = 0.0;
nickjillings@1370 591 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
nickjillings@1370 592 this.parent = null;
nickjillings@1370 593 this.decode = function(parent,xml)
nickjillings@1370 594 {
nickjillings@1370 595 this.parent = parent;
nickjillings@1370 596 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 597 for (var i=0; i<attributeMap.length; i++)
nickjillings@1370 598 {
nickjillings@1370 599 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 600 var projectAttr = xml.getAttribute(attributeName);
nickjillings@1898 601 projectAttr = parent.parent.processAttribute(projectAttr,attributeMap[i],parent.parent.schema);
nickjillings@1370 602 switch(typeof projectAttr)
nickjillings@1370 603 {
nickjillings@1370 604 case "number":
nickjillings@1370 605 case "boolean":
nickjillings@1370 606 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 607 break;
nickjillings@1370 608 case "string":
nickjillings@1370 609 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 610 break;
nickjillings@1370 611 }
nickjillings@1370 612 }
nickjillings@1370 613
nickjillings@1370 614 };
nickjillings@1370 615 this.encode = function(root)
nickjillings@1370 616 {
nickjillings@1372 617 var AENode = root.createElement("audioelement");
nickjillings@1372 618 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1372 619 for (var i=0; i<attributes.length; i++)
nickjillings@1370 620 {
nickjillings@1372 621 var name = attributes[i].getAttribute("name");
nickjillings@1372 622 if (name == undefined) {
nickjillings@1372 623 name = attributes[i].getAttribute("ref");
nickjillings@1372 624 }
nickjillings@1372 625 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 626 {
nickjillings@1372 627 eval("AENode.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 628 }
nickjillings@1370 629 }
nickjillings@1370 630 return AENode;
nickjillings@1370 631 };
nickjillings@1370 632 };
nickjillings@1370 633 };
nickjillings@1370 634 }
nickjillings@1372 635
nickjillings@1370 636 </script>
nickjillings@1381 637 <script src="../jquery-2.1.4.js"></script>
nickjillings@1370 638 <script type="text/javascript" src="test_core.js"/>
nickjillings@1370 639 <script type="text/javascript">
nickjillings@1370 640
nickjillings@1370 641 </script>
nickjillings@1370 642 </head>
nickjillings@1370 643 <body>
nickjillings@1370 644 <div id="popupHolder"></div>
nickjillings@1370 645 <div id="blanket"></div>
nickjillings@1370 646 <div id="content"></div>
nickjillings@1370 647 </body>
giuliomoro@1304 648 </html>