annotate test_create/test_create.html @ 2110:44eef6a6ca7e

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