annotate test_create/test_create.html @ 1373:65eecc71c381

Drag and drop area defined for updating a project file in test creator.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 10 Feb 2016 16:33:41 +0000
parents 25a33f2489e7
children 6a2e904c519f
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"/>
nickjillings@1370 5 <script type="text/javascript">
nickjillings@1370 6 // Copy of Specifiation node from Core.js
nickjillings@1370 7 function Specification() {
nickjillings@1370 8 // Handles the decoding of the project specification XML into a simple JavaScript Object.
nickjillings@1370 9
nickjillings@1370 10 this.interface = null;
nickjillings@1373 11 this.projectReturn = "null";
nickjillings@1370 12 this.randomiseOrder = null;
nickjillings@1370 13 this.testPages = null;
nickjillings@1370 14 this.pages = [];
nickjillings@1370 15 this.metrics = null;
nickjillings@1370 16 this.interfaces = null;
nickjillings@1370 17 this.loudness = null;
nickjillings@1370 18 this.errors = [];
nickjillings@1370 19 this.schema = null;
nickjillings@1370 20
nickjillings@1370 21 this.processAttribute = function(attribute,schema)
nickjillings@1370 22 {
nickjillings@1370 23 // attribute is the string returned from getAttribute on the XML
nickjillings@1370 24 // schema is the <xs:attribute> node
nickjillings@1370 25 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
nickjillings@1370 26 {
nickjillings@1370 27 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
nickjillings@1370 28 }
nickjillings@1370 29 var defaultOpt = schema.getAttribute('default');
nickjillings@1370 30 if (attribute == null) {
nickjillings@1370 31 attribute = defaultOpt;
nickjillings@1370 32 }
nickjillings@1370 33 var dataType = schema.getAttribute('type');
nickjillings@1370 34 if (typeof dataType == "string") { dataType = dataType.substr(3);}
nickjillings@1370 35 else {dataType = "string";}
nickjillings@1370 36 if (attribute == null)
nickjillings@1370 37 {
nickjillings@1370 38 return attribute;
nickjillings@1370 39 }
nickjillings@1370 40 switch(dataType)
nickjillings@1370 41 {
nickjillings@1370 42 case "boolean":
nickjillings@1370 43 if (attribute == 'true'){attribute = true;}else{attribute=false;}
nickjillings@1370 44 break;
nickjillings@1370 45 case "negativeInteger":
nickjillings@1370 46 case "positiveInteger":
nickjillings@1370 47 case "nonNegativeInteger":
nickjillings@1370 48 case "nonPositiveInteger":
nickjillings@1370 49 case "integer":
nickjillings@1370 50 case "decimal":
nickjillings@1370 51 case "short":
nickjillings@1370 52 attribute = Number(attribute);
nickjillings@1370 53 break;
nickjillings@1370 54 case "string":
nickjillings@1370 55 default:
nickjillings@1370 56 attribute = String(attribute);
nickjillings@1370 57 break;
nickjillings@1370 58 }
nickjillings@1370 59 return attribute;
nickjillings@1370 60 };
nickjillings@1370 61
nickjillings@1370 62 this.decode = function(projectXML) {
nickjillings@1370 63 this.errors = [];
nickjillings@1370 64 // projectXML - DOM Parsed document
nickjillings@1370 65 this.projectXML = projectXML.childNodes[0];
nickjillings@1370 66 var setupNode = projectXML.getElementsByTagName('setup')[0];
nickjillings@1370 67 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@1370 68 // First decode the attributes
nickjillings@1370 69 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@1370 70 for (var i in attributes)
nickjillings@1370 71 {
nickjillings@1370 72 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 73 var attributeName = attributes[i].getAttribute('name');
nickjillings@1370 74 var projectAttr = setupNode.getAttribute(attributeName);
nickjillings@1370 75 projectAttr = this.processAttribute(projectAttr,attributes[i]);
nickjillings@1370 76 switch(typeof projectAttr)
nickjillings@1370 77 {
nickjillings@1370 78 case "number":
nickjillings@1370 79 case "boolean":
nickjillings@1370 80 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 81 break;
nickjillings@1370 82 case "string":
nickjillings@1370 83 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 84 break;
nickjillings@1370 85 }
nickjillings@1370 86
nickjillings@1370 87 }
nickjillings@1370 88
nickjillings@1370 89 this.metrics = new this.metricNode();
nickjillings@1370 90
nickjillings@1370 91 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
nickjillings@1370 92
nickjillings@1370 93 // Now process the survey node options
nickjillings@1370 94 var survey = setupNode.getElementsByTagName('survey');
nickjillings@1370 95 for (var i in survey) {
nickjillings@1370 96 if (isNaN(Number(i)) == true){break;}
nickjillings@1370 97 var location = survey[i].getAttribute('location');
nickjillings@1370 98 if (location == 'pre' || location == 'before')
nickjillings@1370 99 {
nickjillings@1370 100 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
nickjillings@1370 101 else {
nickjillings@1370 102 this.preTest = new this.surveyNode();
nickjillings@1370 103 this.preTest.decode(this,survey[i]);
nickjillings@1370 104 }
nickjillings@1370 105 } else if (location == 'post' || location == 'after') {
nickjillings@1370 106 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
nickjillings@1370 107 else {
nickjillings@1370 108 this.postTest = new this.surveyNode();
nickjillings@1370 109 this.postTest.decode(this,survey[i]);
nickjillings@1370 110 }
nickjillings@1370 111 }
nickjillings@1370 112 }
nickjillings@1370 113
nickjillings@1370 114 var interfaceNode = setupNode.getElementsByTagName('interface');
nickjillings@1370 115 if (interfaceNode.length > 1)
nickjillings@1370 116 {
nickjillings@1370 117 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
nickjillings@1370 118 }
nickjillings@1370 119 this.interfaces = new this.interfaceNode();
nickjillings@1370 120 if (interfaceNode.length != 0)
nickjillings@1370 121 {
nickjillings@1370 122 interfaceNode = interfaceNode[0];
nickjillings@1370 123 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
nickjillings@1370 124 }
nickjillings@1370 125
nickjillings@1370 126 // Page tags
nickjillings@1370 127 var pageTags = projectXML.getElementsByTagName('page');
nickjillings@1370 128 var pageSchema = this.schema.getAllElementsByName('page')[0];
nickjillings@1370 129 for (var i=0; i<pageTags.length; i++)
nickjillings@1370 130 {
nickjillings@1370 131 var node = new this.page();
nickjillings@1370 132 node.decode(this,pageTags[i],pageSchema);
nickjillings@1370 133 this.pages.push(node);
nickjillings@1370 134 }
nickjillings@1370 135 };
nickjillings@1370 136
nickjillings@1370 137 this.encode = function()
nickjillings@1370 138 {
nickjillings@1372 139 var RootDocument = document.implementation.createDocument(null,"waet");
nickjillings@1372 140 var root = RootDocument.children[0];
nickjillings@1372 141 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
nickjillings@1372 142 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
nickjillings@1370 143 // Build setup node
nickjillings@1372 144 var setup = RootDocument.createElement("setup");
nickjillings@1372 145 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
nickjillings@1372 146 // First decode the attributes
nickjillings@1372 147 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
nickjillings@1372 148 for (var i=0; i<attributes.length; i++)
nickjillings@1372 149 {
nickjillings@1372 150 var name = attributes[i].getAttribute("name");
nickjillings@1372 151 if (name == undefined) {
nickjillings@1372 152 name = attributes[i].getAttribute("ref");
nickjillings@1372 153 }
nickjillings@1372 154 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 155 {
nickjillings@1372 156 eval("setup.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 157 }
nickjillings@1372 158 }
nickjillings@1372 159 root.appendChild(setup);
nickjillings@1372 160 // Survey node
nickjillings@1372 161 setup.appendChild(this.preTest.encode(RootDocument));
nickjillings@1372 162 setup.appendChild(this.postTest.encode(RootDocument));
nickjillings@1372 163 setup.appendChild(this.metrics.encode(RootDocument));
nickjillings@1372 164 setup.appendChild(this.interfaces.encode(RootDocument));
nickjillings@1372 165 for (var page of this.pages)
nickjillings@1372 166 {
nickjillings@1372 167 root.appendChild(page.encode(RootDocument));
nickjillings@1372 168 }
nickjillings@1372 169 return RootDocument;
nickjillings@1370 170 };
nickjillings@1370 171
nickjillings@1370 172 this.surveyNode = function() {
nickjillings@1370 173 this.location = null;
nickjillings@1370 174 this.options = [];
nickjillings@1370 175 this.schema = specification.schema.getAllElementsByName('survey')[0];
nickjillings@1370 176
nickjillings@1370 177 this.OptionNode = function() {
nickjillings@1370 178 this.type = undefined;
nickjillings@1370 179 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
nickjillings@1370 180 this.id = undefined;
nickjillings@1370 181 this.mandatory = undefined;
nickjillings@1370 182 this.statement = undefined;
nickjillings@1370 183 this.boxsize = undefined;
nickjillings@1370 184 this.options = [];
nickjillings@1370 185 this.min = undefined;
nickjillings@1370 186 this.max = undefined;
nickjillings@1370 187 this.step = undefined;
nickjillings@1370 188
nickjillings@1370 189 this.decode = function(parent,child)
nickjillings@1370 190 {
nickjillings@1370 191 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 192 for (var i in attributeMap){
nickjillings@1370 193 if(isNaN(Number(i)) == true){break;}
nickjillings@1370 194 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 195 var projectAttr = child.getAttribute(attributeName);
nickjillings@1370 196 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
nickjillings@1370 197 switch(typeof projectAttr)
nickjillings@1370 198 {
nickjillings@1370 199 case "number":
nickjillings@1370 200 case "boolean":
nickjillings@1370 201 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 202 break;
nickjillings@1370 203 case "string":
nickjillings@1370 204 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 205 break;
nickjillings@1370 206 }
nickjillings@1370 207 }
nickjillings@1370 208 this.statement = child.getElementsByTagName('statement')[0].textContent;
nickjillings@1370 209 if (this.type == "checkbox" || this.type == "radio") {
nickjillings@1370 210 var children = child.getElementsByTagName('option');
nickjillings@1370 211 if (children.length == null) {
nickjillings@1370 212 console.log('Malformed' +child.nodeName+ 'entry');
nickjillings@1370 213 this.statement = 'Malformed' +child.nodeName+ 'entry';
nickjillings@1370 214 this.type = 'statement';
nickjillings@1370 215 } else {
nickjillings@1370 216 this.options = [];
nickjillings@1370 217 for (var i in children)
nickjillings@1370 218 {
nickjillings@1370 219 if (isNaN(Number(i))==true){break;}
nickjillings@1370 220 this.options.push({
nickjillings@1370 221 name: children[i].getAttribute('name'),
nickjillings@1370 222 text: children[i].textContent
nickjillings@1370 223 });
nickjillings@1370 224 }
nickjillings@1370 225 }
nickjillings@1370 226 }
nickjillings@1370 227 };
nickjillings@1370 228
nickjillings@1372 229 this.exportXML = function(doc)
nickjillings@1370 230 {
nickjillings@1372 231 var node = doc.createElement('surveyelement');
nickjillings@1370 232 node.setAttribute('type',this.type);
nickjillings@1372 233 var statement = doc.createElement('statement');
nickjillings@1370 234 statement.textContent = this.statement;
nickjillings@1370 235 node.appendChild(statement);
nickjillings@1370 236 switch(this.type)
nickjillings@1370 237 {
nickjillings@1370 238 case "statement":
nickjillings@1370 239 break;
nickjillings@1370 240 case "question":
nickjillings@1370 241 node.id = this.id;
nickjillings@1370 242 node.setAttribute("mandatory",this.mandatory);
nickjillings@1370 243 node.setAttribute("boxsize",this.boxsize);
nickjillings@1370 244 break;
nickjillings@1370 245 case "number":
nickjillings@1370 246 node.id = this.id;
nickjillings@1370 247 node.setAttribute("mandatory",this.mandatory);
nickjillings@1370 248 node.setAttribute("min", this.min);
nickjillings@1370 249 node.setAttribute("max", this.max);
nickjillings@1370 250 node.setAttribute("step", this.step);
nickjillings@1370 251 break;
nickjillings@1370 252 case "checkbox":
nickjillings@1370 253 case "radio":
nickjillings@1370 254 node.id = this.id;
nickjillings@1370 255 for (var i=0; i<this.options.length; i++)
nickjillings@1370 256 {
nickjillings@1370 257 var option = this.options[i];
nickjillings@1372 258 var optionNode = doc.createElement("option");
nickjillings@1370 259 optionNode.setAttribute("name",option.name);
nickjillings@1370 260 optionNode.textContent = option.text;
nickjillings@1370 261 node.appendChild(optionNode);
nickjillings@1370 262 }
nickjillings@1370 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@1370 531 this.type = undefined;
nickjillings@1370 532 this.options = [];
nickjillings@1370 533 this.statement = undefined;
nickjillings@1370 534 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
nickjillings@1370 535 this.decode = function(parent,xml)
nickjillings@1370 536 {
nickjillings@1370 537 this.id = xml.id;
nickjillings@1370 538 this.type = xml.getAttribute('type');
nickjillings@1370 539 this.statement = xml.getElementsByTagName('statement')[0].textContent;
nickjillings@1370 540 var optNodes = xml.getElementsByTagName('option');
nickjillings@1370 541 for (var i=0; i<optNodes.length; i++)
nickjillings@1370 542 {
nickjillings@1370 543 var optNode = optNodes[i];
nickjillings@1370 544 this.options.push({
nickjillings@1370 545 name: optNode.getAttribute('name'),
nickjillings@1370 546 text: optNode.textContent
nickjillings@1370 547 });
nickjillings@1370 548 }
nickjillings@1370 549 };
nickjillings@1370 550
nickjillings@1370 551 this.encode = function(root)
nickjillings@1370 552 {
nickjillings@1372 553 var node = root.createElement("commentquestion");
nickjillings@1372 554 node.id = this.id;
nickjillings@1372 555 node.setAttribute("type",this.type);
nickjillings@1372 556 var statement = root.createElement("statement");
nickjillings@1372 557 statement.textContent = this.statement;
nickjillings@1372 558 node.appendChild(statement);
nickjillings@1372 559 for (var option of this.options)
nickjillings@1372 560 {
nickjillings@1372 561 var child = root.createElement("option");
nickjillings@1372 562 child.setAttribute("name",option.name);
nickjillings@1372 563 child.textContent = option.text;
nickjillings@1372 564 node.appendChild(child);
nickjillings@1372 565 }
nickjillings@1372 566 return node;
nickjillings@1370 567 };
nickjillings@1370 568 };
nickjillings@1370 569
nickjillings@1370 570 this.audioElementNode = function() {
nickjillings@1370 571 this.url = null;
nickjillings@1370 572 this.id = null;
nickjillings@1370 573 this.parent = null;
nickjillings@1370 574 this.type = null;
nickjillings@1370 575 this.marker = false;
nickjillings@1370 576 this.enforce = false;
nickjillings@1370 577 this.gain = 1.0;
nickjillings@1370 578 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
nickjillings@1370 579 this.parent = null;
nickjillings@1370 580 this.decode = function(parent,xml)
nickjillings@1370 581 {
nickjillings@1370 582 this.parent = parent;
nickjillings@1370 583 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1370 584 for (var i=0; i<attributeMap.length; i++)
nickjillings@1370 585 {
nickjillings@1370 586 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
nickjillings@1370 587 var projectAttr = xml.getAttribute(attributeName);
nickjillings@1370 588 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
nickjillings@1370 589 switch(typeof projectAttr)
nickjillings@1370 590 {
nickjillings@1370 591 case "number":
nickjillings@1370 592 case "boolean":
nickjillings@1370 593 eval('this.'+attributeName+' = '+projectAttr);
nickjillings@1370 594 break;
nickjillings@1370 595 case "string":
nickjillings@1370 596 eval('this.'+attributeName+' = "'+projectAttr+'"');
nickjillings@1370 597 break;
nickjillings@1370 598 }
nickjillings@1370 599 }
nickjillings@1370 600
nickjillings@1370 601 };
nickjillings@1370 602 this.encode = function(root)
nickjillings@1370 603 {
nickjillings@1372 604 var AENode = root.createElement("audioelement");
nickjillings@1372 605 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
nickjillings@1372 606 for (var i=0; i<attributes.length; i++)
nickjillings@1370 607 {
nickjillings@1372 608 var name = attributes[i].getAttribute("name");
nickjillings@1372 609 if (name == undefined) {
nickjillings@1372 610 name = attributes[i].getAttribute("ref");
nickjillings@1372 611 }
nickjillings@1372 612 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
nickjillings@1372 613 {
nickjillings@1372 614 eval("AENode.setAttribute('"+name+"',this."+name+")");
nickjillings@1372 615 }
nickjillings@1370 616 }
nickjillings@1370 617 return AENode;
nickjillings@1370 618 };
nickjillings@1370 619 };
nickjillings@1370 620 };
nickjillings@1370 621 }
nickjillings@1372 622
nickjillings@1370 623 </script>
nickjillings@1370 624 <script type="text/javascript" src="test_core.js"/>
nickjillings@1370 625 <script type="text/javascript">
nickjillings@1370 626
nickjillings@1370 627 </script>
nickjillings@1370 628 </head>
nickjillings@1370 629 <body>
nickjillings@1370 630 <div id="popupHolder"></div>
nickjillings@1370 631 <div id="blanket"></div>
nickjillings@1370 632 <div id="content"></div>
nickjillings@1370 633 </body>
nickjillings@1370 634 </html>