Diff for /loncom/interface/lonhelper.pm between versions 1.176 and 1.180.2.2

version 1.176, 2009/06/15 11:18:11 version 1.180.2.2, 2010/09/02 00:19:17
Line 571  sub process { Line 571  sub process {
 # 4: Render the current state to the screen as an HTML page.  # 4: Render the current state to the screen as an HTML page.
 sub display {  sub display {
     my $self = shift;      my $self = shift;
       my $footer = shift;
     my $state = $self->{STATES}{$self->{STATE}};      my $state = $self->{STATES}{$self->{STATE}};
   
     my $result = "";      my $result = "";
Line 606  sub display { Line 606  sub display {
     # FIXME: This should be parameterized, not concatenated - Jeremy      # FIXME: This should be parameterized, not concatenated - Jeremy
   
   
     if (!$state->overrideForm()) { $result.='<form name="helpform" method="post">'; }      if (!$state->overrideForm()) { $result.='<form name="helpform" method="post" action="">'; }
     if ($stateHelp) {      if ($stateHelp) {
         $stateHelp = &Apache::loncommon::help_open_topic($stateHelp);          $stateHelp = &Apache::loncommon::help_open_topic($stateHelp);
     }      }
Line 661  sub display { Line 661  sub display {
         </form>          </form>
 FOOTER  FOOTER
   
     $result .= &Apache::loncommon::end_page();      $result .= $footer.&Apache::loncommon::end_page();
     # Handle writing out the vars to the file      # Handle writing out the vars to the file
     my $file = Apache::File->new('>'.$self->{FILENAME});      my $file = Apache::File->new('>'.$self->{FILENAME});
     print $file $self->_varsInFile();      print $file $self->_varsInFile();
Line 2066  the toplevel default.sequence in the res Line 2066  the toplevel default.sequence in the res
   evaluated with "sub { my $helper = shift; my $state = shift;" and    evaluated with "sub { my $helper = shift; my $state = shift;" and
   "}", with the return value used as the mapurl.    "}", with the return value used as the mapurl.
   
   =item * <option />: Allows you to add optional elements to the
     resource chooser currently these can be a checkbox, or a text entry
     or hidden (see the 'type' attribute below).
     the following attributes are supported by this tag:
   
   =over 4
   
   =item * type=control-type : determines the type of control displayed.
     This can be one of the following types: 'checkbox' provides a true/false
     checkbox.  'text' provides a text entry control. 'hidden' provides a
     hidden form element that returns the name of the resource for each
     element of the text box.
   
   =item * text=header-text : provides column header text for the option.
     
   =item * variable=helpervar : provides a helper variable to contain the
     value of the input control for each resource.  In general, the result
     will be a set of values separated by |||  for the checkbox the value between
     the |||'s will either be empty, if the box is not checked, or the resource
     name if checked.  For the text entry, the values will be the text in the
     text box.  This could be empty.  Hidden elements unconditionally provide
     the resource name for each row of the chooser and allow you to therefore
     correlate text entries to their resources.
     The helper variable can be initialized by the user code to pre-load values
     into the controls:
   
   =over 4
   
     
   =item * Preloading checkboxes : Set the helper variable to the value you
      would have gotten from the control if it had been manually set as desired.
   
   =item * Preloading text entries : Set the helper variable to triple pipe
      separated values where each value is of the form resource-name=value
   
   =item * Preloading hidden fields : These cannot be pre-loaded and will always
     be pipe separated resource names.
   
   =back
   
   
   =back
   
 =back  =back
   
 =cut  =cut
Line 2195  sub start_option { Line 2238  sub start_option {
     if (!defined($paramHash->{OPTION_TEXTS})) {      if (!defined($paramHash->{OPTION_TEXTS})) {
  $paramHash->{OPTION_TEXTS} = [ ];   $paramHash->{OPTION_TEXTS} = [ ];
  $paramHash->{OPTION_VARS}  = [ ];   $paramHash->{OPTION_VARS}  = [ ];
    $paramHash->{OPTION_TYPES} = [ ];
   
     }      }
       #  We can have an attribute: type which can have the
       #  values: "checkbox" or "text" which defaults to 
       #           checkbox allowing us to change the type of input
       #           for the option:
       #
       my $input_widget_type = 'checkbox';
       if(defined($token->[2]{'type'})) {
    my $widget_type  = $token->[2]{'type'};
    if ($widget_type eq 'text') {          # only accept legal alternatives
       $input_widget_type = $widget_type; # Illegals are checks.
    } elsif ($widget_type eq 'hidden') {
       $input_widget_type = $widget_type;
    }
       }
   
     # OPTION_TEXTS is a list of the text attribute      # OPTION_TEXTS is a list of the text attribute
     #               values used to create column headings.      #               values used to create column headings.
     # OPTION_VARS is a list of the variable names, used to create the checkbox      # OPTION_VARS is a list of the variable names, used to create the checkbox
     #             inputs.      #             inputs.
       # OPTION_TYPES is a list of the option types:
       #
     #  We're ok with empty elements. as place holders      #  We're ok with empty elements. as place holders
     # Although the 'variable' element should really exist.      # Although the 'variable' element should really exist.
     #      #
   
   
     my $option_texts  = $paramHash->{OPTION_TEXTS};      my $option_texts  = $paramHash->{OPTION_TEXTS};
     my $option_vars   = $paramHash->{OPTION_VARS};      my $option_vars   = $paramHash->{OPTION_VARS};
       my $option_types   = $paramHash->{OPTION_TYPES};
     push(@$option_texts,  $token->[2]{'text'});      push(@$option_texts,  $token->[2]{'text'});
     push(@$option_vars,   $token->[2]{'variable'});      push(@$option_vars,   $token->[2]{'variable'});
       push(@$option_types,   $input_widget_type);
   
   
     #  Need to create and declare the option variables as well to make them      #  Need to create and declare the option variables as well to make them
     # persistent.      # persistent.
Line 2284  BUTTONS Line 2349  BUTTONS
     my $multichoice    = $self->{'multichoice'};      my $multichoice    = $self->{'multichoice'};
     my $option_vars    = $self->{OPTION_VARS};      my $option_vars    = $self->{OPTION_VARS};
     my $option_texts   = $self->{OPTION_TEXTS};      my $option_texts   = $self->{OPTION_TEXTS};
       my $option_types   = $self->{OPTION_TYPES};
     my $addparts       = $self->{'addparts'};      my $addparts       = $self->{'addparts'};
     my $headings_done  = 0;      my $headings_done  = 0;
   
Line 2342  BUTTONS Line 2408  BUTTONS
     my $resource_name =         my $resource_name =   
                    HTML::Entities::encode($raw_name,"<>&\"'");                     HTML::Entities::encode($raw_name,"<>&\"'");
     if($option_vars) {      if($option_vars) {
    my $option_num = 0;
  foreach my $option_var (@$option_vars) {   foreach my $option_var (@$option_vars) {
       my $option_type = $option_types->[$option_num];
       $option_num++;
     my $var_value = "\|\|\|" . $helper->{VARS}->{$option_var} .       my $var_value = "\|\|\|" . $helper->{VARS}->{$option_var} . 
  "\|\|\|";   "\|\|\|";
     my $checked ="";      my $checked ="";
     if($var_value =~ /\Q|||$raw_name|||\E/) {      if($var_value =~ /\Q|||$raw_name|||\E/) {
  $checked = "checked='checked'";   $checked = "checked='checked'";
     }      }
     $col .=       if ($option_type eq 'text') {
                         "<td align='center'><input type='checkbox' name ='$option_var".   #
  "_forminput' value='".   # For text's the variable value is a ||| separated set of
  $resource_name . "' $checked /> </td>";   # resource_name=value 
    #
    my @values = split(/\|\|\|/, $helper->{VARS}->{$option_var});
   
    # Normal practice would be to toss this in a hash but 
    # the only thing that saves is the compare in the loop
    # below and for all but one case we'll break out of the loop
    # before it completes.
   
    my $text_value = '';    # In case there's no match.
    foreach my $value (@values) {
       my ($res, $skip) = split(/=/, $value);
       if($res eq $resource_name) {
    $text_value = $skip;
    last;
       }
    }
    # TODO: add an attribute to <option> that allows the
    #       programmer to set the width of the tex entry box.
   
    $col .=
       "<td align='center'><input type='text' name ='$option_var".
       "_forminput' value='".$text_value."' size='5' /> </td>";
       } elsif ($option_type eq 'hidden') {
     $col .= "<td align='center'><input type='hidden' name ='$option_var".
       "_forminput' value='".
       $resource_name . "'/> </td>";
       } else {
    $col .= 
       "<td align='center'><input type=$option_type name ='$option_var".
       "_forminput' value='".
       $resource_name . "' $checked /> </td>";
       }
  }   }
     }      }
   
Line 3188  package Apache::lonhelper::string; Line 3289  package Apache::lonhelper::string;
 string elements provide a string entry field for the user. string elements  string elements provide a string entry field for the user. string elements
 take the usual 'variable' and 'nextstate' parameters. string elements  take the usual 'variable' and 'nextstate' parameters. string elements
 also pass through 'maxlength' and 'size' attributes to the input tag.  also pass through 'maxlength' and 'size' attributes to the input tag.
   Since you could have multiple strings in a helper state, each with its own
   validator, all but the last string should have
   noproceed='1' so that _all_ validators are evaluated before the next
   state can be reached.
   
 string honors the defaultvalue tag, if given.  string honors the defaultvalue tag, if given.
   
Line 3207  BEGIN { Line 3312  BEGIN {
   
 sub new {  sub new {
     my $ref = Apache::lonhelper::element->new();      my $ref = Apache::lonhelper::element->new();
       $ref->{'PROCEED'} = 1;      # By default postprocess goes to next state.
     bless($ref);      bless($ref);
 }  }
   
Line 3223  sub start_string { Line 3329  sub start_string {
     $paramHash->{'nextstate'} = $token->[2]{'nextstate'};      $paramHash->{'nextstate'} = $token->[2]{'nextstate'};
     $paramHash->{'maxlength'} = $token->[2]{'maxlength'};      $paramHash->{'maxlength'} = $token->[2]{'maxlength'};
     $paramHash->{'size'} = $token->[2]{'size'};      $paramHash->{'size'} = $token->[2]{'size'};
   
     return '';      return '';
 }  }
   
 sub end_string {  sub end_string {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
   
     if ($target ne 'helper') {      if ($target ne 'helper') {
         return '';          return '';
     }      }
     Apache::lonhelper::string->new();      my $state = Apache::lonhelper::string->new();
   
   
       if(&Apache::lonxml::get_param('noproceed', $parstack, $safeeval, undef, 1)) {
    $state->noproceed();
       }
   
      
   
     return '';      return '';
 }  }
   
   sub noproceed() {
       my $self = shift;
       $self->{PROCEED}  = 0;
   }
   
 sub render {  sub render {
     my $self = shift;      my $self = shift;
     my $result = '';      my $result = '';
Line 3280  sub postprocess { Line 3399  sub postprocess {
  }   }
     }      }
   
     if (defined($self->{'nextstate'})) {      if (defined($self->{'nextstate'}) && $self->{PROCEED}) {
         $helper->changeState($self->{'nextstate'});          $helper->changeState($self->{'nextstate'});
     }      }
   

Removed from v.1.176  
changed lines
  Added in v.1.180.2.2


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