annotate test_create/test_create.html @ 1273:227ca4d00ab1

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