annotate test_create/test_create.html @ 1309:e8b1aa4f2c0a

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