Diff for /loncom/interface/Attic/lonwizard.pm between versions 1.3 and 1.4

version 1.3, 2003/01/30 19:34:24 version 1.4, 2003/02/07 19:30:43
Line 5  package Apache::lonwizard; Line 5  package Apache::lonwizard;
   
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::loncommon;  use Apache::loncommon;
   use Apache::lonnet;
   
 =head1 lonwizard - HTML "Wizard" framework for LON-CAPA  =head1 lonwizard - HTML "Wizard" framework for LON-CAPA
   
Line 253  HEADER Line 254  HEADER
         }          }
         else          else
         {          {
               $result .= '<input name="back" type="button" ';
               $result .= 'value="&lt;- Previous" onclick="history.go(-1)" /> ';
             $result .= '<input name="SUBMIT" type="submit" value="Next -&gt;" />';              $result .= '<input name="SUBMIT" type="submit" value="Next -&gt;" />';
         }          }
         $result .= "</center>\n";          $result .= "</center>\n";
Line 310  sub setVar { Line 313  sub setVar {
   
 =pod  =pod
   
   =item B<queryStringVars>(): Returns a string representing the current state of the wizard, suitable for use directly as part of a query string. (See resource_state for an example.)
   
   =cut
   
   sub queryStringVars {
       my $self = shift;
   
       my @queryString = ();
       
       for my $varname (keys %{$self->{VARS}}) {
           push @queryString, Apache::lonnet::escape($varname) . "=" .
               Apache::lonnet::escape($self->{VARS}{$varname});
       }
       push @queryString, 'CURRENT_STATE=' . Apache::lonnet::escape($self->{STATE});
       push @queryString, 'RETURN_PAGE=' . Apache::lonnet::escape($self->{RETURN_PAGE});
   
       return join '&', @queryString;
   }
   
   =pod
   
 =item B<setDone>(): If a state calls this, the wizard will consider itself completed. The state should display a friendly "Done" message, and the wizard will display a link returning the user to the invoking page, rather then a "Next" button.  =item B<setDone>(): If a state calls this, the wizard will consider itself completed. The state should display a friendly "Done" message, and the wizard will display a link returning the user to the invoking page, rather then a "Next" button.
   
 =cut  =cut
Line 1081  Note this state will not automatically a Line 1105  Note this state will not automatically a
   
 =over 4  =over 4
   
 =item overriddent method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, filterFunction, choiceFunction): messageBefore and messageAfter appear before and after the state choice, respectively. nextState is the state to proceed to after the choice. varName is the wizard variable to store the choice in.  =item overriddent method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, filterFunction, choiceFunction, multichoice): messageBefore and messageAfter appear before and after the state choice, respectively. nextState is the state to proceed to after the choice. varName is the wizard variable to store the choice in.
   
 filterFunction is a function reference that receives the current resource as an argument, and returns 1 if it should be displayed, and 0 if it should not be displayed. By default, the class will use sub {return 1;}, which will show all resources. choiceFunction is a reference to a function that receives the resource object as a parameter and returns 1 if it should be a *selectable choice*, and 0 if not. By default, this is the same as the filterFunction, which means all displayed choices will be choosable. See parm wizard for an example of this in the resource selection routines.  filterFunction is a function reference that receives the current resource as an argument, and returns 1 if it should be displayed, and 0 if it should not be displayed. By default, the class will use sub {return 1;}, which will show all resources. choiceFunction is a reference to a function that receives the resource object as a parameter and returns 1 if it should be a *selectable choice*, and 0 if not. By default, this is the same as the filterFunction, which means all displayed choices will be choosable. See parm wizard for an example of this in the resource selection routines.
   
   multichoice specifies whether the state should provide radio buttons, allowing the user one choice, or checkboxes, allowing the user multiple choices, and automatically including some convenience buttons the user can choose (like "Check All" and "Uncheck All"), implemented with Javascript. Defaults to false, allow just one choice.
   
 =back  =back
   
 =cut  =cut
Line 1110  sub new { Line 1136  sub new {
     if (!defined($self->{CHOICE_FUNC})) {      if (!defined($self->{CHOICE_FUNC})) {
         $self->{CHOICE_FUNC} = $self->{FILTER_FUNC};          $self->{CHOICE_FUNC} = $self->{FILTER_FUNC};
     }      }
       $self->{MULTICHOICE} = shift;
       if (!defined($self->{MULTICHOICE})) {
           $self->{MULTICHOICE} = 0;
       }
 }  }
   
 sub postprocess {  sub postprocess {
     my $self = shift;      my $self = shift;
     my $wizard = $self->{WIZARD};      my $wizard = $self->{WIZARD};
   
       # If we were just manipulating a folder, do not proceed to the
       # next state
       if ($ENV{'form.folderManip'}) {
           return;
       }
   
     my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . ".forminput"};      my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . ".forminput"};
     $wizard->setVar($self->{VAR_NAME}, $chosenValue)      $wizard->setVar($self->{VAR_NAME}, $chosenValue)
         if (defined($self->{VAR_NAME}));          if (defined($self->{VAR_NAME}));
Line 1124  sub postprocess { Line 1161  sub postprocess {
   
 sub render {  sub render {
     my $self = shift;      my $self = shift;
       my $wizard = $self->{WIZARD};
     my $result = "";      my $result = "";
     my $var = $self->{VAR_NAME};      my $var = $self->{VAR_NAME};
     my $curVal = $self->{WIZARD}->{VARS}->{$var};      my $curVal = $self->{WIZARD}->{VARS}->{$var};
       my $vals = {};
       if ($curVal =~ /,/) { # multiple choices
           foreach (split /,/, $curVal) {
               $vals->{$_} = 1;
           }
       } else {
           $vals->{$curVal} = 1;
       }
   
     $result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE});      $result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE});
   
Line 1139  sub render { Line 1185  sub render {
         return "<font color='red' size='+1'>Something has gone wrong with the map selection feature. Please contact your administrator.</font>";          return "<font color='red' size='+1'>Something has gone wrong with the map selection feature. Please contact your administrator.</font>";
     }      }
   
     my $iterator = $navmap->getIterator(undef, undef, undef, 1, 0);      my $iterator = $navmap->getIterator(undef, undef, undef, 0, 0);
     my $depth = 1;  
     $iterator->next(); # discard first BEGIN_MAP  
     my $curRes = $iterator->next();  
     my $i;  
     my $padding = "&nbsp;&nbsp;";  
     my $isChoosable = 0;  
     my $filterFunc = $self->{FILTER_FUNC};      my $filterFunc = $self->{FILTER_FUNC};
     my $choiceFunc = $self->{CHOICE_FUNC};      my $choiceFunc = $self->{CHOICE_FUNC};
   
     $result .= "<table border='0'>\n";      # Create the composite function that renders the column on the nav map
       my $renderColFunc = sub {
     while ($depth > 0) {          my ($resource, $part, $params) = @_;
         if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }          
         if ($curRes == $iterator->END_MAP()) { $depth--; }          if (!&$choiceFunc($resource)) {
               return '<td>&nbsp;</td>';
         if (ref($curRes) && &$filterFunc($curRes)) {          } else {
             $result .= "<tr><td>";              my $col = "<td><input type='radio' name='${var}.forminput' ";
               if ($vals->{$resource->{ID}}) {
             if (&$choiceFunc($curRes)) {                  $col .= "checked ";
                 if (!$curVal) {  
                     # Set this to the first one if they have no previous  
                     # selection.  
                     $curVal = $curRes->{ID};   
                 }  
   
                 $isChoosable = 1;  
                 $result .= "<input type='radio' name='${var}.forminput'";  
                 if ($curRes->{ID} eq $curVal) {  
                     $result .= " checked";  
                 }  
                 $result .= ' value="' . $curRes->{ID} . '" />';  
             }  
   
             $result .= "</td><td>";  
   
             for ($i = 0; $i < $depth; $i++) {  
                 $result .= $padding;  
             }              }
               $col .= "value='" . $resource->{ID} . "' /></td>";
             #$result .= "<img border='0' src='/adm/lonIcons/navmap.folder.open.gif'>";              return $col;
             $result .= $curRes->compTitle . "</td></tr>\n";  
         }          }
       };
   
         $curRes = $iterator->next();      $result .= 
     }          &Apache::lonnavmaps::render( { "iterator" => $iterator,
                                          'cols' => [$renderColFunc, 
     $result .= "</table>\n";                                                    Apache::lonnavmaps::resource()],
                                          'showParts' => 0,
                                          'queryString' => $wizard->queryStringVars() . '&folderManip=1',
                                          'url' => '/adm/wizard'} );
                                                   
     $navmap->untieHashes();      $navmap->untieHashes();
   
     if (!$isChoosable) {  
         # FIXME: Check all the wiz vars for this.  
         $result .= "<p><font color='#ff0000'>There are no valid resources to select in this course.</font> The entire course will be selected by default (as if 1you selected &quot;Set for Whole Course&quot; on the previous screen).</p>";  
         $result .= "<input type='hidden' name='${var}.forminput' value='0.0' />\n";  
     }   
   
     $result .= "<p>(Note: I need to add the icons in.)</p>";  
     $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER});      $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER});
   
     return $result;      return $result;

Removed from v.1.3  
changed lines
  Added in v.1.4


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