Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1588:a64c6a1d869c
Added check box mode to pre/post test survey
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Fri, 05 Jun 2015 12:10:49 +0100 |
parents | c6ef0ce95e4a |
children | dd36d98cd4f9 |
comparison
equal
deleted
inserted
replaced
1587:c6ef0ce95e4a | 1588:a64c6a1d869c |
---|---|
119 var br = document.createElement('br'); | 119 var br = document.createElement('br'); |
120 this.popupContent.appendChild(span); | 120 this.popupContent.appendChild(span); |
121 this.popupContent.appendChild(br); | 121 this.popupContent.appendChild(br); |
122 this.popupContent.appendChild(textArea); | 122 this.popupContent.appendChild(textArea); |
123 this.popupContent.childNodes[2].focus(); | 123 this.popupContent.childNodes[2].focus(); |
124 } else if (node.type == 'checkbox') { | |
125 var span = document.createElement('span'); | |
126 span.textContent = node.statement; | |
127 this.popupContent.appendChild(span); | |
128 var optHold = document.createElement('div'); | |
129 optHold.id = 'option-holder'; | |
130 optHold.align = 'left'; | |
131 for (var i=0; i<node.options.length; i++) { | |
132 var option = node.options[i]; | |
133 var input = document.createElement('input'); | |
134 input.id = option.id; | |
135 input.type = 'checkbox'; | |
136 var span = document.createElement('span'); | |
137 span.textContent = option.text; | |
138 var hold = document.createElement('div'); | |
139 hold.setAttribute('name','option'); | |
140 hold.style.float = 'left'; | |
141 hold.style.padding = '4px'; | |
142 hold.appendChild(input); | |
143 hold.appendChild(span); | |
144 optHold.appendChild(hold); | |
145 } | |
146 this.popupContent.appendChild(optHold); | |
124 } | 147 } |
125 this.popupContent.appendChild(this.popupButton); | 148 this.popupContent.appendChild(this.popupButton); |
126 }; | 149 }; |
127 | 150 |
128 this.initState = function(node) { | 151 this.initState = function(node) { |
162 hold.innerHTML = textArea.value; | 185 hold.innerHTML = textArea.value; |
163 console.log("Question: "+ node.textContent); | 186 console.log("Question: "+ node.textContent); |
164 console.log("Question Response: "+ textArea.value); | 187 console.log("Question Response: "+ textArea.value); |
165 this.responses.appendChild(hold); | 188 this.responses.appendChild(hold); |
166 } | 189 } |
190 } else if (node.type == 'checkbox') { | |
191 // Must extract checkbox data | |
192 var optHold = document.getElementById('option-holder'); | |
193 var hold = document.createElement('checkbox'); | |
194 console.log("Checkbox: "+ node.statement); | |
195 for (var i=0; i<optHold.childElementCount; i++) { | |
196 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; | |
197 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; | |
198 var response = document.createElement('option'); | |
199 response.setAttribute('id',input.id); | |
200 response.setAttribute('checked',input.checked); | |
201 hold.appendChild(response); | |
202 console.log(input.id +': '+ input.checked); | |
203 } | |
204 this.responses.appendChild(hold); | |
167 } | 205 } |
168 this.currentIndex++; | 206 this.currentIndex++; |
169 if (this.currentIndex < this.popupOptions.length) { | 207 if (this.currentIndex < this.popupOptions.length) { |
170 this.postNode(); | 208 this.postNode(); |
171 } else { | 209 } else { |
1012 this.prepostNode = function(type,Collection) { | 1050 this.prepostNode = function(type,Collection) { |
1013 this.type = type; | 1051 this.type = type; |
1014 this.options = []; | 1052 this.options = []; |
1015 | 1053 |
1016 this.OptionNode = function(child) { | 1054 this.OptionNode = function(child) { |
1055 | |
1056 this.childOption = function(element) { | |
1057 this.type = 'option'; | |
1058 this.id = element.id; | |
1059 this.text = element.textContent; | |
1060 } | |
1061 | |
1017 this.type = child.nodeName; | 1062 this.type = child.nodeName; |
1018 if (child.nodeName == "question") { | 1063 if (child.nodeName == "question") { |
1019 this.id = child.id; | 1064 this.id = child.id; |
1020 this.mandatory; | 1065 this.mandatory; |
1021 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} | 1066 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} |
1022 else {this.mandatory = false;} | 1067 else {this.mandatory = false;} |
1023 this.question = child.textContent; | 1068 this.question = child.textContent; |
1024 } else if (child.nodeName == "statement") { | 1069 } else if (child.nodeName == "statement") { |
1025 this.statement = child.textContent; | 1070 this.statement = child.textContent; |
1071 } else if (child.nodeName == "checkbox") { | |
1072 var element = child.firstElementChild; | |
1073 if (element == null) { | |
1074 console.log('Malformed checkbox entry'); | |
1075 this.statement = 'Malformed checkbox entry'; | |
1076 this.type = 'statement'; | |
1077 } else { | |
1078 this.options = []; | |
1079 while (element != null) { | |
1080 if (element.nodeName == 'statement' && this.statement == undefined){ | |
1081 this.statement = element.textContent; | |
1082 } else if (element.nodeName == 'option') { | |
1083 this.options.push(new this.childOption(element)); | |
1084 } | |
1085 element = element.nextElementSibling; | |
1086 } | |
1087 } | |
1026 } | 1088 } |
1027 }; | 1089 }; |
1028 | 1090 |
1029 // On construction: | 1091 // On construction: |
1030 if (Collection.length != 0) { | 1092 if (Collection.length != 0) { |