version 1.39, 2003/06/19 19:28:52
|
version 1.42, 2003/08/13 14:49:58
|
Line 1142 sub end_choice {
|
Line 1142 sub end_choice {
|
} |
} |
|
|
sub render { |
sub render { |
# START HERE: Replace this with correct choices code. |
|
my $self = shift; |
my $self = shift; |
my $var = $self->{'variable'}; |
my $var = $self->{'variable'}; |
my $buttons = ''; |
my $buttons = ''; |
Line 1275 sub postprocess {
|
Line 1274 sub postprocess {
|
} |
} |
1; |
1; |
|
|
|
package Apache::lonhelper::dropdown; |
|
|
|
=pod |
|
|
|
=head2 Element: dropdown |
|
|
|
A drop-down provides a drop-down box instead of a radio button |
|
box. Because most people do not know how to use a multi-select |
|
drop-down box, that option is not allowed. Otherwise, the arguments |
|
are the same as "choices", except "allowempty" is also meaningless. |
|
|
|
<dropdown> takes an attribute "variable" to control which helper variable |
|
the result is stored in. |
|
|
|
B<SUB-TAGS> |
|
|
|
<choice>, which acts just as it does in the "choices" element. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonhelper::element"); |
|
use strict; |
|
|
|
BEGIN { |
|
&Apache::lonhelper::register('Apache::lonhelper::dropdown', |
|
('dropdown')); |
|
} |
|
|
|
sub new { |
|
my $ref = Apache::lonhelper::element->new(); |
|
bless($ref); |
|
} |
|
|
|
# CONSTRUCTION: Construct the message element from the XML |
|
sub start_dropdown { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
# Need to initialize the choices list, so everything can assume it exists |
|
$paramHash->{'variable'} = $token->[2]{'variable'} if (!defined($paramHash->{'variable'})); |
|
$helper->declareVar($paramHash->{'variable'}); |
|
$paramHash->{CHOICES} = []; |
|
return ''; |
|
} |
|
|
|
sub end_dropdown { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
Apache::lonhelper::dropdown->new(); |
|
return ''; |
|
} |
|
|
|
sub render { |
|
my $self = shift; |
|
my $var = $self->{'variable'}; |
|
my $result = ''; |
|
|
|
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />'; |
|
} |
|
|
|
my %checkedChoices; |
|
my $checkedChoicesFunc; |
|
|
|
if (defined($self->{DEFAULT_VALUE})) { |
|
$checkedChoicesFunc = eval ($self->{DEFAULT_VALUE}); |
|
die 'Error in default value code for variable ' . |
|
$self->{'variable'} . ', Perl said: ' . $@ if $@; |
|
} else { |
|
$checkedChoicesFunc = sub { return ''; }; |
|
} |
|
|
|
# single choice |
|
my $selectedChoice = &$checkedChoicesFunc($helper, $self); |
|
|
|
my $foundChoice = 0; |
|
|
|
# check that the choice is in the list of choices. |
|
for my $choice (@{$self->{CHOICES}}) { |
|
if ($choice->[1] eq $selectedChoice) { |
|
$checkedChoices{$choice->[1]} = 1; |
|
$foundChoice = 1; |
|
} |
|
} |
|
|
|
# If we couldn't find the choice, pick the first one |
|
if (!$foundChoice) { |
|
$checkedChoices{$self->{CHOICES}->[0]->[1]} = 1; |
|
} |
|
|
|
$result .= "<select name='${var}.forminput'>\n"; |
|
foreach my $choice (@{$self->{CHOICES}}) { |
|
$result .= "<option value='" . |
|
HTML::Entities::encode($choice->[1]) |
|
. "'"; |
|
if ($checkedChoices{$choice->[1]}) { |
|
$result .= " selected"; |
|
} |
|
my $choiceLabel = $choice->[0]; |
|
if ($choice->[4]) { # if we need to evaluate this choice |
|
$choiceLabel = "sub { my $helper = shift; my $state = shift;" . |
|
$choiceLabel . "}"; |
|
$choiceLabel = eval($choiceLabel); |
|
$choiceLabel = &$choiceLabel($helper, $self); |
|
} |
|
$result .= ">" . $choiceLabel . "\n"; |
|
} |
|
|
|
return $result; |
|
} |
|
|
|
# If a NEXTSTATE was given or a nextstate for this choice was |
|
# given, switch to it |
|
sub postprocess { |
|
my $self = shift; |
|
my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'}; |
|
|
|
if (!defined($chosenValue) && !$self->{'allowempty'}) { |
|
$self->{ERROR_MSG} = "You must choose one or more choices to" . |
|
" continue."; |
|
return 0; |
|
} |
|
|
|
if (defined($self->{NEXTSTATE})) { |
|
$helper->changeState($self->{NEXTSTATE}); |
|
} |
|
|
|
foreach my $choice (@{$self->{CHOICES}}) { |
|
if ($choice->[1] eq $chosenValue) { |
|
if (defined($choice->[2])) { |
|
$helper->changeState($choice->[2]); |
|
} |
|
} |
|
} |
|
return 1; |
|
} |
|
1; |
|
|
package Apache::lonhelper::date; |
package Apache::lonhelper::date; |
|
|
=pod |
=pod |
Line 2654 sub render {
|
Line 2800 sub render {
|
} |
} |
} |
} |
|
|
if (scalar(@results) == 0) { |
my $result; |
return ''; |
|
} |
|
|
|
my $result = "<ul>\n"; |
|
for my $re (@results) { |
|
$result .= ' <li>' . $re . "</li>\n"; |
|
} |
|
|
|
if (!@results) { |
if (scalar(@results) != 0) { |
$result .= ' <li>No changes were made to current settings.</li>'; |
$result .= "<ul>\n"; |
|
for my $re (@results) { |
|
$result .= ' <li>' . $re . "</li>\n"; |
|
} |
|
|
|
if (!@results) { |
|
$result .= ' <li>No changes were made to current settings.</li>'; |
|
} |
|
|
|
$result .= '</ul>'; |
} |
} |
|
|
if ($self->{'restartCourse'}) { |
if ($self->{'restartCourse'}) { |
Line 2678 sub render {
|
Line 2826 sub render {
|
"</form></center>"; |
"</form></center>"; |
} |
} |
|
|
return $result . '</ul>'; |
return $result; |
} |
} |
|
|
sub overrideForm { |
sub overrideForm { |
Line 2753 sub render {
|
Line 2901 sub render {
|
$symb = 'a'; |
$symb = 'a'; |
$paramlevel = 'general'; |
$paramlevel = 'general'; |
} elsif ($vars->{GRANULARITY} eq 'map') { |
} elsif ($vars->{GRANULARITY} eq 'map') { |
my $navmap = Apache::lonnavmaps::navmap->new( |
my $navmap = Apache::lonnavmaps::navmap->new(); |
$ENV{"request.course.fn"}.".db", |
|
$ENV{"request.course.fn"}."_parms.db", 0, 0); |
|
my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); |
my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); |
my $title = $res->compTitle(); |
my $title = $res->compTitle(); |
$symb = $res->symb(); |
$symb = $res->symb(); |
Line 2765 sub render {
|
Line 2911 sub render {
|
$affectedResourceId = $vars->{RESOURCE_ID}; |
$affectedResourceId = $vars->{RESOURCE_ID}; |
$paramlevel = 'map'; |
$paramlevel = 'map'; |
} else { |
} else { |
my $navmap = Apache::lonnavmaps::navmap->new( |
my $navmap = Apache::lonnavmaps::navmap->new(); |
$ENV{"request.course.fn"}.".db", |
|
$ENV{"request.course.fn"}."_parms.db", 0, 0); |
|
my $res = $navmap->getById($vars->{RESOURCE_ID}); |
my $res = $navmap->getById($vars->{RESOURCE_ID}); |
$symb = $res->symb(); |
$symb = $res->symb(); |
my $title = $res->compTitle(); |
my $title = $res->compTitle(); |