Diff for /loncom/interface/lonhelper.pm between versions 1.5 and 1.6

version 1.5, 2003/04/10 18:02:09 version 1.6, 2003/04/11 17:21:18
Line 472  sub preprocess { Line 472  sub preprocess {
     }      }
 }  }
   
   # FIXME: Document that all postprocesses must return a true value or
   # the state transition will be overridden
 sub postprocess {  sub postprocess {
     my $self = shift;      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}}) {      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;
     }      }
 }  }
   
Line 690  sub postprocess { Line 705  sub postprocess {
     if (defined($self->{NEXTSTATE})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
   
       return 1;
 }  }
 1;  1;
   
Line 826  sub render { Line 843  sub render {
     my $result = '';      my $result = '';
   
     if ($self->{'multichoice'}) {      if ($self->{'multichoice'}) {
         $result = <<SCRIPT;          $result .= <<SCRIPT;
 <script>  <script>
     function checkall(value) {      function checkall(value) {
  for (i=0; i<document.forms.wizform.elements.length; i++) {   for (i=0; i<document.forms.wizform.elements.length; i++) {
Line 839  SCRIPT Line 856  SCRIPT
 <br />  <br />
 <input type="button" onclick="checkall(true)" value="Select All" />  <input type="button" onclick="checkall(true)" value="Select All" />
 <input type="button" onclick="checkall(false)" value="Unselect All" />  <input type="button" onclick="checkall(false)" value="Unselect All" />
 <br />  <br />&nbsp;
 BUTTONS  BUTTONS
     }      }
   
     if (defined $self->{ERROR_MSG}) {      if (defined $self->{ERROR_MSG}) {
         $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';          $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
     }      }
   
     $result .= $buttons;      $result .= $buttons;
       
     $result .= "<table>\n\n";      $result .= "<table>\n\n";
   
     my $type = "radio";      my $type = "radio";
Line 878  sub postprocess { Line 895  sub postprocess {
     my $self = shift;      my $self = shift;
     my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'};      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})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
Line 889  sub postprocess { Line 917  sub postprocess {
             }              }
         }          }
     }      }
       return 1;
 }  }
 1;  1;
   
Line 1089  sub postprocess { Line 1118  sub postprocess {
         $checkDate->year + 1900 != $year) {          $checkDate->year + 1900 != $year) {
         $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "          $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "
             . "date because it doesn't exist. Please enter a valid date.";              . "date because it doesn't exist. Please enter a valid date.";
         return;          return 0;
     }      }
   
     $helper->{VARS}->{$var} = $chosenDate;      $helper->{VARS}->{$var} = $chosenDate;
Line 1097  sub postprocess { Line 1126  sub postprocess {
     if (defined($self->{NEXTSTATE})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
   
       return 1;
 }  }
 1;  1;
   
Line 1304  sub postprocess { Line 1335  sub postprocess {
     if (defined($self->{NEXTSTATE})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
   
       return 1;
 }  }
   
 1;  1;
Line 1434  BUTTONS Line 1467  BUTTONS
     return $result;      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;  1;
   
 package Apache::lonhelper::files;  package Apache::lonhelper::files;
Line 1579  BUTTONS Line 1633  BUTTONS
   
     $result .= $buttons;      $result .= $buttons;
   
       if (defined $self->{ERROR_MSG}) {
           $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
       }
   
     $result .= '<table border="0" cellpadding="1" cellspacing="1">';      $result .= '<table border="0" cellpadding="1" cellspacing="1">';
   
     # Keeps track if there are no choices, prints appropriate error      # Keeps track if there are no choices, prints appropriate error
Line 1621  BUTTONS Line 1679  BUTTONS
   
 sub postprocess {  sub postprocess {
     my $self = shift;      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'}) {      if ($self->{'multichoice'}) {
         $self->process_multiple_choices($self->{'variable'}.'.forminput',          $self->process_multiple_choices($self->{'variable'}.'.forminput',
                                         $self->{'variable'});                                          $self->{'variable'});
Line 1628  sub postprocess { Line 1693  sub postprocess {
     if (defined($self->{NEXTSTATE})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
   
       return 1;
 }  }
   
 1;  1;

Removed from v.1.5  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>