--- loncom/interface/lonhelper.pm 2003/05/12 19:33:57 1.27 +++ loncom/interface/lonhelper.pm 2003/05/15 16:14:52 1.30 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.27 2003/05/12 19:33:57 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.30 2003/05/15 16:14:52 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -344,8 +344,6 @@ sub new { $self->{TITLE} = shift; - Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - # If there is a state from the previous form, use that. If there is no # state, use the start state parameter. if (defined $ENV{"form.CURRENT_STATE"}) @@ -461,7 +459,11 @@ sub declareVar { my $envname = 'form.' . $var . '.forminput'; if (defined($ENV{$envname})) { - $self->{VARS}->{$var} = $ENV{$envname}; + if (ref($ENV{$envname})) { + $self->{VARS}->{$var} = join('|||', @{$ENV{$envname}}); + } else { + $self->{VARS}->{$var} = $ENV{$envname}; + } } } @@ -545,17 +547,44 @@ sub display { $bodytag HEADER - if (!$state->overrideForm()) { $result.="
"; } + if (!$state->overrideForm()) { $result.=""; } $result .= <

$stateTitle

HEADER + $result .= "
"; + if (!$state->overrideForm()) { $result .= $self->_saveVars(); } - $result .= $state->render() . "

 

"; + $result .= $state->render(); + + $result .= "
"; + + # Warning: Copy and pasted from below, because it's too much trouble to + # turn this into a subroutine + if (!$state->overrideForm()) { + $result .= '
'; + if ($self->{STATE} ne $self->{START_STATE}) { + #$result .= '  '; + } + if ($self->{DONE}) { + my $returnPage = $self->{RETURN_PAGE}; + $result .= "End Helper"; + } + else { + $result .= 'overrideForm()) { $result .= '
'; if ($self->{STATE} ne $self->{START_STATE}) { @@ -566,9 +595,9 @@ HEADER $result .= "End Helper"; } else { - $result .= '{VARS}->{$key} . "
"; #} + $result .= "
"; + $result .= < @@ -689,6 +720,7 @@ sub render { for my $element (@{$self->{ELEMENTS}}) { push @results, $element->render(); } + return join("\n", @results); } @@ -701,23 +733,8 @@ package Apache::lonhelper::element; =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: - -=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 +The Apache::lonhelper::element base class provides support for elements +and defines some generally useful tags for use in elements. B @@ -831,28 +848,6 @@ sub overrideForm { return 0; } -sub process_multiple_choices { - my $self = shift; - my $formname = shift; - my $var = shift; - - # Must extract values from data directly, as there - # may be more then one. - my @values; - for my $formparam (split (/&/, $ENV{QUERY_STRING})) { - my ($name, $value) = split(/=/, $formparam); - if ($name ne $formname) { - next; - } - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; - push @values, $value; - } - $helper->{VARS}->{$var} = join('|||', @values); - - return; -} - 1; package Apache::lonhelper::message; @@ -1205,9 +1200,8 @@ sub postprocess { return 0; } - if ($self->{'multichoice'}) { - $self->process_multiple_choices($self->{'variable'}.'.forminput', - $self->{'variable'}); + if (ref($chosenValue)) { + $helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue); } if (defined($self->{NEXTSTATE})) { @@ -1453,7 +1447,10 @@ variable stores the results. It also tak which controls whether the user can select more then one resource. The "toponly" attribute controls whether the resource display shows just the resources in that sequence, or recurses into all sub-sequences, defaulting -to false. +to false. The "suppressEmptySequences" attribute reflects the +suppressEmptySequences argument to the render routine, which will cause +folders that have all of their contained resources filtered out to also +be filtered out. B @@ -1514,6 +1511,7 @@ sub start_resource { $paramHash->{'variable'} = $token->[2]{'variable'}; $helper->declareVar($paramHash->{'variable'}); $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; + $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'}; $paramHash->{'toponly'} = $token->[2]{'toponly'}; return ''; } @@ -1682,6 +1680,7 @@ BUTTONS 'showParts' => 0, 'filterFunc' => $filterFunc, 'resource_no_folder_link' => 1, + 'suppressEmptySequences' => $self->{'suppressEmptySequences'}, 'iterator_map' => $mapUrl } ); @@ -1693,11 +1692,6 @@ BUTTONS sub postprocess { my $self = shift; - if ($self->{'multichoice'}) { - $self->process_multiple_choices($self->{'variable'}.'.forminput', - $self->{'variable'}); - } - if ($self->{'multichoice'} && !$helper->{VARS}->{$self->{'variable'}}) { $self->{ERROR_MSG} = 'You must choose at least one resource to continue.'; return 0; @@ -1855,10 +1849,6 @@ sub postprocess { return 0; } - if ($self->{'multichoice'}) { - $self->process_multiple_choices($self->{'variable'}.'.forminput', - $self->{'variable'}); - } if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } @@ -2143,10 +2133,6 @@ sub postprocess { return 0; } - if ($self->{'multichoice'}) { - $self->process_multiple_choices($self->{'variable'}.'.forminput', - $self->{'variable'}); - } if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); }