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

version 1.3, 2003/03/27 20:58:16 version 1.4, 2003/03/28 20:25:19
Line 105  use Apache::lonxml; Line 105  use Apache::lonxml;
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register('Apache::lonhelper',       &Apache::lonxml::register('Apache::lonhelper', 
                               ('helper', 'state', 'message'));                                ('helper', 'state'));
 }  }
   
 # Since all wizards are only three levels deep (wizard tag, state tag,   # Since all wizards are only three levels deep (wizard tag, state tag, 
Line 115  BEGIN { Line 115  BEGIN {
 my $helper;  my $helper;
 my $state;  my $state;
 my $substate;  my $substate;
   # To collect parameters, the contents of the subtags are collected
   # into this paramHash, then passed to the element object when the 
   # end of the element tag is located.
   my $paramHash; 
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
Line 160  sub start_helper { Line 164  sub start_helper {
     }      }
           
     $helper = Apache::lonhelper::helper->new($token->[2]{'title'});      $helper = Apache::lonhelper::helper->new($token->[2]{'title'});
     return 'helper made';      return '';
 }  }
   
 sub end_helper {  sub end_helper {
Line 170  sub end_helper { Line 174  sub end_helper {
         return '';          return '';
     }      }
           
     return 'Helper ended.';      return '';
 }  }
   
 sub start_state {  sub start_state {
Line 190  sub end_state { Line 194  sub end_state {
     return '';      return '';
 }  }
   
 sub start_message {  
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;  
   
     if ($target ne 'helper') {  
         return '';  
     }  
       
     return &Apache::lonxml::get_all_text("/message", $parser);  
 }  
   
 sub end_message {  
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;  
   
     if ($target ne 'helper') {  
         return '';  
     }  
       
     return '';  
 }  
   
 1;  1;
   
 package Apache::lonhelper::helper;  package Apache::lonhelper::helper;
Line 430  FOOTER Line 414  FOOTER
 package Apache::lonhelper::state;  package Apache::lonhelper::state;
   
 # States bundle things together and are responsible for compositing the  # States bundle things together and are responsible for compositing the
 # various elements together  # various elements together. It is not generally necessary for users to
   # use the state object directly, so it is not perldoc'ed.
   
   # Basically, all the states do is pass calls to the elements and aggregate
   # the results.
   
 sub new {  sub new {
     my $proto = shift;      my $proto = shift;
Line 458  sub title { Line 446  sub title {
     return $self->{TITLE};      return $self->{TITLE};
 }  }
   
   sub preprocess {
       my $self = shift;
       for my $element (@{$self->{ELEMENTS}}) {
           $element->preprocess();
       }
   }
   
   sub postprocess {
       my $self = shift;
       
       for my $element (@{$self->{ELEMENTS}}) {
           $element->postprocess();
       }
   }
   
   sub overrideForm {
       return 0;
   }
   
   sub addElement {
       my $self = shift;
       my $element = shift;
       
       push @{$self->{ELEMENTS}}, $element;
   }
   
   sub render {
       my $self = shift;
       my @results = ();
   
       for my $element (@{$self->{ELEMENTS}}) {
           push @results, $element->render();
       }
       return join("\n", @results);
   }
   
   1;
   
   package Apache::lonhelper::element;
   # Support code for elements
   
   =pod
   
   =head2 Element Base Class
   
   The Apache::lonhelper::element base class provides support methods for
   the elements to use, such as a multiple value processer.
   
   B<Methods>:
   
   =over 4
   
   =item * process_multiple_choices(formName, varName): Process the form 
   element named "formName" and place the selected items into the helper 
   variable named varName. This is for things like checkboxes or 
   multiple-selection listboxes where the user can select more then 
   one entry. The selected entries are delimited by triple pipes in 
   the helper variables, like this:  CHOICE_1|||CHOICE_2|||CHOICE_3
   
   =back
   
   =cut
   
   # Because we use the param hash, this is often a sufficent
   # constructor
   sub new {
       my $proto = shift;
       my $class = ref($proto) || $proto;
       my $self = $paramHash;
       bless($self, $class);
   
       $self->{PARAMS} = $paramHash;
       $self->{STATE} = $state;
       $state->addElement($self);
       
       # Ensure param hash is not reused
       $paramHash = {};
   
       return $self;
   }   
   
   sub preprocess {
       return 1;
   }
   
   sub postprocess {
       return 1;
   }
   
   sub render {
       return '';
   }
   
 sub process_multiple_choices {  sub process_multiple_choices {
     my $self = shift;      my $self = shift;
     my $formname = shift;      my $formname = shift;
Line 483  sub process_multiple_choices { Line 564  sub process_multiple_choices {
     return;      return;
 }  }
   
 sub preprocess {  1;
     return 1;  
   package Apache::lonhelper::message;
   
   =pod
   
   =head2 Element: message
   
   Message elements display the contents of their <message_text> tags, and
   transition directly to the state in the <next_state> tag. Example:
   
    <message>
      <next_state>GET_NAME</next_state>
      <message_text>This is the <b>message</b> the user will see, 
                    <i>HTML allowed</i>.</message_text>
      </message>
   
   This will display the HTML message and transition to the <next_state> if
   given. The HTML will be directly inserted into the wizard, so if you don't
   want text to run together, you'll need to manually wrap the <message_text>
   in <p> tags, or whatever is appropriate for your HTML.
   
   This is also a good template for creating your own new states, as it has
   very little code beyond the state template.
   
   =cut
   
   no strict;
   @ISA = ("Apache::lonhelper::element");
   use strict;
   
   BEGIN {
       &Apache::lonxml::register('Apache::lonhelper::message',
                                 ('message', 'next_state', 'message_text'));
 }  }
   
 sub postprocess {  # Don't need to override the "new" from element
     return 1;  
   # CONSTRUCTION: Construct the message element from the XML
   sub start_message {
       return '';
 }  }
   
 sub overrideForm {  sub end_message {
     return 1;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       if ($target ne 'helper') {
           return '';
       }
       Apache::lonhelper::message->new();
       return '';
 }  }
   
 sub addElement {  sub start_next_state {
     my $self = shift;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $element = shift;  
       if ($target ne 'helper') {
           return '';
       }
           
     push @{$self->{ELEMENTS}}, $element;      $paramHash->{NEXT_STATE} = &Apache::lonxml::get_all_text('/next_state',
                                                                $parser);
       return '';
 }  }
   
   sub end_next_state { return ''; }
   
   sub start_message_text {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       if ($target ne 'helper') {
           return '';
       }
   
       $paramHash->{MESSAGE_TEXT} = &Apache::lonxml::get_all_text('/message_text',
                                                                  $parser);
   }
       
   sub end_message_text { return 1; }
   
 sub render {  sub render {
     my $self = shift;      my $self = shift;
     my @results = ();  
   
     for my $element (@{$self->{ELEMENTS}}) {      return $self->{MESSAGE_TEXT};
         push @results, $element->render();  }
   # If a NEXT_STATE was given, switch to it
   sub postprocess {
       my $self = shift;
       if (defined($self->{NEXT_STATE})) {
           $helper->changeState($self->{NEXT_STATE});
     }      }
     push @results, $self->title();  
     return join("\n", @results);  
 }  }
   1;
   
 __END__  __END__
   

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


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