Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2926:151fae569ce9
Implemented #225
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 06 Sep 2017 14:47:19 +0100 |
parents | 4ae62d4c5c6d |
children | 5d7e33fd00d8 3342bc1f3256 |
comparison
equal
deleted
inserted
replaced
2925:21d548eb40f1 | 2926:151fae569ce9 |
---|---|
669 processConditional.call(this, node, textArea.value); | 669 processConditional.call(this, node, textArea.value); |
670 return true; | 670 return true; |
671 } | 671 } |
672 | 672 |
673 function postCheckbox(node) { | 673 function postCheckbox(node) { |
674 if (node.response === undefined) { | 674 if (node.response === null) { |
675 node.response = Array(node.specification.options.length); | 675 node.response = []; |
676 } | 676 } |
677 var table = document.createElement("table"); | 677 var table = document.createElement("table"); |
678 table.className = "popup-option-list"; | 678 table.className = "popup-option-list"; |
679 table.border = "0"; | 679 table.border = "0"; |
680 node.response = []; | |
681 var nodelist = []; | 680 var nodelist = []; |
682 node.specification.options.forEach(function (option, index) { | 681 node.specification.options.forEach(function (option, index) { |
683 var tr = document.createElement("tr"); | 682 var tr = document.createElement("tr"); |
684 nodelist.push(tr); | 683 nodelist.push(tr); |
685 var td = document.createElement("td"); | 684 var td = document.createElement("td"); |
695 span.textContent = option.text; | 694 span.textContent = option.text; |
696 td.appendChild(span); | 695 td.appendChild(span); |
697 tr = document.createElement('div'); | 696 tr = document.createElement('div'); |
698 tr.setAttribute('name', 'option'); | 697 tr.setAttribute('name', 'option'); |
699 tr.className = "popup-option-checbox"; | 698 tr.className = "popup-option-checbox"; |
700 if (node.response[index] !== undefined) { | 699 var resp = undefined; |
701 if (node.response[index].checked === true) { | 700 if (node.response.length > 0) { |
701 resp = node.response.find(function (a) { | |
702 return a.name == option.name; | |
703 }); | |
704 } | |
705 if (resp !== undefined) { | |
706 if (resp.checked === true) { | |
702 input.checked = "true"; | 707 input.checked = "true"; |
703 } | 708 } |
709 } else { | |
710 node.response.push({ | |
711 "name": option.name, | |
712 "text": option.text, | |
713 "checked": false | |
714 }); | |
704 } | 715 } |
705 index++; | 716 index++; |
706 }); | 717 }); |
707 if (node.specification.randomise) { | 718 if (node.specification.randomise) { |
708 nodelist = randomiseOrder(nodelist); | 719 nodelist = randomiseOrder(nodelist); |
714 } | 725 } |
715 | 726 |
716 function processCheckbox(node) { | 727 function processCheckbox(node) { |
717 console.log("Checkbox: " + node.specification.statement); | 728 console.log("Checkbox: " + node.specification.statement); |
718 var inputs = this.popupResponse.getElementsByTagName('input'); | 729 var inputs = this.popupResponse.getElementsByTagName('input'); |
719 node.response = []; | |
720 var numChecked = 0, | 730 var numChecked = 0, |
721 i; | 731 i; |
722 for (i = 0; i < node.specification.options.length; i++) { | 732 for (i = 0; i < node.specification.options.length; i++) { |
723 if (inputs[i].checked) { | 733 if (inputs[i].checked) { |
724 numChecked++; | 734 numChecked++; |
744 return false; | 754 return false; |
745 } | 755 } |
746 } | 756 } |
747 } | 757 } |
748 for (i = 0; i < node.specification.options.length; i++) { | 758 for (i = 0; i < node.specification.options.length; i++) { |
749 node.response.push({ | 759 node.response.forEach(function (a) { |
750 name: node.specification.options[i].name, | 760 var input = this.popupResponse.querySelector("#" + a.name); |
751 text: node.specification.options[i].text, | 761 a.checked = input.checked; |
752 checked: inputs[i].checked | |
753 }); | 762 }); |
754 console.log(node.specification.options[i].name + ": " + inputs[i].checked); | 763 console.log(node.specification.options[i].name + ": " + inputs[i].checked); |
755 } | 764 } |
756 processConditional.call(this, node, node.response); | 765 processConditional.call(this, node, node.response); |
757 return true; | 766 return true; |
787 }; | 796 }; |
788 } | 797 } |
789 var table = document.createElement("table"); | 798 var table = document.createElement("table"); |
790 table.className = "popup-option-list"; | 799 table.className = "popup-option-list"; |
791 table.border = "0"; | 800 table.border = "0"; |
792 if (node.response === null || node.response.length === 0) { | 801 var nodelist = []; |
793 node.response = []; | |
794 } | |
795 node.specification.options.forEach(function (option, index) { | 802 node.specification.options.forEach(function (option, index) { |
796 var tr = document.createElement("tr"); | 803 var tr = document.createElement("tr"); |
797 table.appendChild(tr); | 804 nodelist.push(tr); |
798 var td = document.createElement("td"); | 805 var td = document.createElement("td"); |
799 tr.appendChild(td); | 806 tr.appendChild(td); |
800 var input = document.createElement('input'); | 807 var input = document.createElement('input'); |
801 input.id = option.name; | 808 input.id = option.name; |
802 input.type = 'radio'; | 809 input.type = 'radio'; |
808 var span = document.createElement('span'); | 815 var span = document.createElement('span'); |
809 span.textContent = option.text; | 816 span.textContent = option.text; |
810 td.appendChild(span); | 817 td.appendChild(span); |
811 tr = document.createElement('div'); | 818 tr = document.createElement('div'); |
812 tr.setAttribute('name', 'option'); | 819 tr.setAttribute('name', 'option'); |
813 tr.className = "popup-option-checbox"; | 820 tr.className = "popup-option-checkbox"; |
814 table.appendChild(tr); | 821 if (node.response.name === option.name) { |
822 input.checked = true; | |
823 } | |
824 }); | |
825 if (node.specification.randomise) { | |
826 nodelist = randomiseOrder(nodelist); | |
827 } | |
828 nodelist.forEach(function (e) { | |
829 table.appendChild(e); | |
815 }); | 830 }); |
816 this.popupResponse.appendChild(table); | 831 this.popupResponse.appendChild(table); |
817 } | 832 } |
818 | 833 |
819 function processRadio(node) { | 834 function processRadio(node) { |