comparison core.js @ 1361:10ddee18db8d

Feature #1234: Completed fix
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Tue, 26 Jan 2016 14:20:43 +0000
parents a9eb4f6443d8
children a679987d13cc
comparison
equal deleted inserted replaced
1360:a9eb4f6443d8 1361:10ddee18db8d
547 case 'huge': 547 case 'huge':
548 textArea.cols = "50"; 548 textArea.cols = "50";
549 textArea.rows = "10"; 549 textArea.rows = "10";
550 break; 550 break;
551 } 551 }
552 if (node.response == undefined) {
553 node.response = "";
554 } else {
555 textArea.value = node.response;
556 }
552 this.popupResponse.appendChild(textArea); 557 this.popupResponse.appendChild(textArea);
553 textArea.focus(); 558 textArea.focus();
554 } else if (node.specification.type == 'checkbox') { 559 } else if (node.specification.type == 'checkbox') {
560 if (node.response == undefined) {
561 node.response = Array(node.specification.options.length);
562 }
563 var index = 0;
555 for (var option of node.specification.options) { 564 for (var option of node.specification.options) {
556 var input = document.createElement('input'); 565 var input = document.createElement('input');
557 input.id = option.name; 566 input.id = option.name;
558 input.type = 'checkbox'; 567 input.type = 'checkbox';
559 var span = document.createElement('span'); 568 var span = document.createElement('span');
562 hold.setAttribute('name','option'); 571 hold.setAttribute('name','option');
563 hold.style.padding = '4px'; 572 hold.style.padding = '4px';
564 hold.appendChild(input); 573 hold.appendChild(input);
565 hold.appendChild(span); 574 hold.appendChild(span);
566 this.popupResponse.appendChild(hold); 575 this.popupResponse.appendChild(hold);
576 if (node.response[index] != undefined){
577 if (node.response[index].checked == true) {
578 input.checked = "true";
579 }
580 }
581 index++;
567 } 582 }
568 } else if (node.specification.type == 'radio') { 583 } else if (node.specification.type == 'radio') {
584 if (node.response == undefined) {
585 node.response = {name: "", text: ""};
586 }
587 var index = 0;
569 for (var option of node.specification.options) { 588 for (var option of node.specification.options) {
570 var input = document.createElement('input'); 589 var input = document.createElement('input');
571 input.id = option.name; 590 input.id = option.name;
572 input.type = 'radio'; 591 input.type = 'radio';
573 input.name = node.specification.id; 592 input.name = node.specification.id;
577 hold.setAttribute('name','option'); 596 hold.setAttribute('name','option');
578 hold.style.padding = '4px'; 597 hold.style.padding = '4px';
579 hold.appendChild(input); 598 hold.appendChild(input);
580 hold.appendChild(span); 599 hold.appendChild(span);
581 this.popupResponse.appendChild(hold); 600 this.popupResponse.appendChild(hold);
601 if (input.id == node.response.name) {
602 input.checked = "true";
603 }
582 } 604 }
583 } else if (node.specification.type == 'number') { 605 } else if (node.specification.type == 'number') {
584 var input = document.createElement('input'); 606 var input = document.createElement('input');
585 input.type = 'textarea'; 607 input.type = 'textarea';
586 if (node.min != null) {input.min = node.specification.min;} 608 if (node.min != null) {input.min = node.specification.min;}
587 if (node.max != null) {input.max = node.specification.max;} 609 if (node.max != null) {input.max = node.specification.max;}
588 if (node.step != null) {input.step = node.specification.step;} 610 if (node.step != null) {input.step = node.specification.step;}
611 if (node.response != undefined) {
612 input.value = node.response;
613 }
589 this.popupResponse.appendChild(input); 614 this.popupResponse.appendChild(input);
590 } 615 }
591 var content_height = Number(this.popup.offsetHeight.toFixed()); 616 var content_height = Number(this.popup.offsetHeight.toFixed());
592 content_height -= Number(this.popupContent.offsetHeight.toFixed()); 617 content_height -= Number(this.popupContent.offsetHeight.toFixed());
593 content_height -=Number(this.buttonProceed.offsetHeight.toFixed()); 618 content_height -=Number(this.buttonProceed.offsetHeight.toFixed());
719 744
720 this.previousClick = function() { 745 this.previousClick = function() {
721 // Triggered when the 'Back' button is clicked in the survey 746 // Triggered when the 'Back' button is clicked in the survey
722 if (this.currentIndex > 0) { 747 if (this.currentIndex > 0) {
723 this.currentIndex--; 748 this.currentIndex--;
724 var node = this.popupOptions[this.currentIndex];
725 if (node.type != 'statement') {
726 var prevResp = this.responses.childNodes[this.responses.childElementCount-1];
727 this.responses.removeChild(prevResp);
728 }
729 this.postNode(); 749 this.postNode();
730 if (node.type == 'question') {
731 this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent;
732 } else if (node.type == 'checkbox') {
733 var options = this.popupContent.getElementsByTagName('input');
734 var savedOptions = prevResp.getElementsByTagName('option');
735 for (var i=0; i<options.length; i++) {
736 var id = options[i].id;
737 for (var j=0; j<savedOptions.length; j++) {
738 if (savedOptions[j].getAttribute('name') == id) {
739 if (savedOptions[j].textContent == 'true') {options[i].checked = true;}
740 else {options[i].checked = false;}
741 break;
742 }
743 }
744 }
745 } else if (node.type == 'number') {
746 this.popupContent.getElementsByTagName('input')[0].value = prevResp.textContent;
747 } else if (node.type == 'radio') {
748 var options = this.popupContent.getElementsByTagName('input');
749 var name = prevResp.getAttribute('name');
750 for (var i=0; i<options.length; i++) {
751 if (options[i].id == name) {
752 options[i].checked = true;
753 break;
754 }
755 }
756 }
757 } 750 }
758 }; 751 };
759 752
760 this.resize = function(event) 753 this.resize = function(event)
761 { 754 {