annotate test_create/test_create.html @ 1303:ade3acb0cee3

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