annotate test_create/test_create.html @ 1113:9ee921c8cdd3

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