comparison test_create/test_create.html @ 1106:282dfb8076f5

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