annotate test_create/test_create.html @ 637:df6c09f5835d Dev_main

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