Survey: more bug fixes

Fixed invalid calendar markup so that Date question type works in IE
Minor tweaks to ResponseJSON for more robustness
Fixed Number question type javascript
This commit is contained in:
Patrick Donelan 2009-05-24 09:59:43 +00:00
parent 3a25e806c6
commit 0ad26a1921
5 changed files with 69 additions and 48 deletions

View file

@ -102,11 +102,11 @@ sub reset {
startTime => time(),
surveyOrder => undef,
tags => {},
# And then data overrides
%{$data},
};
# And then data overrides (via a hash slice)
@{$self->{_response}}{keys %{$data}} = values %{$data};
# If first section is logical, process it immediately
$self->checkForLogicalSection;
return $self;
@ -1141,6 +1141,15 @@ sub nextQuestions {
last;
}
# In rare cases where you change the structure of your survey after
# someone has already started a response, it's possible for this
# to be triggered, in which case the easiest course of action is
# to just skip over the question.
if (!$self->survey->question( $address )) {
$self->session->log->debug("Unable to retrieve question for address $sIndex-$qIndex");
next;
}
# Make a safe copy of the question
my %questionCopy = %{$self->survey->question( $address )};
@ -1190,7 +1199,10 @@ sub nextQuestions {
}
} else {
for my $aIndex ( aIndexes($address) ) {
my %answerCopy = %{ $self->survey->answer( [ $sIndex, $qIndex, $aIndex ] ) };
my %answerCopy
= %{ $self->survey->answer( [ $sIndex, $qIndex, $aIndex ] )
|| $self->survey->newAnswer # in case the lookup fails, use a default answer
};
# Do text replacement
$answerCopy{text} = $self->getTemplatedText($answerCopy{text}, \%templateValues);

View file

@ -133,9 +133,6 @@ sub run {
$self->session->db->write( 'delete from Survey_response where assetId = ? and userId = ?',
[ $self->getId, $self->session->user->userId() ] );
# disable cookies so that test code doesn't die
$survey->responseIdCookies(0);
# Start a response as current user
my $responseId = $survey->responseId($self->session->user->userId)
or return { tap => "Bail Out! Unable to start survey response" };
@ -144,7 +141,6 @@ sub run {
my $rJSON = $survey->responseJSON
or return { tap => "Bail Out! Unable to get responseJSON" };
my %validTargets = map { $_ => 1 } @{$survey->surveyJSON->getGotoTargets};
my $surveyOrder = $rJSON->surveyOrder;
my $surveyOrderIndexByVariableName = $rJSON->surveyOrderIndexByVariableName;
@ -371,28 +367,24 @@ sub _setup {
# Setup any fake data the user wants prior to the test
if ($setup && ref $setup eq 'HASH') {
my %existingTags = %{$rJSON->tags};
# Process tags
# N.B. Make sure we add to existing tags instead of overwriting
my %tags;
if (ref $setup->{tag} eq 'HASH') {
# already a hash, so store it right away
$rJSON->tags( {%existingTags, %{$setup->{tag}} });
%tags = %{$setup->{tag}};
} elsif (ref $setup->{tag} eq 'ARRAY') {
# turn array into hash before storing it
my $tags;
for my $tag (@{$setup->{tag}}) {
if (ref $tag eq 'HASH') {
# Individual item is a single key/value hash
my ($key, $value) = %$tag;
$tags->{$key} = $value;
$tags{$key} = $value;
} else {
# Individual item is a string, default to boolean truth flag
$tags->{$tag} = 1; # default to 1
$tags{$tag} = 1; # default to 1
}
}
$rJSON->tags( {%existingTags, %$tags });
}
# N.B. Make sure we add to existing tags instead of overwriting
@{$rJSON->tags}{keys %tags} = values %tags;
}
}