Mercurial > hg > webaudioevaluationtool
comparison core.js @ 198:a7b377b86ed6
Merge from branch "Dev_main"
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 10 Jun 2015 09:31:44 +0100 |
parents | c53ba966b716 |
children | 30b9d9538cb7 |
comparison
equal
deleted
inserted
replaced
193:b0d683510881 | 198:a7b377b86ed6 |
---|---|
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); |
185 hold.appendChild(input); | 185 hold.appendChild(input); |
186 hold.appendChild(span); | 186 hold.appendChild(span); |
187 optHold.appendChild(hold); | 187 optHold.appendChild(hold); |
188 } | 188 } |
189 this.popupContent.appendChild(optHold); | 189 this.popupContent.appendChild(optHold); |
190 } | 190 } else if (node.type == 'number') { |
191 this.popupContent.appendChild(this.popupButton); | 191 var span = document.createElement('span'); |
192 span.textContent = node.statement; | |
193 this.popupContent.appendChild(span); | |
194 this.popupContent.appendChild(document.createElement('br')); | |
195 var input = document.createElement('input'); | |
196 input.type = 'number'; | |
197 if (node.min != null) {input.min = node.min;} | |
198 if (node.max != null) {input.max = node.max;} | |
199 if (node.step != null) {input.step = node.step;} | |
200 this.popupContent.appendChild(input); | |
201 } | |
202 this.popupContent.appendChild(this.buttonProceed); | |
192 }; | 203 }; |
193 | 204 |
194 this.initState = function(node) { | 205 this.initState = function(node) { |
195 //Call this with your preTest and postTest nodes when needed to | 206 //Call this with your preTest and postTest nodes when needed to |
196 // initialise the popup procedure. | 207 // initialise the popup procedure. |
210 } else { | 221 } else { |
211 advanceState(); | 222 advanceState(); |
212 } | 223 } |
213 }; | 224 }; |
214 | 225 |
215 this.buttonClicked = function() { | 226 this.proceedClicked = function() { |
216 // Each time the popup button is clicked! | 227 // Each time the popup button is clicked! |
217 var node = this.popupOptions[this.currentIndex]; | 228 var node = this.popupOptions[this.currentIndex]; |
218 if (node.type == 'question') { | 229 if (node.type == 'question') { |
219 // Must extract the question data | 230 // Must extract the question data |
220 var textArea = $(popup.popupContent).find('textarea')[0]; | 231 var textArea = $(popup.popupContent).find('textarea')[0]; |
224 } else { | 235 } else { |
225 // Save the text content | 236 // Save the text content |
226 var hold = document.createElement('comment'); | 237 var hold = document.createElement('comment'); |
227 hold.id = node.id; | 238 hold.id = node.id; |
228 hold.innerHTML = textArea.value; | 239 hold.innerHTML = textArea.value; |
229 console.log("Question: "+ node.textContent); | 240 console.log("Question: "+ node.question); |
230 console.log("Question Response: "+ textArea.value); | 241 console.log("Question Response: "+ textArea.value); |
231 this.responses.appendChild(hold); | 242 this.responses.appendChild(hold); |
232 } | 243 } |
233 } else if (node.type == 'checkbox') { | 244 } else if (node.type == 'checkbox') { |
234 // Must extract checkbox data | 245 // Must extract checkbox data |
238 hold.id = node.id; | 249 hold.id = node.id; |
239 for (var i=0; i<optHold.childElementCount; i++) { | 250 for (var i=0; i<optHold.childElementCount; i++) { |
240 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; | 251 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; |
241 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; | 252 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; |
242 var response = document.createElement('option'); | 253 var response = document.createElement('option'); |
243 response.setAttribute('id',input.id); | 254 response.setAttribute('name',input.id); |
244 response.setAttribute('checked',input.checked); | 255 response.textContent = input.checked; |
245 hold.appendChild(response); | 256 hold.appendChild(response); |
246 console.log(input.id +': '+ input.checked); | 257 console.log(input.id +': '+ input.checked); |
247 } | 258 } |
248 this.responses.appendChild(hold); | 259 this.responses.appendChild(hold); |
249 } else if (node.type == "radio") { | 260 } else if (node.type == "radio") { |
260 } | 271 } |
261 hold.id = node.id; | 272 hold.id = node.id; |
262 hold.setAttribute('name',node.options[responseID].name); | 273 hold.setAttribute('name',node.options[responseID].name); |
263 hold.textContent = node.options[responseID].text; | 274 hold.textContent = node.options[responseID].text; |
264 this.responses.appendChild(hold); | 275 this.responses.appendChild(hold); |
276 } else if (node.type == "number") { | |
277 var input = this.popupContent.getElementsByTagName('input')[0]; | |
278 if (node.mandatory == true && input.value.length == 0) { | |
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); | |
293 return; | |
294 } | |
295 var hold = document.createElement('number'); | |
296 hold.id = node.id; | |
297 hold.textContent = input.value; | |
298 this.responses.appendChild(hold); | |
265 } | 299 } |
266 this.currentIndex++; | 300 this.currentIndex++; |
267 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 } | |
268 this.postNode(); | 305 this.postNode(); |
269 } else { | 306 } else { |
270 // Reached the end of the popupOptions | 307 // Reached the end of the popupOptions |
271 this.hidePopup(); | 308 this.hidePopup(); |
272 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { | 309 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { |
1150 this.options.push(new this.childOption(element)); | 1187 this.options.push(new this.childOption(element)); |
1151 } | 1188 } |
1152 element = element.nextElementSibling; | 1189 element = element.nextElementSibling; |
1153 } | 1190 } |
1154 } | 1191 } |
1192 } else if (child.nodeName == "number") { | |
1193 this.statement = child.textContent; | |
1194 this.id = child.id; | |
1195 this.min = child.getAttribute('min'); | |
1196 this.max = child.getAttribute('max'); | |
1197 this.step = child.getAttribute('step'); | |
1155 } | 1198 } |
1156 }; | 1199 }; |
1157 | 1200 |
1158 // On construction: | 1201 // On construction: |
1159 if (Collection.length != 0) { | 1202 if (Collection.length != 0) { |
1220 } else if (child.nodeName == 'option') { | 1263 } else if (child.nodeName == 'option') { |
1221 this.options.push(new this.childOption(child)); | 1264 this.options.push(new this.childOption(child)); |
1222 } | 1265 } |
1223 child = child.nextElementSibling; | 1266 child = child.nextElementSibling; |
1224 } | 1267 } |
1268 break; | |
1269 case 'checkbox': | |
1270 var child = xml.firstElementChild; | |
1271 this.options = []; | |
1272 while (child != undefined) { | |
1273 if (child.nodeName == 'statement' && this.statement == undefined) { | |
1274 this.statement = child.textContent; | |
1275 } else if (child.nodeName == 'option') { | |
1276 this.options.push(new this.childOption(child)); | |
1277 } | |
1278 child = child.nextElementSibling; | |
1279 } | |
1280 break; | |
1225 } | 1281 } |
1226 }; | 1282 }; |
1227 | 1283 |
1228 this.id = xml.id; | 1284 this.id = xml.id; |
1229 this.hostURL = xml.getAttribute('hostURL'); | 1285 this.hostURL = xml.getAttribute('hostURL'); |
1420 response.textContent = 'null'; | 1476 response.textContent = 'null'; |
1421 } else { | 1477 } else { |
1422 response.textContent = this.options[i].getAttribute('setvalue'); | 1478 response.textContent = this.options[i].getAttribute('setvalue'); |
1423 response.setAttribute('number',i); | 1479 response.setAttribute('number',i); |
1424 } | 1480 } |
1481 console.log('Comment: '+question.textContent); | |
1482 console.log('Response: '+response.textContent); | |
1425 root.appendChild(question); | 1483 root.appendChild(question); |
1426 root.appendChild(response); | 1484 root.appendChild(response); |
1427 return root; | 1485 return root; |
1428 }; | 1486 }; |
1429 }; | 1487 }; |
1430 | 1488 |
1489 this.checkboxBox = function(commentQuestion) { | |
1490 this.specification = commentQuestion; | |
1491 // Create document objects to hold the comment boxes | |
1492 this.holder = document.createElement('div'); | |
1493 this.holder.className = 'comment-div'; | |
1494 // Create a string next to each comment asking for a comment | |
1495 this.string = document.createElement('span'); | |
1496 this.string.innerHTML = commentQuestion.statement; | |
1497 var br = document.createElement('br'); | |
1498 // Add to the holder. | |
1499 this.holder.appendChild(this.string); | |
1500 this.holder.appendChild(br); | |
1501 this.options = []; | |
1502 this.inputs = document.createElement('div'); | |
1503 this.span = document.createElement('div'); | |
1504 this.inputs.align = 'center'; | |
1505 this.inputs.style.marginLeft = '12px'; | |
1506 this.span.style.marginLeft = '12px'; | |
1507 this.span.align = 'center'; | |
1508 this.span.style.marginTop = '15px'; | |
1509 | |
1510 var optCount = commentQuestion.options.length; | |
1511 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; | |
1512 console.log(spanMargin); | |
1513 for (var i=0; i<optCount; i++) | |
1514 { | |
1515 var div = document.createElement('div'); | |
1516 div.style.width = '100px'; | |
1517 div.style.float = 'left'; | |
1518 div.style.marginRight = spanMargin; | |
1519 div.style.marginLeft = spanMargin; | |
1520 var input = document.createElement('input'); | |
1521 input.type = 'checkbox'; | |
1522 input.name = commentQuestion.id; | |
1523 input.setAttribute('setvalue',commentQuestion.options[i].name); | |
1524 input.className = 'comment-radio'; | |
1525 div.appendChild(input); | |
1526 this.inputs.appendChild(div); | |
1527 | |
1528 | |
1529 div = document.createElement('div'); | |
1530 div.style.width = '100px'; | |
1531 div.style.float = 'left'; | |
1532 div.style.marginRight = spanMargin; | |
1533 div.style.marginLeft = spanMargin; | |
1534 div.align = 'center'; | |
1535 var span = document.createElement('span'); | |
1536 span.textContent = commentQuestion.options[i].text; | |
1537 span.className = 'comment-radio-span'; | |
1538 div.appendChild(span); | |
1539 this.span.appendChild(div); | |
1540 this.options.push(input); | |
1541 } | |
1542 this.holder.appendChild(this.span); | |
1543 this.holder.appendChild(this.inputs); | |
1544 | |
1545 this.exportXMLDOM = function() { | |
1546 var root = document.createElement('comment'); | |
1547 root.id = this.specification.id; | |
1548 root.setAttribute('type',this.specification.type); | |
1549 var question = document.createElement('question'); | |
1550 question.textContent = this.string.textContent; | |
1551 root.appendChild(question); | |
1552 console.log('Comment: '+question.textContent); | |
1553 for (var i=0; i<this.options.length; i++) { | |
1554 var response = document.createElement('response'); | |
1555 response.textContent = this.options[i].checked; | |
1556 response.setAttribute('name',this.options[i].getAttribute('setvalue')); | |
1557 root.appendChild(response); | |
1558 console.log('Response '+response.getAttribute('name') +': '+response.textContent); | |
1559 } | |
1560 return root; | |
1561 }; | |
1562 }; | |
1431 | 1563 |
1432 this.createCommentBox = function(audioObject) { | 1564 this.createCommentBox = function(audioObject) { |
1433 var node = new this.elementCommentBox(audioObject); | 1565 var node = new this.elementCommentBox(audioObject); |
1434 this.commentBoxes.push(node); | 1566 this.commentBoxes.push(node); |
1435 audioObject.commentDOM = node; | 1567 audioObject.commentDOM = node; |
1456 var node; | 1588 var node; |
1457 if (element.type == 'text') { | 1589 if (element.type == 'text') { |
1458 node = new this.commentBox(element); | 1590 node = new this.commentBox(element); |
1459 } else if (element.type == 'radio') { | 1591 } else if (element.type == 'radio') { |
1460 node = new this.radioBox(element); | 1592 node = new this.radioBox(element); |
1593 } else if (element.type == 'checkbox') { | |
1594 node = new this.checkboxBox(element); | |
1461 } | 1595 } |
1462 this.commentQuestions.push(node); | 1596 this.commentQuestions.push(node); |
1463 return node; | 1597 return node; |
1464 }; | 1598 }; |
1465 } | 1599 } |