annotate test_create/test_create.html @ 1106:282dfb8076f5

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