annotate test_create/test_create.html @ 600:0794fefefbd8

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