annotate test_create/test_create.html @ 1289:175cf75946f7

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