Survey bug fixes

Fixed bugs in the handling of logical sections,
creating of responses and counting of responses.
Added in a bunch of new tests.
Jslinting of all survye js files
This commit is contained in:
Patrick Donelan 2009-05-23 09:54:03 +00:00
parent 5e7c594440
commit 3a25e806c6
12 changed files with 703 additions and 476 deletions

View file

@ -1,4 +1,4 @@
/*global Survey, YAHOO */
/*global Survey, YAHOO, alert, scrollPage, window */
if (typeof Survey === "undefined") {
var Survey = {};
}
@ -91,22 +91,30 @@ if (typeof Survey === "undefined") {
}
else if (toValidate[i].type === 'Year Month') {
answered = 1;//set to true, then let a single failure set it back to false.
for (var z1 in toValidate[i].answers) {
if (YAHOO.lang.hasOwnProperty(toValidate[i].answers, z1)) {
var m = document.getElementById(z1+'-month').value;
var y = document.getElementById(z1+'-year').value;
if(m == ''){ answered = 0; }
var yInt = parseInt(y, 10);
if(!yInt) { answered = 0; }
if(yInt < 1000 || yInt > 3000) { answered = 0; }
if(answered == 1){ document.getElementById(z1).value = m + "-" + y; }
for (var z2 in toValidate[i].answers) {
if (YAHOO.lang.hasOwnProperty(toValidate[i].answers, z2)) {
var month = document.getElementById(z2+'-month').value;
var year = document.getElementById(z2+'-year').value;
if (month == ''){
answered = 0;
}
var yInt = parseInt(year, 10);
if(!yInt) {
answered = 0;
}
if(yInt < 1000 || yInt > 3000) {
answered = 0;
}
if (answered == 1){
document.getElementById(z2).value = month + "-" + year;
}
}
}
}
else {
for (var z1 in toValidate[i].answers) {
if (YAHOO.lang.hasOwnProperty(toValidate[i].answers, z1)) {
var v = document.getElementById(z1).value;
for (var z3 in toValidate[i].answers) {
if (YAHOO.lang.hasOwnProperty(toValidate[i].answers, z3)) {
var v = document.getElementById(z3).value;
if (YAHOO.lang.isValue(v) && v !== '') {
answered = 1;
break;
@ -140,15 +148,21 @@ if (typeof Survey === "undefined") {
var submitDiv = submitButton && YAHOO.util.Dom.getAncestorByTagName(submitButton, 'div');
if (submit) {
submitDiv && YAHOO.util.Dom.removeClass(submitDiv, INVALID_SUBMIT_CLASS);
if (submitDiv) {
YAHOO.util.Dom.removeClass(submitDiv, INVALID_SUBMIT_CLASS);
}
YAHOO.log("Submitting");
Survey.Comm.callServer('', 'submitQuestions', 'surveyForm', hasFile);
}
else {
submitDiv && YAHOO.util.Dom.addClass(submitDiv, INVALID_SUBMIT_CLASS);
if (submitDiv) {
YAHOO.util.Dom.addClass(submitDiv, INVALID_SUBMIT_CLASS);
}
// Scroll page to the y-coord of the lowest invalid question
lowestInvalidY && scrollPage(lowestInvalidY, 1.5, YAHOO.util.Easing.easeOut);
if (lowestInvalidY) {
scrollPage(lowestInvalidY, 1.5, YAHOO.util.Easing.easeOut);
}
}
}
@ -203,13 +217,18 @@ if (typeof Survey === "undefined") {
}
}else if(+keycode == 38){//key up
if(objs.max == ''){
this.value = +value + +step;
this.value = value + step;
}
if(+value + +step <= +objs.max){
this.value = +value + +step;
if(value + step <= objs.max){
this.value = value + step;
}
}
}
function sliderTextSet(event, objs){
this.value = this.value * 1;
this.value = YAHOO.lang.isValue(this.value) ? this.value : 0;
}
function sliderManager(q){
//total number of pixels in the slider.
@ -237,9 +256,9 @@ if (typeof Survey === "undefined") {
var type = 'slider';
//find the maximum difference between an answers max and min
for (var s in q.answers) {
if (YAHOO.lang.hasOwnProperty(q.answers, s)) {
var a1 = q.answers[s];
for (var _s in q.answers) {
if (YAHOO.lang.hasOwnProperty(q.answers, _s)) {
var a1 = q.answers[_s];
YAHOO.util.Event.addListener(a1.id, "blur", sliderTextSet);
if (a1.max - a1.min > max) {
max = a1.max - a1.min;
@ -309,7 +328,7 @@ if (typeof Survey === "undefined") {
Event.on(document.getElementById(s.input), "blur", manualEntry);
Event.on(document.getElementById(s.input), "keypress", manualEntry);
var getRealValue = function(){
return parseInt((this.getValue() / bugSteps * step) + +min, 10);
return parseInt((this.getValue() / bugSteps * step) +min, 10);
};
s.getRealValue = getRealValue;
document.getElementById(s.input).value = s.getRealValue();
@ -317,11 +336,6 @@ if (typeof Survey === "undefined") {
}
}
function sliderTextSet(event, objs){
this.value = this.value * 1;
this.value = YAHOO.lang.isValue(this.value) ? this.value : 0;
}
function handleDualSliders(q){
var a1 = q.answers[0];
@ -453,7 +467,6 @@ if (typeof Survey === "undefined") {
return toolTipText;
},
showSummary: function(summary,html){
var html = html;
document.getElementById('survey').innerHTML = html;
@ -467,7 +480,7 @@ if (typeof Survey === "undefined") {
totalSummaryDS.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
totalSummaryDS.responseSchema = { fields: [ "correct", "count" ] };
new YAHOO.widget.PieChart( "chart", totalSummaryDS, {
var _pie = new YAHOO.widget.PieChart( "chart", totalSummaryDS, {
dataField: "count",
categoryField: "correct",
style:
@ -511,7 +524,7 @@ if (typeof Survey === "undefined") {
fields: ["Question ID","Question Text","Answer ID","Correct","Answer Text","Score","Value"]
};
var tempText = "section" + (i+1) + "datatable";
new YAHOO.widget.DataTable(tempText, myColumnDefs, myDataSource, { caption: "Section " + (i+1) } );
var _dt = new YAHOO.widget.DataTable(tempText, myColumnDefs, myDataSource, { caption: "Section " + (i+1) } );
}
//Now create section summary bar charts
@ -656,35 +669,35 @@ if (typeof Survey === "undefined") {
}
if (COUNTRY[q.questionType]) {
for (var k = 0; k < q.answers.length; k++) {
var ans = q.answers[k];
for (var k2 = 0; k2 < q.answers.length; k2++) {
var ans2 = q.answers[k2];
if (toValidate[q.id]) {
toValidate[q.id].type = q.questionType;
toValidate[q.id].answers[ans.id] = 1;
toValidate[q.id].answers[ans2.id] = 1;
}
}
continue;
}
if (DATE_TYPES[q.questionType]) {
for (var k = 0; k < q.answers.length; k++) {
var ans = q.answers[k];
for (var k3 = 0; k3 < q.answers.length; k3++) {
var ans3 = q.answers[k3];
if (toValidate[q.id]) {
toValidate[q.id].answers[ans.id] = 1;
toValidate[q.id].answers[ans3.id] = 1;
}
var calid = ans.id + 'container';
var calid = ans3.id + 'container';
var c = new YAHOO.widget.Calendar(calid, {
title: 'Choose a date:',
close: true,
navigator: true
});
c.selectEvent.subscribe(selectCalendar, [c, ans.id], true);
c.selectEvent.subscribe(selectCalendar, [c, ans3.id], true);
c.render();
c.hide();
var btn = new YAHOO.widget.Button({
label: "Select Date",
id: "pushbutton" + ans.id,
container: ans.id + 'button'
id: "pushbutton" + ans3.id,
container: ans3.id + 'button'
});
btn.on("click", showCalendar, [c]);
}
@ -715,12 +728,12 @@ if (typeof Survey === "undefined") {
continue;
}
if (NUMBER_TYPES[q.questionType]) {
for (var x in q.answers) {
if (YAHOO.lang.hasOwnProperty(q.answers, x)) {
for (var x1 in q.answers) {
if (YAHOO.lang.hasOwnProperty(q.answers, x1)) {
if (toValidate[q.id]) {
toValidate[q.id].answers[q.answers[x].id] = {'min':q.answers[x].min,'max':q.answers[x].max,'step':q.answers[x].step};
toValidate[q.id].answers[q.answers[x1].id] = {'min':q.answers[x1].min,'max':q.answers[x1].max,'step':q.answers[x1].step};
}
YAHOO.util.Event.addListener(q.answers[x].id, "keyup", numberHandler, q.answers[x]);
YAHOO.util.Event.addListener(q.answers[x1].id, "keyup", numberHandler, q.answers[x1]);
}
}
continue;

View file

@ -1,5 +1,4 @@
/*global Survey, YAHOO */
/*global Survey, YAHOO, alert, window */
if (typeof Survey === "undefined") {
var Survey = {};
}
@ -20,7 +19,7 @@ if (typeof Survey === "undefined") {
//YAHOO.log('setForm was true');
}
if (callMade) {
alert("Waiting on previous request");
alert("Your previous action is still being processed. Please try again.");
}
else {
callMade = 1;
@ -40,7 +39,14 @@ if (typeof Survey === "undefined") {
window.scrollTo(0, 0);
callMade = 0;
var response = '';
response = YAHOO.lang.JSON.parse(o.responseText);
try {
response = YAHOO.lang.JSON.parse(o.responseText);
}
catch (err) {
YAHOO.log(err);
alert("Oops.. A problem was encountered. Please try again.");
return;
}
if (response.type === 'displayquestions') {
Survey.Form.displayQuestions(response);
}

View file

@ -1,4 +1,4 @@
/*global Survey, YAHOO */
/*global Survey, YAHOO, alert */
if (typeof Survey === "undefined") {
var Survey = {};
}
@ -55,7 +55,9 @@ Survey.Data = (function(){
focus = d.address;//What is the current highlighted item.
var warnings = "";
for(var w in d.warnings){
warnings += "<div class='warning'>" + d.warnings[w] + "</div>";
if (YAHOO.lang.hasOwnProperty(d.warnings, w)) {
warnings += "<div class='warning'>" + d.warnings[w] + "</div>";
}
}
if (document.getElementById('warnings')) {
if (warnings !== "") {
@ -111,7 +113,9 @@ Survey.Data = (function(){
}
// (re)Add resize handler
Survey.Data.ddContainerResize && Survey.Data.ddContainerResize.destroy();
if (Survey.Data.ddContainerResize) {
Survey.Data.ddContainerResize.destroy();
}
Survey.Data.ddContainerResize = new YAHOO.util.Resize('sections-panel', {
proxy: true,
minWidth: 300,
@ -137,7 +141,9 @@ Survey.Data = (function(){
YAHOO.util.Dom.addClass(selectedId, 'selected');
}
sButton && sButton.destroy();
if (sButton) {
sButton.destroy();
}
sButton = new YAHOO.widget.Button({
label: "Add Section",
id: "addSection",
@ -145,7 +151,9 @@ Survey.Data = (function(){
});
sButton.on("click", this.addSection);
qButton && qButton.destroy();
if (qButton) {
qButton.destroy();
}
qButton = new YAHOO.widget.Button({
label: "Add Question",
id: "addQuestion",
@ -154,7 +162,9 @@ Survey.Data = (function(){
qButton.on("click", this.addQuestion, d.buttons.question);
if (d.buttons.answer) {
aButton && aButton.destroy();
if (aButton) {
aButton.destroy();
}
aButton = new YAHOO.widget.Button({
label: "Add Answer",
id: "addAnswer",

View file

@ -1,3 +1,4 @@
/*global Survey, YAHOO, alert */
if (typeof Survey == "undefined") {
var Survey = {};
}
@ -13,7 +14,7 @@ Survey.Comm = new function(){
callMade = 1;
YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}
}
};
this.callback = {
success:function(o){
YAHOO.util.Dom.setStyle('mask-all','display','none');
@ -21,7 +22,7 @@ Survey.Comm = new function(){
Survey.Data.loadData(YAHOO.lang.JSON.parse(o.responseText));
},
failure: function(o){
YAHOO.util.Dom.setStyle('mask-all','display','none')
YAHOO.util.Dom.setStyle('mask-all','display','none');
callMade = 0;
alert("Last request failed");
Survey.Data.loadLast();
@ -32,47 +33,47 @@ Survey.Comm = new function(){
var postData = "data="+p;
var sUrl = "?func=loadSurvey";
request(sUrl,this.callback,postData);
}
};
this.dragDrop = function(target,before){
var p = {};
p['target'] = target;
p['before'] = before;
p.target = target;
p.before = before;
var postData = "data="+YAHOO.lang.JSON.stringify(p);
var sUrl = "?func=dragDrop";
request(sUrl,this.callback,postData);
}
};
this.submitEdit = function(p){
var postData = "data="+YAHOO.lang.JSON.stringify(p);
var sUrl = "?func=submitEdit";
request(sUrl,this.callback,postData);
}
};
this.newSection = function(){
var sUrl = "?func=newObject";
request(sUrl,this.callback);
}
};
this.newQuestion = function(id){
var postData = "data="+id;
var sUrl = "?func=newObject";
request(sUrl,this.callback,postData);
}
};
this.newAnswer = function(id){
var postData = "data="+id;
var sUrl = "?func=newObject";
request(sUrl,this.callback,postData);
}
};
this.deleteAnswer = function(id){
var postData = "data="+id;
var sUrl = "?func=deleteAnswer";
request(sUrl,this.callback,postData);
}
};
this.deleteQuestion = function(id){
var postData = "data="+id;
var sUrl = "?func=deleteQuestion";
request(sUrl,this.callback,postData);
}
};
this.deleteSection = function(id){
var postData = "data="+id;
var sUrl = "?func=deleteSection";
request(sUrl,this.callback,postData);
}
};
}();

View file

@ -1,5 +1,4 @@
/*global Survey, YAHOO */
/*global Survey, YAHOO, alert, initHoverHelp, window */
if (typeof Survey === "undefined") {
var Survey = {};
}
@ -55,7 +54,7 @@ Survey.ObjectTemplate = (function(){
// Remove all hover-help
var hovers = document.getElementsByClassName('wg-hoverhelp');
for (i = 0; i < hovers.length; i++) {
for (var i = 0; i < hovers.length; i++) {
var hover = hovers[i];
if (!hover) {
continue;
@ -128,14 +127,14 @@ Survey.ObjectTemplate = (function(){
this.submit();
}
}
}
};
btns[btns.length] = {
text: "Remove Default Type",
handler: function(){
document.getElementById('removetype').value = 1;
this.submit();
}
}
};
}
dialog = new YAHOO.widget.Dialog(type, {