Mercurial > hg > webaudioevaluationtool
comparison core.js @ 197:c53ba966b716 Dev_main
Added min/max range check to number box survey
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 08 Jun 2015 12:09:53 +0100 |
parents | e29cc73dc8ee |
children | 30b9d9538cb7 |
comparison
equal
deleted
inserted
replaced
196:e29cc73dc8ee | 197:c53ba966b716 |
---|---|
47 | 47 |
48 function interfacePopup() { | 48 function interfacePopup() { |
49 // Creates an object to manage the popup | 49 // Creates an object to manage the popup |
50 this.popup = null; | 50 this.popup = null; |
51 this.popupContent = null; | 51 this.popupContent = null; |
52 this.popupButton = null; | 52 this.buttonProceed = null; |
53 this.popupOptions = null; | 53 this.popupOptions = null; |
54 this.currentIndex = null; | 54 this.currentIndex = null; |
55 this.responses = null; | 55 this.responses = null; |
56 | 56 |
57 this.createPopup = function(){ | 57 this.createPopup = function(){ |
71 this.popupContent.id = 'popupContent'; | 71 this.popupContent.id = 'popupContent'; |
72 this.popupContent.style.marginTop = '25px'; | 72 this.popupContent.style.marginTop = '25px'; |
73 this.popupContent.align = 'center'; | 73 this.popupContent.align = 'center'; |
74 this.popup.appendChild(this.popupContent); | 74 this.popup.appendChild(this.popupContent); |
75 | 75 |
76 this.popupButton = document.createElement('button'); | 76 this.buttonProceed = document.createElement('button'); |
77 this.popupButton.className = 'popupButton'; | 77 this.buttonProceed.className = 'popupButton'; |
78 this.popupButton.innerHTML = 'Next'; | 78 this.buttonProceed.innerHTML = 'Next'; |
79 this.popupButton.onclick = function(){popup.buttonClicked();}; | 79 this.buttonProceed.onclick = function(){popup.proceedClicked();}; |
80 this.popup.style.zIndex = -1; | 80 this.popup.style.zIndex = -1; |
81 this.popup.style.visibility = 'hidden'; | 81 this.popup.style.visibility = 'hidden'; |
82 blank.style.zIndex = -2; | 82 blank.style.zIndex = -2; |
83 blank.style.visibility = 'hidden'; | 83 blank.style.visibility = 'hidden'; |
84 insertPoint.appendChild(this.popup); | 84 insertPoint.appendChild(this.popup); |
197 if (node.min != null) {input.min = node.min;} | 197 if (node.min != null) {input.min = node.min;} |
198 if (node.max != null) {input.max = node.max;} | 198 if (node.max != null) {input.max = node.max;} |
199 if (node.step != null) {input.step = node.step;} | 199 if (node.step != null) {input.step = node.step;} |
200 this.popupContent.appendChild(input); | 200 this.popupContent.appendChild(input); |
201 } | 201 } |
202 this.popupContent.appendChild(this.popupButton); | 202 this.popupContent.appendChild(this.buttonProceed); |
203 }; | 203 }; |
204 | 204 |
205 this.initState = function(node) { | 205 this.initState = function(node) { |
206 //Call this with your preTest and postTest nodes when needed to | 206 //Call this with your preTest and postTest nodes when needed to |
207 // initialise the popup procedure. | 207 // initialise the popup procedure. |
221 } else { | 221 } else { |
222 advanceState(); | 222 advanceState(); |
223 } | 223 } |
224 }; | 224 }; |
225 | 225 |
226 this.buttonClicked = function() { | 226 this.proceedClicked = function() { |
227 // Each time the popup button is clicked! | 227 // Each time the popup button is clicked! |
228 var node = this.popupOptions[this.currentIndex]; | 228 var node = this.popupOptions[this.currentIndex]; |
229 if (node.type == 'question') { | 229 if (node.type == 'question') { |
230 // Must extract the question data | 230 // Must extract the question data |
231 var textArea = $(popup.popupContent).find('textarea')[0]; | 231 var textArea = $(popup.popupContent).find('textarea')[0]; |
274 hold.textContent = node.options[responseID].text; | 274 hold.textContent = node.options[responseID].text; |
275 this.responses.appendChild(hold); | 275 this.responses.appendChild(hold); |
276 } else if (node.type == "number") { | 276 } else if (node.type == "number") { |
277 var input = this.popupContent.getElementsByTagName('input')[0]; | 277 var input = this.popupContent.getElementsByTagName('input')[0]; |
278 if (node.mandatory == true && input.value.length == 0) { | 278 if (node.mandatory == true && input.value.length == 0) { |
279 alert('This question is mandatory'); | 279 alert('This question is mandatory. Please enter a number'); |
280 return; | |
281 } | |
282 var enteredNumber = Number(input.value); | |
283 if (enteredNumber == undefined) { | |
284 alert('Please enter a valid number'); | |
285 return; | |
286 } | |
287 if (enteredNumber < node.min && node.min != null) { | |
288 alert('Number is below the minimum value of '+node.min); | |
289 return; | |
290 } | |
291 if (enteredNumber > node.max && node.max != null) { | |
292 alert('Number is above the maximum value of '+node.max); | |
280 return; | 293 return; |
281 } | 294 } |
282 var hold = document.createElement('number'); | 295 var hold = document.createElement('number'); |
283 hold.id = node.id; | 296 hold.id = node.id; |
284 hold.textContent = input.value; | 297 hold.textContent = input.value; |
285 this.responses.appendChild(hold); | 298 this.responses.appendChild(hold); |
286 } | 299 } |
287 this.currentIndex++; | 300 this.currentIndex++; |
288 if (this.currentIndex < this.popupOptions.length) { | 301 if (this.currentIndex < this.popupOptions.length) { |
302 if(this.currentIndex+1 == this.popupOptions.length) { | |
303 this.buttonProceed.textContent = 'Submit'; | |
304 } | |
289 this.postNode(); | 305 this.postNode(); |
290 } else { | 306 } else { |
291 // Reached the end of the popupOptions | 307 // Reached the end of the popupOptions |
292 this.hidePopup(); | 308 this.hidePopup(); |
293 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { | 309 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { |