Mercurial > hg > webaudioevaluationtool
comparison js/specification.js @ 2579:d83b38564fbb
#137. Modified <commentquestion> nodes in pages to have a proper list structure. Differently labelled nodes depending on type <commentquestion>, <commentradio>. Added slider and converted project.xml to match new specifications. AB_example.xml shows new slider type
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Sun, 30 Oct 2016 13:57:37 +0000 |
parents | 249a1152e525 |
children | a6b32c473577 |
comparison
equal
deleted
inserted
replaced
2578:bf17cc19c1c0 | 2579:d83b38564fbb |
---|---|
493 this.specification = specification; | 493 this.specification = specification; |
494 this.parent = null; | 494 this.parent = null; |
495 | 495 |
496 this.decode = function (parent, xml) { | 496 this.decode = function (parent, xml) { |
497 this.parent = parent; | 497 this.parent = parent; |
498 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); | 498 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
499 for (var i=0; i<attributeMap.length; i++) | 499 for (var i = 0; i < attributeMap.length; i++) { |
500 { | 500 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
501 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 501 var projectAttr = xml.getAttribute(attributeName); |
502 var projectAttr = xml.getAttribute(attributeName); | 502 projectAttr = parent.processAttribute(projectAttr, attributeMap[i], parent.schema); |
503 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema); | 503 switch (typeof projectAttr) { |
504 switch(typeof projectAttr) | 504 case "number": |
505 { | 505 case "boolean": |
506 case "number": | 506 eval('this.' + attributeName + ' = ' + projectAttr); |
507 case "boolean": | 507 break; |
508 eval('this.'+attributeName+' = '+projectAttr); | 508 case "string": |
509 break; | 509 eval('this.' + attributeName + ' = "' + projectAttr + '"'); |
510 case "string": | 510 break; |
511 eval('this.'+attributeName+' = "'+projectAttr+'"'); | 511 } |
512 break; | 512 } |
513 } | 513 |
514 } | |
515 | |
516 // Get the title | 514 // Get the title |
517 var title = xml.getElementsByTagName('title'); | 515 var title = xml.getElementsByTagName('title'); |
518 if (title.length != 0 && title[0].parentElement == xml) { | 516 if (title.length != 0 && title[0].parentElement == xml) { |
519 this.title = title[0].textContent; | 517 this.title = title[0].textContent; |
520 } | 518 } |
521 | 519 |
522 // Get the Comment Box Prefix | 520 // Get the Comment Box Prefix |
523 var CBP = xml.getElementsByTagName('commentboxprefix'); | 521 var CBP = xml.getElementsByTagName('commentboxprefix'); |
524 if (CBP.length != 0 && CBP[0].parentElement == xml) { | 522 if (CBP.length != 0 && CBP[0].parentElement == xml) { |
525 this.commentBoxPrefix = CBP[0].textContent; | 523 this.commentBoxPrefix = CBP[0].textContent; |
526 } | 524 } |
527 | 525 |
528 // Now decode the interfaces | 526 // Now decode the interfaces |
529 var interfaceNode = xml.getElementsByTagName('interface'); | 527 var interfaceNode = xml.getElementsByTagName('interface'); |
530 for (var i=0; i<interfaceNode.length; i++) | 528 for (var i = 0; i < interfaceNode.length; i++) { |
531 { | 529 var node = new parent.interfaceNode(this.specification); |
532 var node = new parent.interfaceNode(this.specification); | 530 node.decode(this, interfaceNode[i], parent.schema.getAllElementsByName('interface')[1]); |
533 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]); | 531 this.interfaces.push(node); |
534 this.interfaces.push(node); | 532 } |
535 } | 533 |
536 | 534 // Now process the survey node options |
537 // Now process the survey node options | 535 var survey = xml.getElementsByTagName('survey'); |
538 var survey = xml.getElementsByTagName('survey'); | 536 var surveySchema = parent.schema.getAllElementsByName('survey')[0]; |
539 var surveySchema = parent.schema.getAllElementsByName('survey')[0]; | 537 for (var i = 0; i < survey.length; i++) { |
540 for (var i=0; i<survey.length; i++){ | 538 var location = survey[i].getAttribute('location'); |
541 var location = survey[i].getAttribute('location'); | 539 if (location == 'pre' || location == 'before') { |
542 if (location == 'pre' || location == 'before') | 540 if (this.preTest != null) { |
543 { | 541 this.errors.push("Already a pre/before test survey defined! Ignoring second!!"); |
544 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} | 542 } else { |
545 else { | 543 this.preTest = new parent.surveyNode(this.specification); |
546 this.preTest = new parent.surveyNode(this.specification); | 544 this.preTest.decode(parent, survey[i], surveySchema); |
547 this.preTest.decode(parent,survey[i],surveySchema); | 545 } |
548 } | 546 } else if (location == 'post' || location == 'after') { |
549 } else if (location == 'post' || location == 'after') { | 547 if (this.postTest != null) { |
550 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} | 548 this.errors.push("Already a post/after test survey defined! Ignoring second!!"); |
551 else { | 549 } else { |
552 this.postTest = new parent.surveyNode(this.specification); | 550 this.postTest = new parent.surveyNode(this.specification); |
553 this.postTest.decode(parent,survey[i],surveySchema); | 551 this.postTest.decode(parent, survey[i], surveySchema); |
554 } | 552 } |
555 } | 553 } |
556 } | 554 } |
557 | 555 |
558 // Now process the audioelement tags | 556 // Now process the audioelement tags |
559 var audioElements = xml.getElementsByTagName('audioelement'); | 557 var audioElements = xml.getElementsByTagName('audioelement'); |
560 for (var i=0; i<audioElements.length; i++) | 558 for (var i = 0; i < audioElements.length; i++) { |
561 { | 559 var node = new this.audioElementNode(this.specification); |
562 var node = new this.audioElementNode(this.specification); | 560 node.decode(this, audioElements[i]); |
563 node.decode(this,audioElements[i]); | 561 this.audioElements.push(node); |
564 this.audioElements.push(node); | 562 } |
565 } | 563 |
566 | 564 // Now decode the commentquestions |
567 // Now decode the commentquestions | 565 var cqNode = xml.getElementsByTagName('commentquestions'); |
568 var commentQuestions = xml.getElementsByTagName('commentquestion'); | 566 if (cqNode.length != 0) { |
569 for (var i=0; i<commentQuestions.length; i++) | 567 cqNode = cqNode[0]; |
570 { | 568 var commentQuestions = cqNode.children; |
571 var node = new this.commentQuestionNode(this.specification); | 569 for (var i = 0; i < commentQuestions.length; i++) { |
572 node.decode(parent,commentQuestions[i]); | 570 var node = new this.commentQuestionNode(this.specification); |
573 this.commentQuestions.push(node); | 571 node.decode(parent, commentQuestions[i]); |
574 } | 572 this.commentQuestions.push(node); |
575 }; | 573 } |
576 | 574 } |
577 this.encode = function(root) | 575 }; |
578 { | 576 |
579 var AHNode = root.createElement("page"); | 577 this.encode = function (root) { |
578 var AHNode = root.createElement("page"); | |
580 // First decode the attributes | 579 // First decode the attributes |
581 var attributes = this.schema.getAllElementsByTagName('xs:attribute'); | 580 var attributes = this.schema.getAllElementsByTagName('xs:attribute'); |
582 for (var i = 0; i < attributes.length; i++) { | 581 for (var i = 0; i < attributes.length; i++) { |
583 var name = attributes[i].getAttribute("name"); | 582 var name = attributes[i].getAttribute("name"); |
584 if (name == undefined) { | 583 if (name == undefined) { |
615 | 614 |
616 this.commentQuestionNode = function (specification) { | 615 this.commentQuestionNode = function (specification) { |
617 this.id = null; | 616 this.id = null; |
618 this.name = undefined; | 617 this.name = undefined; |
619 this.type = undefined; | 618 this.type = undefined; |
620 this.options = []; | |
621 this.statement = undefined; | 619 this.statement = undefined; |
622 this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; | 620 this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; |
623 this.decode = function (parent, xml) { | 621 this.decode = function (parent, xml) { |
624 this.id = xml.id; | 622 this.id = xml.id; |
625 this.name = xml.getAttribute('name'); | 623 this.name = xml.getAttribute('name'); |
626 this.type = xml.getAttribute('type'); | 624 switch (xml.nodeName) { |
625 case "commentradio": | |
626 this.type = "radio"; | |
627 this.options = []; | |
628 break; | |
629 case "commentcheckbox": | |
630 this.type = "checkbox"; | |
631 this.options = []; | |
632 break; | |
633 case "commentslider": | |
634 this.type = "slider"; | |
635 this.min = undefined; | |
636 this.max = undefined; | |
637 this.step = undefined; | |
638 break; | |
639 case "commentquestion": | |
640 default: | |
641 this.type = "question"; | |
642 break; | |
643 } | |
627 this.statement = xml.getElementsByTagName('statement')[0].textContent; | 644 this.statement = xml.getElementsByTagName('statement')[0].textContent; |
628 var optNodes = xml.getElementsByTagName('option'); | 645 if (this.type == "radio" || this.type == "checkbox") { |
629 for (var i = 0; i < optNodes.length; i++) { | 646 var optNodes = xml.getElementsByTagName('option'); |
630 var optNode = optNodes[i]; | 647 for (var i = 0; i < optNodes.length; i++) { |
631 this.options.push({ | 648 var optNode = optNodes[i]; |
632 name: optNode.getAttribute('name'), | 649 this.options.push({ |
633 text: optNode.textContent | 650 name: optNode.getAttribute('name'), |
634 }); | 651 text: optNode.textContent |
652 }); | |
653 } | |
654 } | |
655 if (this.type == "slider") { | |
656 this.min = Number(xml.getAttribute("min")); | |
657 this.max = Number(xml.getAttribute("max")); | |
658 this.step = Number(xml.getAttribute("step")); | |
659 if (this.step == undefined) { | |
660 this.step = 1; | |
661 } | |
662 this.value = Number(xml.getAttribute("value")); | |
663 if (this.value == undefined) { | |
664 this.value = min; | |
665 } | |
635 } | 666 } |
636 }; | 667 }; |
637 | 668 |
638 this.encode = function (root) { | 669 this.encode = function (root) { |
639 var node = root.createElement("commentquestion"); | 670 var node; |
671 switch (this.type) { | |
672 case "radio": | |
673 node = root.createElement("commentradio"); | |
674 break; | |
675 case "checkbox": | |
676 node = root.createElement("commentcheckbox"); | |
677 break; | |
678 case "slider": | |
679 node = root.createElement("commentslider"); | |
680 break; | |
681 case "question": | |
682 default: | |
683 node = root.createElement("commentquestion"); | |
684 break; | |
685 } | |
640 node.id = this.id; | 686 node.id = this.id; |
641 node.setAttribute("type", this.type); | 687 node.setAttribute("type", this.type); |
642 if (this.name != undefined) { | 688 if (this.name != undefined) { |
643 node.setAttribute("name", this.name); | 689 node.setAttribute("name", this.name); |
644 } | 690 } |
645 var statement = root.createElement("statement"); | 691 var statement = root.createElement("statement"); |
646 statement.textContent = this.statement; | 692 statement.textContent = this.statement; |
647 node.appendChild(statement); | 693 node.appendChild(statement); |
648 for (var option of this.options) { | 694 if (this.type == "radio" || this.type == "checkbox") { |
649 var child = root.createElement("option"); | 695 for (var option of this.options) { |
650 child.setAttribute("name", option.name); | 696 var child = root.createElement("option"); |
651 child.textContent = option.text; | 697 child.setAttribute("name", option.name); |
652 node.appendChild(child); | 698 child.textContent = option.text; |
699 node.appendChild(child); | |
700 } | |
701 } | |
702 if (this.type == "slider") { | |
703 node.setAttribute("min", this.min); | |
704 node.setAttribute("max", this.max); | |
705 if (this.step !== 1) { | |
706 node.setAttribute("step", this.step); | |
707 } | |
708 if (this.value !== this.min) { | |
709 node.setAttribute("value", this.value); | |
710 } | |
653 } | 711 } |
654 return node; | 712 return node; |
655 }; | 713 }; |
656 }; | 714 }; |
657 | 715 |