comparison core.js @ 1572:75f47f1c6cbe

Feature #1208: Added checkbox. Bug-fix on console debug lines not showing question of survery.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 08 Jun 2015 11:17:26 +0100
parents 2a3e95841f14
children 3464a477c021
comparison
equal deleted inserted replaced
1571:2a3e95841f14 1572:75f47f1c6cbe
224 } else { 224 } else {
225 // Save the text content 225 // Save the text content
226 var hold = document.createElement('comment'); 226 var hold = document.createElement('comment');
227 hold.id = node.id; 227 hold.id = node.id;
228 hold.innerHTML = textArea.value; 228 hold.innerHTML = textArea.value;
229 console.log("Question: "+ node.textContent); 229 console.log("Question: "+ node.question);
230 console.log("Question Response: "+ textArea.value); 230 console.log("Question Response: "+ textArea.value);
231 this.responses.appendChild(hold); 231 this.responses.appendChild(hold);
232 } 232 }
233 } else if (node.type == 'checkbox') { 233 } else if (node.type == 'checkbox') {
234 // Must extract checkbox data 234 // Must extract checkbox data
238 hold.id = node.id; 238 hold.id = node.id;
239 for (var i=0; i<optHold.childElementCount; i++) { 239 for (var i=0; i<optHold.childElementCount; i++) {
240 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; 240 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
241 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; 241 var statement = optHold.childNodes[i].getElementsByTagName('span')[0];
242 var response = document.createElement('option'); 242 var response = document.createElement('option');
243 response.setAttribute('id',input.id); 243 response.setAttribute('name',input.id);
244 response.setAttribute('checked',input.checked); 244 response.textContent = input.checked;
245 hold.appendChild(response); 245 hold.appendChild(response);
246 console.log(input.id +': '+ input.checked); 246 console.log(input.id +': '+ input.checked);
247 } 247 }
248 this.responses.appendChild(hold); 248 this.responses.appendChild(hold);
249 } else if (node.type == "radio") { 249 } else if (node.type == "radio") {
1220 } else if (child.nodeName == 'option') { 1220 } else if (child.nodeName == 'option') {
1221 this.options.push(new this.childOption(child)); 1221 this.options.push(new this.childOption(child));
1222 } 1222 }
1223 child = child.nextElementSibling; 1223 child = child.nextElementSibling;
1224 } 1224 }
1225 break;
1226 case 'checkbox':
1227 var child = xml.firstElementChild;
1228 this.options = [];
1229 while (child != undefined) {
1230 if (child.nodeName == 'statement' && this.statement == undefined) {
1231 this.statement = child.textContent;
1232 } else if (child.nodeName == 'option') {
1233 this.options.push(new this.childOption(child));
1234 }
1235 child = child.nextElementSibling;
1236 }
1237 break;
1225 } 1238 }
1226 }; 1239 };
1227 1240
1228 this.id = xml.id; 1241 this.id = xml.id;
1229 this.hostURL = xml.getAttribute('hostURL'); 1242 this.hostURL = xml.getAttribute('hostURL');
1420 response.textContent = 'null'; 1433 response.textContent = 'null';
1421 } else { 1434 } else {
1422 response.textContent = this.options[i].getAttribute('setvalue'); 1435 response.textContent = this.options[i].getAttribute('setvalue');
1423 response.setAttribute('number',i); 1436 response.setAttribute('number',i);
1424 } 1437 }
1438 console.log('Comment: '+question.textContent);
1439 console.log('Response: '+response.textContent);
1425 root.appendChild(question); 1440 root.appendChild(question);
1426 root.appendChild(response); 1441 root.appendChild(response);
1427 return root; 1442 return root;
1428 }; 1443 };
1429 }; 1444 };
1430 1445
1446 this.checkboxBox = function(commentQuestion) {
1447 this.specification = commentQuestion;
1448 // Create document objects to hold the comment boxes
1449 this.holder = document.createElement('div');
1450 this.holder.className = 'comment-div';
1451 // Create a string next to each comment asking for a comment
1452 this.string = document.createElement('span');
1453 this.string.innerHTML = commentQuestion.statement;
1454 var br = document.createElement('br');
1455 // Add to the holder.
1456 this.holder.appendChild(this.string);
1457 this.holder.appendChild(br);
1458 this.options = [];
1459 this.inputs = document.createElement('div');
1460 this.span = document.createElement('div');
1461 this.inputs.align = 'center';
1462 this.inputs.style.marginLeft = '12px';
1463 this.span.style.marginLeft = '12px';
1464 this.span.align = 'center';
1465 this.span.style.marginTop = '15px';
1466
1467 var optCount = commentQuestion.options.length;
1468 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px';
1469 console.log(spanMargin);
1470 for (var i=0; i<optCount; i++)
1471 {
1472 var div = document.createElement('div');
1473 div.style.width = '100px';
1474 div.style.float = 'left';
1475 div.style.marginRight = spanMargin;
1476 div.style.marginLeft = spanMargin;
1477 var input = document.createElement('input');
1478 input.type = 'checkbox';
1479 input.name = commentQuestion.id;
1480 input.setAttribute('setvalue',commentQuestion.options[i].name);
1481 input.className = 'comment-radio';
1482 div.appendChild(input);
1483 this.inputs.appendChild(div);
1484
1485
1486 div = document.createElement('div');
1487 div.style.width = '100px';
1488 div.style.float = 'left';
1489 div.style.marginRight = spanMargin;
1490 div.style.marginLeft = spanMargin;
1491 div.align = 'center';
1492 var span = document.createElement('span');
1493 span.textContent = commentQuestion.options[i].text;
1494 span.className = 'comment-radio-span';
1495 div.appendChild(span);
1496 this.span.appendChild(div);
1497 this.options.push(input);
1498 }
1499 this.holder.appendChild(this.span);
1500 this.holder.appendChild(this.inputs);
1501
1502 this.exportXMLDOM = function() {
1503 var root = document.createElement('comment');
1504 root.id = this.specification.id;
1505 root.setAttribute('type',this.specification.type);
1506 var question = document.createElement('question');
1507 question.textContent = this.string.textContent;
1508 root.appendChild(question);
1509 console.log('Comment: '+question.textContent);
1510 for (var i=0; i<this.options.length; i++) {
1511 var response = document.createElement('response');
1512 response.textContent = this.options[i].checked;
1513 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
1514 root.appendChild(response);
1515 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
1516 }
1517 return root;
1518 };
1519 };
1431 1520
1432 this.createCommentBox = function(audioObject) { 1521 this.createCommentBox = function(audioObject) {
1433 var node = new this.elementCommentBox(audioObject); 1522 var node = new this.elementCommentBox(audioObject);
1434 this.commentBoxes.push(node); 1523 this.commentBoxes.push(node);
1435 audioObject.commentDOM = node; 1524 audioObject.commentDOM = node;
1456 var node; 1545 var node;
1457 if (element.type == 'text') { 1546 if (element.type == 'text') {
1458 node = new this.commentBox(element); 1547 node = new this.commentBox(element);
1459 } else if (element.type == 'radio') { 1548 } else if (element.type == 'radio') {
1460 node = new this.radioBox(element); 1549 node = new this.radioBox(element);
1550 } else if (element.type == 'checkbox') {
1551 node = new this.checkboxBox(element);
1461 } 1552 }
1462 this.commentQuestions.push(node); 1553 this.commentQuestions.push(node);
1463 return node; 1554 return node;
1464 }; 1555 };
1465 } 1556 }