$stateTitle
@@ -681,6 +684,7 @@ sub addElement {
push @{$self->{ELEMENTS}}, $element;
}
+use Data::Dumper;
sub render {
my $self = shift;
my @results = ();
@@ -688,6 +692,7 @@ sub render {
for my $element (@{$self->{ELEMENTS}}) {
push @results, $element->render();
}
+
return join("\n", @results);
}
@@ -700,23 +705,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
@@ -830,28 +820,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;
@@ -960,6 +928,10 @@ the result is stored in.
takes an attribute "multichoice" which, if set to a true
value, will allow the user to select multiple choices.
+ takes an attribute "allowempty" which, if set to a true
+value, will allow the user to select none of the choices without raising
+an error message.
+
B
can have the following subtags:
@@ -1049,6 +1021,7 @@ sub start_choices {
$paramHash->{'variable'} = $token->[2]{'variable'} if (!defined($paramHash->{'variable'}));
$helper->declareVar($paramHash->{'variable'});
$paramHash->{'multichoice'} = $token->[2]{'multichoice'};
+ $paramHash->{'allowempty'} = $token->[2]{'allowempty'};
$paramHash->{CHOICES} = [];
return '';
}
@@ -1193,15 +1166,14 @@ sub postprocess {
my $self = shift;
my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'};
- if (!defined($chosenValue)) {
+ if (!defined($chosenValue) && !$self->{'allowempty'}) {
$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 (ref($chosenValue)) {
+ $helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue);
}
if (defined($self->{NEXTSTATE})) {
@@ -1687,11 +1659,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;
@@ -1849,10 +1816,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});
}
@@ -2137,10 +2100,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});
}
@@ -2357,6 +2316,101 @@ sub end_eval {
1;
+package Apache::lonhelper::final;
+
+=pod
+
+=head2 Element: final
+
+ is a special element that works with helpers that use the
+tag. It goes through all the states and elements, executing the
+snippets and collecting the results. Finally, it takes the user out of the
+helper, going to a provided page.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+ &Apache::lonhelper::register('Apache::lonhelper::final',
+ ('final', 'exitpage'));
+}
+
+sub new {
+ my $ref = Apache::lonhelper::element->new();
+ bless($ref);
+}
+
+sub start_final { return ''; }
+
+sub end_final {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ Apache::lonhelper::final->new();
+
+ return '';
+}
+
+sub start_exitpage {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ $paramHash->{EXIT_PAGE} = &Apache::lonxml::get_all_text('/exitpage',
+ $parser);
+
+ return '';
+}
+
+sub end_exitpage { return ''; }
+
+sub render {
+ my $self = shift;
+
+ my @results;
+
+ # Collect all the results
+ for my $stateName (keys %{$helper->{STATES}}) {
+ my $state = $helper->{STATES}->{$stateName};
+
+ for my $element (@{$state->{ELEMENTS}}) {
+ if (defined($element->{FINAL_CODE})) {
+ # Compile the code.
+ my $code = 'sub { my $helper = shift; ' . $element->{FINAL_CODE} .
+ '}';
+ $code = eval($code);
+ die 'Error while executing final code for element with var ' .
+ $element->{'variable'} . ', Perl said: ' . $@ if $@;
+
+ my $result = &$code($helper);
+ if ($result) {
+ push @results, $result;
+ }
+ }
+ }
+ }
+
+ if (scalar(@results) == 0) {
+ return '';
+ }
+
+ my $result = "\n";
+ for my $re (@results) {
+ $result .= ' - ' . $re . "
\n";
+ }
+ return $result . ' ';
+}
+
+1;
+
package Apache::lonhelper::parmwizfinal;
# This is the final state for the parmwizard. It is not generally useful,
@@ -2404,60 +2458,72 @@ sub render {
'due_date' => "0_duedate",
'answer_date' => "0_answerdate");
- my $result = "\n";
|