--- loncom/interface/lonhelper.pm 2003/04/10 18:02:09 1.5 +++ loncom/interface/lonhelper.pm 2003/04/11 17:21:18 1.6 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.5 2003/04/10 18:02:09 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.6 2003/04/11 17:21:18 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -472,11 +472,26 @@ sub preprocess { } } +# FIXME: Document that all postprocesses must return a true value or +# the state transition will be overridden sub postprocess { my $self = shift; - + + # Save the state so we can roll it back if we need to. + my $originalState = $helper->{STATE}; + my $everythingSuccessful = 1; + for my $element (@{$self->{ELEMENTS}}) { - $element->postprocess(); + my $result = $element->postprocess(); + if (!$result) { $everythingSuccessful = 0; } + } + + # If not all the postprocesses were successful, override + # any state transitions that may have occurred. It is the + # responsibility of the states to make sure they have + # error handling in that case. + if (!$everythingSuccessful) { + $helper->{STATE} = $originalState; } } @@ -690,6 +705,8 @@ sub postprocess { if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } + + return 1; } 1; @@ -826,7 +843,7 @@ sub render { my $result = ''; if ($self->{'multichoice'}) { - $result = < function checkall(value) { for (i=0; i -
+
  BUTTONS } if (defined $self->{ERROR_MSG}) { - $result .= '' . $self->{ERROR_MSG} . '

'; + $result .= '
' . $self->{ERROR_MSG} . '
'; } $result .= $buttons; - + $result .= "\n\n"; my $type = "radio"; @@ -878,6 +895,17 @@ sub postprocess { my $self = shift; my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'}; + if (!$chosenValue) { + $self->{ERROR_MSG} = "You must choose one or more choices to" . + " continue."; + return 0; + } + + if ($self->{'multichoice'}) { + $self->process_multiple_choices($self->{'variable'}.'.forminput', + $self->{'variable'}); + } + if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } @@ -889,6 +917,7 @@ sub postprocess { } } } + return 1; } 1; @@ -1089,7 +1118,7 @@ sub postprocess { $checkDate->year + 1900 != $year) { $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a " . "date because it doesn't exist. Please enter a valid date."; - return; + return 0; } $helper->{VARS}->{$var} = $chosenDate; @@ -1097,6 +1126,8 @@ sub postprocess { if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } + + return 1; } 1; @@ -1304,6 +1335,8 @@ sub postprocess { if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } + + return 1; } 1; @@ -1434,6 +1467,27 @@ BUTTONS return $result; } +sub postprocess { + my $self = shift; + + my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'}; + if (!$result) { + $self->{ERROR_MSG} = 'You must choose at least one student '. + 'to continue.'; + return 0; + } + + if ($self->{'multichoice'}) { + $self->process_multiple_choices($self->{'variable'}.'.forminput', + $self->{'variable'}); + } + if (defined($self->{NEXTSTATE})) { + $helper->changeState($self->{NEXTSTATE}); + } + + return 1; +} + 1; package Apache::lonhelper::files; @@ -1579,6 +1633,10 @@ BUTTONS $result .= $buttons; + if (defined $self->{ERROR_MSG}) { + $result .= '
' . $self->{ERROR_MSG} . '

'; + } + $result .= '
'; # Keeps track if there are no choices, prints appropriate error @@ -1621,6 +1679,13 @@ BUTTONS sub postprocess { my $self = shift; + my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'}; + if (!$result) { + $self->{ERROR_MSG} = 'You must choose at least one file '. + 'to continue.'; + return 0; + } + if ($self->{'multichoice'}) { $self->process_multiple_choices($self->{'variable'}.'.forminput', $self->{'variable'}); @@ -1628,6 +1693,8 @@ sub postprocess { if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } + + return 1; } 1;