annotate test_create/test_create.html @ 1895:37c5e99ef828

Fixed test creator <surveyentry> options. Updated interface-specs for ABX.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 16 Mar 2016 15:17:04 +0000
parents 1d0936cfa1d4
children 3600fff74af9
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@1889 183 this.name = undefined;
nickjillings@1370 184 this.mandatory = undefined;
nickjillings@1370 185 this.statement = undefined;
nickjillings@1370 186 this.boxsize = undefined;
nickjillings@1370 187 this.options = [];
nickjillings@1370 188 this.min = undefined;
nickjillings@1370 189 this.max = undefined;
nickjillings@1370 190 this.step = undefined;
nickjillings@1370 191
nickjillings@1370 192 this.decode = function(parent,child)
nickjillings@1370 193 {
nickjillings@1370 194 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 195 for (var i in attributeMap){
nickjillings@1370 196 if(isNaN(Number(i)) == true){break;}
nickjillings@1370 197 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 198 var projectAttr = child.getAttribute(attributeName);
nickjillings@1370 199 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
nickjillings@1370 200 switch(typeof projectAttr)
nickjillings@1370 201 {
nickjillings@1370 202 case "number":
nickjillings@1370 203 case "boolean":
nickjillings@1370 204 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 205 break;
nickjillings@1370 206 case "string":
nickjillings@1370 207 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 208 break;
nickjillings@1370 209 }
nickjillings@1370 210 }
nickjillings@1370 211 this.statement = child.getElementsByTagName('statement')[0].textContent;
nickjillings@1370 212 if (this.type == "checkbox" || this.type == "radio") {
nickjillings@1370 213 var children = child.getElementsByTagName('option');
nickjillings@1370 214 if (children.length == null) {
nickjillings@1370 215 console.log('Malformed' +child.nodeName+ 'entry');
nickjillings@1370 216 this.statement = 'Malformed' +child.nodeName+ 'entry';
nickjillings@1370 217 this.type = 'statement';
nickjillings@1370 218 } else {
nickjillings@1370 219 this.options = [];
nickjillings@1370 220 for (var i in children)
nickjillings@1370 221 {
nickjillings@1370 222 if (isNaN(Number(i))==true){break;}
nickjillings@1370 223 this.options.push({
nickjillings@1370 224 name: children[i].getAttribute('name'),
nickjillings@1370 225 text: children[i].textContent
nickjillings@1370 226 });
nickjillings@1370 227 }
nickjillings@1370 228 }
nickjillings@1370 229 }
nickjillings@1370 230 };
nickjillings@1370 231
nickjillings@1372 232 this.exportXML = function(doc)
nickjillings@1370 233 {
nickjillings@1844 234 var node = doc.createElement('surveyentry');
nickjillings@1370 235 node.setAttribute('type',this.type);
nickjillings@1372 236 var statement = doc.createElement('statement');
nickjillings@1370 237 statement.textContent = this.statement;
nickjillings@1370 238 node.appendChild(statement);
nickjillings@1895 239 node.id = this.id;
nickjillings@1895 240 if (this.name != undefined) { node.setAttribute("name",this.name);}
nickjillings@1895 241 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
nickjillings@1895 242 node.id = this.id;
nickjillings@1895 243 if (this.name != undefined) {node.setAttribute("name",this.name);}
nickjillings@1895 244 switch(this.type)
nickjillings@1895 245 {
nickjillings@1889 246 case "checkbox":
nickjillings@1889 247 case "radio":
nickjillings@1889 248 for (var i=0; i<this.options.length; i++)
nickjillings@1889 249 {
nickjillings@1889 250 var option = this.options[i];
nickjillings@1889 251 var optionNode = doc.createElement("option");
nickjillings@1889 252 optionNode.setAttribute("name",option.name);
nickjillings@1889 253 optionNode.textContent = option.text;
nickjillings@1889 254 node.appendChild(optionNode);
nickjillings@1889 255 }
nickjillings@1895 256 case "number":
nickjillings@1895 257 if (this.min != undefined) {node.setAttribute("min", this.min);}
nickjillings@1895 258 if (this.max != undefined) {node.setAttribute("max", this.max);}
nickjillings@1895 259 case "question":
nickjillings@1895 260 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
nickjillings@1895 261 if (this.mandatory != undefined) {node.setAttribute("mandatory",this.mandatory);}
nickjillings@1895 262 default:
nickjillings@1889 263 break;
nickjillings@1370 264 }
nickjillings@1370 265 return node;
nickjillings@1370 266 };
nickjillings@1370 267 };
nickjillings@1370 268 this.decode = function(parent,xml) {
nickjillings@1370 269 this.location = xml.getAttribute('location');
nickjillings@1370 270 if (this.location == 'before'){this.location = 'pre';}
nickjillings@1370 271 else if (this.location == 'after'){this.location = 'post';}
nickjillings@1370 272 for (var i in xml.children)
nickjillings@1370 273 {
nickjillings@1370 274 if(isNaN(Number(i))==true){break;}
nickjillings@1370 275 var node = new this.OptionNode();
nickjillings@1370 276 node.decode(parent,xml.children[i]);
nickjillings@1370 277 this.options.push(node);
nickjillings@1370 278 }
nickjillings@1370 279 };
nickjillings@1372 280 this.encode = function(doc) {
nickjillings@1372 281 var node = doc.createElement('survey');
nickjillings@1370 282 node.setAttribute('location',this.location);
nickjillings@1370 283 for (var i=0; i<this.options.length; i++)
nickjillings@1370 284 {
nickjillings@1372 285 node.appendChild(this.options[i].exportXML(doc));
nickjillings@1370 286 }
nickjillings@1370 287 return node;
nickjillings@1370 288 };
nickjillings@1370 289 };
nickjillings@1370 290
nickjillings@1370 291 this.interfaceNode = function()
nickjillings@1370 292 {
nickjillings@1370 293 this.title = null;
nickjillings@1370 294 this.name = null;
nickjillings@1370 295 this.options = [];
nickjillings@1370 296 this.scales = [];
nickjillings@1370 297 this.schema = specification.schema.getAllElementsByName('interface')[1];
nickjillings@1370 298
nickjillings@1370 299 this.decode = function(parent,xml) {
nickjillings@1370 300 this.name = xml.getAttribute('name');
nickjillings@1370 301 var titleNode = xml.getElementsByTagName('title');
nickjillings@1370 302 if (titleNode.length == 1)
nickjillings@1370 303 {
nickjillings@1370 304 this.title = titleNode[0].textContent;
nickjillings@1370 305 }
nickjillings@1370 306 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
nickjillings@1370 307 // Extract interfaceoption node schema
nickjillings@1370 308 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
nickjillings@1370 309 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 310 for (var i=0; i<interfaceOptionNodes.length; i++)
nickjillings@1370 311 {
nickjillings@1370 312 var ioNode = interfaceOptionNodes[i];
nickjillings@1370 313 var option = {};
nickjillings@1370 314 for (var j=0; j<attributeMap.length; j++)
nickjillings@1370 315 {
nickjillings@1370 316 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
nickjillings@1370 317 var projectAttr = ioNode.getAttribute(attributeName);
nickjillings@1370 318 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
nickjillings@1370 319 switch(typeof projectAttr)
nickjillings@1370 320 {
nickjillings@1370 321 case "number":
nickjillings@1370 322 case "boolean":
nickjillings@1370 323 eval('option.'+attributeName+' = '+projectAttr);
nickjillings@1370 324 break;
nickjillings@1370 325 case "string":
nickjillings@1370 326 eval('option.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 327 break;
nickjillings@1370 328 }
nickjillings@1370 329 }
nickjillings@1370 330 this.options.push(option);
nickjillings@1370 331 }
nickjillings@1370 332
nickjillings@1370 333 // Now the scales nodes
nickjillings@1370 334 var scaleParent = xml.getElementsByTagName('scales');
nickjillings@1370 335 if (scaleParent.length == 1) {
nickjillings@1370 336 scaleParent = scaleParent[0];
nickjillings@1370 337 for (var i=0; i<scaleParent.children.length; i++) {
nickjillings@1370 338 var child = scaleParent.children[i];
nickjillings@1370 339 this.scales.push({
nickjillings@1370 340 text: child.textContent,
nickjillings@1370 341 position: Number(child.getAttribute('position'))
nickjillings@1370 342 });
nickjillings@1370 343 }
nickjillings@1370 344 }
nickjillings@1370 345 };
nickjillings@1370 346
nickjillings@1372 347 this.encode = function(doc) {
nickjillings@1372 348 var node = doc.createElement("interface");
nickjillings@1372 349 if (typeof name == "string")
nickjillings@1372 350 node.setAttribute("name",this.name);
nickjillings@1372 351 for (var option of this.options)
nickjillings@1372 352 {
nickjillings@1372 353 var child = doc.createElement("interfaceoption");
nickjillings@1372 354 child.setAttribute("type",option.type);
nickjillings@1372 355 child.setAttribute("name",option.name);
nickjillings@1372 356 node.appendChild(child);
nickjillings@1372 357 }
nickjillings@1372 358 if (this.scales.length != 0) {
nickjillings@1372 359 var scales = doc.createElement("scales");
nickjillings@1372 360 for (var scale of this.scales)
nickjillings@1372 361 {
nickjillings@1372 362 var child = doc.createElement("scalelabel");
nickjillings@1372 363 child.setAttribute("position",scale.position);
nickjillings@1372 364 child.textContent = scale.text;
nickjillings@1372 365 scales.appendChild(child);
nickjillings@1372 366 }
nickjillings@1372 367 node.appendChild(scales);
nickjillings@1372 368 }
nickjillings@1372 369 return node;
nickjillings@1370 370 };
nickjillings@1370 371 };
nickjillings@1370 372
nickjillings@1370 373 this.metricNode = function() {
nickjillings@1370 374 this.enabled = [];
nickjillings@1370 375 this.decode = function(parent, xml) {
nickjillings@1370 376 var children = xml.getElementsByTagName('metricenable');
nickjillings@1370 377 for (var i in children) {
nickjillings@1370 378 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 379 this.enabled.push(children[i].textContent);
nickjillings@1370 380 }
nickjillings@1370 381 }
nickjillings@1372 382 this.encode = function(doc) {
nickjillings@1372 383 var node = doc.createElement('metric');
nickjillings@1370 384 for (var i in this.enabled)
nickjillings@1370 385 {
nickjillings@1370 386 if (isNaN(Number(i)) == true){break;}
nickjillings@1372 387 var child = doc.createElement('metricenable');
nickjillings@1370 388 child.textContent = this.enabled[i];
nickjillings@1370 389 node.appendChild(child);
nickjillings@1370 390 }
nickjillings@1370 391 return node;
nickjillings@1370 392 }
nickjillings@1370 393 }
nickjillings@1370 394
nickjillings@1370 395 this.page = function() {
nickjillings@1370 396 this.presentedId = undefined;
nickjillings@1370 397 this.id = undefined;
nickjillings@1370 398 this.hostURL = undefined;
nickjillings@1370 399 this.randomiseOrder = undefined;
nickjillings@1370 400 this.loop = undefined;
nickjillings@1370 401 this.showElementComments = undefined;
nickjillings@1370 402 this.outsideReference = null;
nickjillings@1370 403 this.loudness = null;
nickjillings@1370 404 this.preTest = null;
nickjillings@1370 405 this.postTest = null;
nickjillings@1370 406 this.interfaces = [];
nickjillings@1370 407 this.commentBoxPrefix = "Comment on track";
nickjillings@1370 408 this.audioElements = [];
nickjillings@1370 409 this.commentQuestions = [];
nickjillings@1370 410 this.schema = specification.schema.getAllElementsByName("page")[0];
nickjillings@1370 411
nickjillings@1370 412 this.decode = function(parent,xml)
nickjillings@1370 413 {
nickjillings@1370 414 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 415 for (var i=0; i<attributeMap.length; i++)
nickjillings@1370 416 {
nickjillings@1370 417 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 418 var projectAttr = xml.getAttribute(attributeName);
nickjillings@1370 419 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
nickjillings@1370 420 switch(typeof projectAttr)
nickjillings@1370 421 {
nickjillings@1370 422 case "number":
nickjillings@1370 423 case "boolean":
nickjillings@1370 424 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 425 break;
nickjillings@1370 426 case "string":
nickjillings@1370 427 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 428 break;
nickjillings@1370 429 }
nickjillings@1370 430 }
nickjillings@1370 431
nickjillings@1370 432 // Get the Comment Box Prefix
nickjillings@1370 433 var CBP = xml.getElementsByTagName('commentboxprefix');
nickjillings@1370 434 if (CBP.length != 0) {
nickjillings@1370 435 this.commentBoxPrefix = CBP[0].textContent;
nickjillings@1370 436 }
nickjillings@1370 437
nickjillings@1370 438 // Now decode the interfaces
nickjillings@1370 439 var interfaceNode = xml.getElementsByTagName('interface');
nickjillings@1370 440 for (var i=0; i<interfaceNode.length; i++)
nickjillings@1370 441 {
nickjillings@1370 442 var node = new parent.interfaceNode();
nickjillings@1370 443 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
nickjillings@1370 444 this.interfaces.push(node);
nickjillings@1370 445 }
nickjillings@1370 446
nickjillings@1370 447 // Now process the survey node options
nickjillings@1370 448 var survey = xml.getElementsByTagName('survey');
nickjillings@1370 449 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
nickjillings@1370 450 for (var i in survey) {
nickjillings@1370 451 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 452 var location = survey[i].getAttribute('location');
nickjillings@1370 453 if (location == 'pre' || location == 'before')
nickjillings@1370 454 {
nickjillings@1370 455 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@1370 456 else {
nickjillings@1370 457 this.preTest = new parent.surveyNode();
nickjillings@1370 458 this.preTest.decode(parent,survey[i],surveySchema);
nickjillings@1370 459 }
nickjillings@1370 460 } else if (location == 'post' || location == 'after') {
nickjillings@1370 461 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@1370 462 else {
nickjillings@1370 463 this.postTest = new parent.surveyNode();
nickjillings@1370 464 this.postTest.decode(parent,survey[i],surveySchema);
nickjillings@1370 465 }
nickjillings@1370 466 }
nickjillings@1370 467 }
nickjillings@1370 468
nickjillings@1370 469 // Now process the audioelement tags
nickjillings@1370 470 var audioElements = xml.getElementsByTagName('audioelement');
nickjillings@1370 471 for (var i=0; i<audioElements.length; i++)
nickjillings@1370 472 {
nickjillings@1370 473 var node = new this.audioElementNode();
nickjillings@1370 474 node.decode(this,audioElements[i]);
nickjillings@1370 475 this.audioElements.push(node);
nickjillings@1370 476 }
nickjillings@1370 477
nickjillings@1370 478 // Now decode the commentquestions
nickjillings@1370 479 var commentQuestions = xml.getElementsByTagName('commentquestion');
nickjillings@1370 480 for (var i=0; i<commentQuestions.length; i++)
nickjillings@1370 481 {
nickjillings@1370 482 var node = new this.commentQuestionNode();
nickjillings@1370 483 node.decode(parent,commentQuestions[i]);
nickjillings@1370 484 this.commentQuestions.push(node);
nickjillings@1370 485 }
nickjillings@1370 486 };
nickjillings@1370 487
nickjillings@1370 488 this.encode = function(root)
nickjillings@1370 489 {
nickjillings@1372 490 var AHNode = root.createElement("page");
nickjillings@1372 491 // First decode the attributes
nickjillings@1372 492 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1372 493 for (var i=0; i<attributes.length; i++)
nickjillings@1372 494 {
nickjillings@1372 495 var name = attributes[i].getAttribute("name");
nickjillings@1372 496 if (name == undefined) {
nickjillings@1372 497 name = attributes[i].getAttribute("ref");
nickjillings@1372 498 }
nickjillings@1372 499 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 500 {
nickjillings@1372 501 eval("AHNode.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 502 }
nickjillings@1372 503 }
nickjillings@1370 504 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
nickjillings@1372 505 // <commentboxprefix>
nickjillings@1372 506 var commentboxprefix = root.createElement("commentboxprefix");
nickjillings@1372 507 commentboxprefix.textContent = this.commentBoxPrefix;
nickjillings@1372 508 AHNode.appendChild(commentboxprefix);
nickjillings@1372 509
nickjillings@1370 510 for (var i=0; i<this.interfaces.length; i++)
nickjillings@1370 511 {
nickjillings@1370 512 AHNode.appendChild(this.interfaces[i].encode(root));
nickjillings@1370 513 }
nickjillings@1370 514
nickjillings@1370 515 for (var i=0; i<this.audioElements.length; i++) {
nickjillings@1370 516 AHNode.appendChild(this.audioElements[i].encode(root));
nickjillings@1370 517 }
nickjillings@1370 518 // Create <CommentQuestion>
nickjillings@1370 519 for (var i=0; i<this.commentQuestions.length; i++)
nickjillings@1370 520 {
nickjillings@1372 521 AHNode.appendChild(this.commentQuestions[i].encode(root));
nickjillings@1370 522 }
nickjillings@1370 523
nickjillings@1372 524 AHNode.appendChild(this.preTest.encode(root));
nickjillings@1372 525 AHNode.appendChild(this.postTest.encode(root));
nickjillings@1370 526 return AHNode;
nickjillings@1370 527 };
nickjillings@1370 528
nickjillings@1370 529 this.commentQuestionNode = function() {
nickjillings@1370 530 this.id = null;
nickjillings@1889 531 this.name = undefined;
nickjillings@1370 532 this.type = undefined;
nickjillings@1370 533 this.options = [];
nickjillings@1370 534 this.statement = undefined;
nickjillings@1370 535 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
nickjillings@1370 536 this.decode = function(parent,xml)
nickjillings@1370 537 {
nickjillings@1370 538 this.id = xml.id;
nickjillings@1889 539 this.name = xml.getAttribute('name');
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@1889 558 if (this.name != undefined){node.setAttribute("name",this.name);}
nickjillings@1372 559 var statement = root.createElement("statement");
nickjillings@1372 560 statement.textContent = this.statement;
nickjillings@1372 561 node.appendChild(statement);
nickjillings@1372 562 for (var option of this.options)
nickjillings@1372 563 {
nickjillings@1372 564 var child = root.createElement("option");
nickjillings@1372 565 child.setAttribute("name",option.name);
nickjillings@1372 566 child.textContent = option.text;
nickjillings@1372 567 node.appendChild(child);
nickjillings@1372 568 }
nickjillings@1372 569 return node;
nickjillings@1370 570 };
nickjillings@1370 571 };
nickjillings@1370 572
nickjillings@1370 573 this.audioElementNode = function() {
nickjillings@1370 574 this.url = null;
nickjillings@1370 575 this.id = null;
nickjillings@1889 576 this.name = null;
nickjillings@1370 577 this.parent = null;
nickjillings@1370 578 this.type = null;
nickjillings@1310 579 this.marker = null;
nickjillings@1370 580 this.enforce = false;
nickjillings@1863 581 this.gain = 0.0;
nickjillings@1370 582 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
nickjillings@1370 583 this.parent = null;
nickjillings@1370 584 this.decode = function(parent,xml)
nickjillings@1370 585 {
nickjillings@1370 586 this.parent = parent;
nickjillings@1370 587 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 588 for (var i=0; i<attributeMap.length; i++)
nickjillings@1370 589 {
nickjillings@1370 590 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 591 var projectAttr = xml.getAttribute(attributeName);
nickjillings@1370 592 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
nickjillings@1370 593 switch(typeof projectAttr)
nickjillings@1370 594 {
nickjillings@1370 595 case "number":
nickjillings@1370 596 case "boolean":
nickjillings@1370 597 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 598 break;
nickjillings@1370 599 case "string":
nickjillings@1370 600 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 601 break;
nickjillings@1370 602 }
nickjillings@1370 603 }
nickjillings@1370 604
nickjillings@1370 605 };
nickjillings@1370 606 this.encode = function(root)
nickjillings@1370 607 {
nickjillings@1372 608 var AENode = root.createElement("audioelement");
nickjillings@1372 609 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1372 610 for (var i=0; i<attributes.length; i++)
nickjillings@1370 611 {
nickjillings@1372 612 var name = attributes[i].getAttribute("name");
nickjillings@1372 613 if (name == undefined) {
nickjillings@1372 614 name = attributes[i].getAttribute("ref");
nickjillings@1372 615 }
nickjillings@1372 616 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 617 {
nickjillings@1372 618 eval("AENode.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 619 }
nickjillings@1370 620 }
nickjillings@1370 621 return AENode;
nickjillings@1370 622 };
nickjillings@1370 623 };
nickjillings@1370 624 };
nickjillings@1370 625 }
nickjillings@1372 626
nickjillings@1370 627 </script>
nickjillings@1381 628 <script src="../jquery-2.1.4.js"></script>
nickjillings@1370 629 <script type="text/javascript" src="test_core.js"/>
nickjillings@1370 630 <script type="text/javascript">
nickjillings@1370 631
nickjillings@1370 632 </script>
nickjillings@1370 633 </head>
nickjillings@1370 634 <body>
nickjillings@1370 635 <div id="popupHolder"></div>
nickjillings@1370 636 <div id="blanket"></div>
nickjillings@1370 637 <div id="content"></div>
nickjillings@1370 638 </body>
giuliomoro@1304 639 </html>