comparison test_create/test_create.html @ 1088:3705f68a38b7

The version I use and works, addresses issues #1622, #1616, partially #1620
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 22 Feb 2016 04:17:19 +0000
parents
children 9ee921c8cdd3
comparison
equal deleted inserted replaced
-1:000000000000 1088:3705f68a38b7
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('surveyelement');
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 node.setAttribute("mandatory",this.mandatory);
245 node.setAttribute("boxsize",this.boxsize);
246 break;
247 case "number":
248 node.id = this.id;
249 node.setAttribute("mandatory",this.mandatory);
250 node.setAttribute("min", this.min);
251 node.setAttribute("max", this.max);
252 node.setAttribute("step", this.step);
253 break;
254 case "checkbox":
255 case "radio":
256 node.id = this.id;
257 for (var i=0; i<this.options.length; i++)
258 {
259 var option = this.options[i];
260 var optionNode = doc.createElement("option");
261 optionNode.setAttribute("name",option.name);
262 optionNode.textContent = option.text;
263 node.appendChild(optionNode);
264 }
265 break;
266 }
267 return node;
268 };
269 };
270 this.decode = function(parent,xml) {
271 this.location = xml.getAttribute('location');
272 if (this.location == 'before'){this.location = 'pre';}
273 else if (this.location == 'after'){this.location = 'post';}
274 for (var i in xml.children)
275 {
276 if(isNaN(Number(i))==true){break;}
277 var node = new this.OptionNode();
278 node.decode(parent,xml.children[i]);
279 this.options.push(node);
280 }
281 };
282 this.encode = function(doc) {
283 var node = doc.createElement('survey');
284 node.setAttribute('location',this.location);
285 for (var i=0; i<this.options.length; i++)
286 {
287 node.appendChild(this.options[i].exportXML(doc));
288 }
289 return node;
290 };
291 };
292
293 this.interfaceNode = function()
294 {
295 this.title = null;
296 this.name = null;
297 this.options = [];
298 this.scales = [];
299 this.schema = specification.schema.getAllElementsByName('interface')[1];
300
301 this.decode = function(parent,xml) {
302 this.name = xml.getAttribute('name');
303 var titleNode = xml.getElementsByTagName('title');
304 if (titleNode.length == 1)
305 {
306 this.title = titleNode[0].textContent;
307 }
308 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
309 // Extract interfaceoption node schema
310 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
311 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
312 for (var i=0; i<interfaceOptionNodes.length; i++)
313 {
314 var ioNode = interfaceOptionNodes[i];
315 var option = {};
316 for (var j=0; j<attributeMap.length; j++)
317 {
318 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
319 var projectAttr = ioNode.getAttribute(attributeName);
320 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
321 switch(typeof projectAttr)
322 {
323 case "number":
324 case "boolean":
325 eval('option.'+attributeName+' = '+projectAttr);
326 break;
327 case "string":
328 eval('option.'+attributeName+' = "'+projectAttr+'"');
329 break;
330 }
331 }
332 this.options.push(option);
333 }
334
335 // Now the scales nodes
336 var scaleParent = xml.getElementsByTagName('scales');
337 if (scaleParent.length == 1) {
338 scaleParent = scaleParent[0];
339 for (var i=0; i<scaleParent.children.length; i++) {
340 var child = scaleParent.children[i];
341 this.scales.push({
342 text: child.textContent,
343 position: Number(child.getAttribute('position'))
344 });
345 }
346 }
347 };
348
349 this.encode = function(doc) {
350 var node = doc.createElement("interface");
351 if (typeof name == "string")
352 node.setAttribute("name",this.name);
353 for (var option of this.options)
354 {
355 var child = doc.createElement("interfaceoption");
356 child.setAttribute("type",option.type);
357 child.setAttribute("name",option.name);
358 node.appendChild(child);
359 }
360 if (this.scales.length != 0) {
361 var scales = doc.createElement("scales");
362 for (var scale of this.scales)
363 {
364 var child = doc.createElement("scalelabel");
365 child.setAttribute("position",scale.position);
366 child.textContent = scale.text;
367 scales.appendChild(child);
368 }
369 node.appendChild(scales);
370 }
371 return node;
372 };
373 };
374
375 this.metricNode = function() {
376 this.enabled = [];
377 this.decode = function(parent, xml) {
378 var children = xml.getElementsByTagName('metricenable');
379 for (var i in children) {
380 if (isNaN(Number(i)) == true){break;}
381 this.enabled.push(children[i].textContent);
382 }
383 }
384 this.encode = function(doc) {
385 var node = doc.createElement('metric');
386 for (var i in this.enabled)
387 {
388 if (isNaN(Number(i)) == true){break;}
389 var child = doc.createElement('metricenable');
390 child.textContent = this.enabled[i];
391 node.appendChild(child);
392 }
393 return node;
394 }
395 }
396
397 this.page = function() {
398 this.presentedId = undefined;
399 this.id = undefined;
400 this.hostURL = undefined;
401 this.randomiseOrder = undefined;
402 this.loop = undefined;
403 this.showElementComments = undefined;
404 this.outsideReference = null;
405 this.loudness = null;
406 this.preTest = null;
407 this.postTest = null;
408 this.interfaces = [];
409 this.commentBoxPrefix = "Comment on track";
410 this.audioElements = [];
411 this.commentQuestions = [];
412 this.schema = specification.schema.getAllElementsByName("page")[0];
413
414 this.decode = function(parent,xml)
415 {
416 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
417 for (var i=0; i<attributeMap.length; i++)
418 {
419 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
420 var projectAttr = xml.getAttribute(attributeName);
421 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
422 switch(typeof projectAttr)
423 {
424 case "number":
425 case "boolean":
426 eval('this.'+attributeName+' = '+projectAttr);
427 break;
428 case "string":
429 eval('this.'+attributeName+' = "'+projectAttr+'"');
430 break;
431 }
432 }
433
434 // Get the Comment Box Prefix
435 var CBP = xml.getElementsByTagName('commentboxprefix');
436 if (CBP.length != 0) {
437 this.commentBoxPrefix = CBP[0].textContent;
438 }
439
440 // Now decode the interfaces
441 var interfaceNode = xml.getElementsByTagName('interface');
442 for (var i=0; i<interfaceNode.length; i++)
443 {
444 var node = new parent.interfaceNode();
445 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
446 this.interfaces.push(node);
447 }
448
449 // Now process the survey node options
450 var survey = xml.getElementsByTagName('survey');
451 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
452 for (var i in survey) {
453 if (isNaN(Number(i)) == true){break;}
454 var location = survey[i].getAttribute('location');
455 if (location == 'pre' || location == 'before')
456 {
457 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
458 else {
459 this.preTest = new parent.surveyNode();
460 this.preTest.decode(parent,survey[i],surveySchema);
461 }
462 } else if (location == 'post' || location == 'after') {
463 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
464 else {
465 this.postTest = new parent.surveyNode();
466 this.postTest.decode(parent,survey[i],surveySchema);
467 }
468 }
469 }
470
471 // Now process the audioelement tags
472 var audioElements = xml.getElementsByTagName('audioelement');
473 for (var i=0; i<audioElements.length; i++)
474 {
475 var node = new this.audioElementNode();
476 node.decode(this,audioElements[i]);
477 this.audioElements.push(node);
478 }
479
480 // Now decode the commentquestions
481 var commentQuestions = xml.getElementsByTagName('commentquestion');
482 for (var i=0; i<commentQuestions.length; i++)
483 {
484 var node = new this.commentQuestionNode();
485 node.decode(parent,commentQuestions[i]);
486 this.commentQuestions.push(node);
487 }
488 };
489
490 this.encode = function(root)
491 {
492 var AHNode = root.createElement("page");
493 // First decode the attributes
494 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
495 for (var i=0; i<attributes.length; i++)
496 {
497 var name = attributes[i].getAttribute("name");
498 if (name == undefined) {
499 name = attributes[i].getAttribute("ref");
500 }
501 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
502 {
503 eval("AHNode.setAttribute('"+name+"',this."+name+")");
504 }
505 }
506 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
507 // <commentboxprefix>
508 var commentboxprefix = root.createElement("commentboxprefix");
509 commentboxprefix.textContent = this.commentBoxPrefix;
510 AHNode.appendChild(commentboxprefix);
511
512 for (var i=0; i<this.interfaces.length; i++)
513 {
514 AHNode.appendChild(this.interfaces[i].encode(root));
515 }
516
517 for (var i=0; i<this.audioElements.length; i++) {
518 AHNode.appendChild(this.audioElements[i].encode(root));
519 }
520 // Create <CommentQuestion>
521 for (var i=0; i<this.commentQuestions.length; i++)
522 {
523 AHNode.appendChild(this.commentQuestions[i].encode(root));
524 }
525
526 AHNode.appendChild(this.preTest.encode(root));
527 AHNode.appendChild(this.postTest.encode(root));
528 return AHNode;
529 };
530
531 this.commentQuestionNode = function() {
532 this.id = null;
533 this.type = undefined;
534 this.options = [];
535 this.statement = undefined;
536 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
537 this.decode = function(parent,xml)
538 {
539 this.id = xml.id;
540 this.type = xml.getAttribute('type');
541 this.statement = xml.getElementsByTagName('statement')[0].textContent;
542 var optNodes = xml.getElementsByTagName('option');
543 for (var i=0; i<optNodes.length; i++)
544 {
545 var optNode = optNodes[i];
546 this.options.push({
547 name: optNode.getAttribute('name'),
548 text: optNode.textContent
549 });
550 }
551 };
552
553 this.encode = function(root)
554 {
555 var node = root.createElement("commentquestion");
556 node.id = this.id;
557 node.setAttribute("type",this.type);
558 var statement = root.createElement("statement");
559 statement.textContent = this.statement;
560 node.appendChild(statement);
561 for (var option of this.options)
562 {
563 var child = root.createElement("option");
564 child.setAttribute("name",option.name);
565 child.textContent = option.text;
566 node.appendChild(child);
567 }
568 return node;
569 };
570 };
571
572 this.audioElementNode = function() {
573 this.url = null;
574 this.id = null;
575 this.parent = null;
576 this.type = null;
577 this.marker = null;
578 this.enforce = false;
579 this.gain = 1.0;
580 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
581 this.parent = null;
582 this.decode = function(parent,xml)
583 {
584 this.parent = parent;
585 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
586 for (var i=0; i<attributeMap.length; i++)
587 {
588 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
589 var projectAttr = xml.getAttribute(attributeName);
590 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
591 switch(typeof projectAttr)
592 {
593 case "number":
594 case "boolean":
595 eval('this.'+attributeName+' = '+projectAttr);
596 break;
597 case "string":
598 eval('this.'+attributeName+' = "'+projectAttr+'"');
599 break;
600 }
601 }
602
603 };
604 this.encode = function(root)
605 {
606 var AENode = root.createElement("audioelement");
607 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
608 for (var i=0; i<attributes.length; i++)
609 {
610 var name = attributes[i].getAttribute("name");
611 if (name == undefined) {
612 name = attributes[i].getAttribute("ref");
613 }
614 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
615 {
616 eval("AENode.setAttribute('"+name+"',this."+name+")");
617 }
618 }
619 return AENode;
620 };
621 };
622 };
623 }
624
625 </script>
626 <script src="../jquery-2.1.4.js"></script>
627 <script type="text/javascript" src="test_core.js"/>
628 <script type="text/javascript">
629
630 </script>
631 </head>
632 <body>
633 <div id="popupHolder"></div>
634 <div id="blanket"></div>
635 <div id="content"></div>
636 </body>
637 </html>