comparison test_create/test_create.html @ 1090:c07b9e2312ba

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