Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2464:75bd7b5dc522
Implemented #5
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 23 Jun 2016 13:44:17 +0100 |
parents | fda7ee7bb914 |
children | 496fde335890 |
comparison
equal
deleted
inserted
replaced
2463:fda7ee7bb914 | 2464:75bd7b5dc522 |
---|---|
857 // Save the text content | 857 // Save the text content |
858 console.log("Question: "+ node.specification.statement); | 858 console.log("Question: "+ node.specification.statement); |
859 console.log("Question Response: "+ textArea.value); | 859 console.log("Question Response: "+ textArea.value); |
860 node.response = textArea.value; | 860 node.response = textArea.value; |
861 } | 861 } |
862 // Perform the conditional | |
863 for (var condition of node.specification.conditions) { | |
864 var pass = false; | |
865 switch(condition.check) { | |
866 case "equals": | |
867 if (textArea.value == condition.value) { | |
868 pass = true; | |
869 } | |
870 break; | |
871 case "greaterThan": | |
872 case "lessThan": | |
873 console.log("Survey Element of type 'question' cannot interpret greaterThan/lessThan conditions. IGNORING"); | |
874 break; | |
875 case "contains": | |
876 if (textArea.value.includes(condition.value)) { | |
877 pass = true; | |
878 } | |
879 break; | |
880 } | |
881 var jumpID; | |
882 if (pass) { | |
883 jumpID = condition.jumpToOnPass; | |
884 } else { | |
885 jumpID = condition.jumpToOnFail; | |
886 } | |
887 if (jumpID != undefined) { | |
888 var index = this.popupOptions.findIndex(function(item,index,element){ | |
889 if (item.specification.id == jumpID) {return true;} else {return false;} | |
890 },this); | |
891 this.currentIndex = index-1; | |
892 break; | |
893 } | |
894 } | |
862 } else if (node.specification.type == 'checkbox') { | 895 } else if (node.specification.type == 'checkbox') { |
863 // Must extract checkbox data | 896 // Must extract checkbox data |
864 console.log("Checkbox: "+ node.specification.statement); | 897 console.log("Checkbox: "+ node.specification.statement); |
865 var inputs = this.popupResponse.getElementsByTagName('input'); | 898 var inputs = this.popupResponse.getElementsByTagName('input'); |
866 node.response = []; | 899 node.response = []; |
870 text: node.specification.options[i].text, | 903 text: node.specification.options[i].text, |
871 checked: inputs[i].checked | 904 checked: inputs[i].checked |
872 }); | 905 }); |
873 console.log(node.specification.options[i].name+": "+ inputs[i].checked); | 906 console.log(node.specification.options[i].name+": "+ inputs[i].checked); |
874 } | 907 } |
908 // Perform the conditional | |
909 for (var condition of node.specification.conditions) { | |
910 var pass = false; | |
911 switch(condition.check) { | |
912 case "equals": | |
913 case "greaterThan": | |
914 case "lessThan": | |
915 console.log("Survey Element of type 'checkbox' cannot interpret equals/greaterThan/lessThan conditions. IGNORING"); | |
916 break; | |
917 case "contains": | |
918 for (var response of node.response) { | |
919 if (response.name == condition.value && response.checked) { | |
920 pass = true; | |
921 break; | |
922 } | |
923 } | |
924 break; | |
925 } | |
926 var jumpID; | |
927 if (pass) { | |
928 jumpID = condition.jumpToOnPass; | |
929 } else { | |
930 jumpID = condition.jumpToOnFail; | |
931 } | |
932 if (jumpID != undefined) { | |
933 var index = this.popupOptions.findIndex(function(item,index,element){ | |
934 if (item.specification.id == jumpID) {return true;} else {return false;} | |
935 },this); | |
936 this.currentIndex = index-1; | |
937 break; | |
938 } | |
939 } | |
875 } else if (node.specification.type == "radio") { | 940 } else if (node.specification.type == "radio") { |
876 var optHold = this.popupResponse; | 941 var optHold = this.popupResponse; |
877 console.log("Radio: "+ node.specification.statement); | 942 console.log("Radio: "+ node.specification.statement); |
878 node.response = null; | 943 node.response = null; |
879 var i=0; | 944 var i=0; |
892 node.response = node.specification.options[i]; | 957 node.response = node.specification.options[i]; |
893 console.log("Selected: "+ node.specification.options[i].name); | 958 console.log("Selected: "+ node.specification.options[i].name); |
894 } | 959 } |
895 i++; | 960 i++; |
896 } | 961 } |
962 // Perform the conditional | |
963 for (var condition of node.specification.conditions) { | |
964 var pass = false; | |
965 switch(condition.check) { | |
966 case "contains": | |
967 case "greaterThan": | |
968 case "lessThan": | |
969 console.log("Survey Element of type 'radio' cannot interpret contains/greaterThan/lessThan conditions. IGNORING"); | |
970 break; | |
971 case "equals": | |
972 if (node.response == condition.value) { | |
973 pass = true; | |
974 } | |
975 break; | |
976 } | |
977 var jumpID; | |
978 if (pass) { | |
979 jumpID = condition.jumpToOnPass; | |
980 } else { | |
981 jumpID = condition.jumpToOnFail; | |
982 } | |
983 if (jumpID != undefined) { | |
984 var index = this.popupOptions.findIndex(function(item,index,element){ | |
985 if (item.specification.id == jumpID) {return true;} else {return false;} | |
986 },this); | |
987 this.currentIndex = index-1; | |
988 break; | |
989 } | |
990 } | |
897 } else if (node.specification.type == "number") { | 991 } else if (node.specification.type == "number") { |
898 var input = this.popupContent.getElementsByTagName('input')[0]; | 992 var input = this.popupContent.getElementsByTagName('input')[0]; |
899 if (node.mandatory == true && input.value.length == 0) { | 993 if (node.mandatory == true && input.value.length == 0) { |
900 interfaceContext.lightbox.post("Error",'This question is mandatory. Please enter a number'); | 994 interfaceContext.lightbox.post("Error",'This question is mandatory. Please enter a number'); |
901 return; | 995 return; |
912 if (enteredNumber > node.max && node.max != null) { | 1006 if (enteredNumber > node.max && node.max != null) { |
913 interfaceContext.lightbox.post("Error",'Number is above the maximum value of '+node.max); | 1007 interfaceContext.lightbox.post("Error",'Number is above the maximum value of '+node.max); |
914 return; | 1008 return; |
915 } | 1009 } |
916 node.response = input.value; | 1010 node.response = input.value; |
1011 // Perform the conditional | |
1012 for (var condition of node.specification.conditions) { | |
1013 var pass = false; | |
1014 switch(condition.check) { | |
1015 case "contains": | |
1016 console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING"); | |
1017 break; | |
1018 case "greaterThan": | |
1019 if (node.response > Number(condition.value)) { | |
1020 pass = true; | |
1021 } | |
1022 break; | |
1023 case "lessThan": | |
1024 if (node.response < Number(condition.value)) { | |
1025 pass = true; | |
1026 } | |
1027 break; | |
1028 case "equals": | |
1029 if (node.response == condition.value) { | |
1030 pass = true; | |
1031 } | |
1032 break; | |
1033 } | |
1034 var jumpID; | |
1035 if (pass) { | |
1036 jumpID = condition.jumpToOnPass; | |
1037 } else { | |
1038 jumpID = condition.jumpToOnFail; | |
1039 } | |
1040 if (jumpID != undefined) { | |
1041 var index = this.popupOptions.findIndex(function(item,index,element){ | |
1042 if (item.specification.id == jumpID) {return true;} else {return false;} | |
1043 },this); | |
1044 this.currentIndex = index-1; | |
1045 break; | |
1046 } | |
1047 } | |
917 } | 1048 } |
918 this.currentIndex++; | 1049 this.currentIndex++; |
919 if (this.currentIndex < this.popupOptions.length) { | 1050 if (this.currentIndex < this.popupOptions.length) { |
920 this.postNode(); | 1051 this.postNode(); |
921 } else { | 1052 } else { |
3188 child.setAttribute('name',node.response.name); | 3319 child.setAttribute('name',node.response.name); |
3189 child.textContent = node.response.text; | 3320 child.textContent = node.response.text; |
3190 surveyresult.appendChild(child); | 3321 surveyresult.appendChild(child); |
3191 break; | 3322 break; |
3192 case "checkbox": | 3323 case "checkbox": |
3324 if (node.response == undefined) { | |
3325 surveyresult.appendChild(this.parent.document.createElement('response')); | |
3326 break; | |
3327 } | |
3193 for (var i=0; i<node.response.length; i++) | 3328 for (var i=0; i<node.response.length; i++) |
3194 { | 3329 { |
3195 var checkNode = this.parent.document.createElement('response'); | 3330 var checkNode = this.parent.document.createElement('response'); |
3196 checkNode.setAttribute('name',node.response[i].name); | 3331 checkNode.setAttribute('name',node.response[i].name); |
3197 checkNode.setAttribute('checked',node.response[i].checked); | 3332 checkNode.setAttribute('checked',node.response[i].checked); |