annotate test_create/test_create.html @ 1315:d9b9f707f862

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