annotate test_create/test_create.html @ 1092:e4b378468589

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