annotate test_create/test_create.html @ 1115:ddc5a639179a

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