annotate test_create/test_create.html @ 1313:c8317e07c15f

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