version 1.134, 2006/03/07 21:36:49
|
version 1.138, 2006/04/24 23:20:37
|
Line 573 sub display {
|
Line 573 sub display {
|
} |
} |
|
|
# Phase 4: Display. |
# Phase 4: Display. |
my $html=&Apache::lonxml::xmlbegin(); |
|
my $stateTitle=&mt($state->title()); |
my $stateTitle=&mt($state->title()); |
my $helperTitle = &mt($self->{TITLE}); |
my $browser_searcher_js = |
my $browser_searcher_js = &Apache::loncommon::browser_and_searcher_javascript(); |
'<script type="text/javascript">'."\n". |
my $bodytag = &Apache::loncommon::bodytag($helperTitle,'',''); |
&Apache::loncommon::browser_and_searcher_javascript(). |
|
"\n".'</script>'; |
|
|
|
$result .= &Apache::loncommon::start_page($self->{TITLE}, |
|
$browser_searcher_js); |
|
|
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
# FIXME: This should be parameterized, not concatenated - Jeremy |
# FIXME: This should be parameterized, not concatenated - Jeremy |
my $loncapaHelper = &mt("LON-CAPA Helper:"); |
|
|
|
$result .= <<HEADER; |
|
$html |
|
<head> |
|
<title>$loncapaHelper: $helperTitle</title> |
|
<script type="text/javascript"> |
|
$browser_searcher_js |
|
</script> |
|
</head> |
|
$bodytag |
|
HEADER |
|
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
$result .= <<HEADER; |
$result .= <<HEADER; |
<table border="0" width='100%'><tr><td> |
<table border="0" width='100%'><tr><td> |
Line 655 HEADER
|
Line 649 HEADER
|
</tr> |
</tr> |
</table> |
</table> |
</form> |
</form> |
</body> |
|
</html> |
|
FOOTER |
FOOTER |
|
|
|
$result .= &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 1076 will be the state transistioned to if th
|
Line 1069 will be the state transistioned to if th
|
the choice is not multichoice. This will override the nextstate |
the choice is not multichoice. This will override the nextstate |
passed to the parent C<choices> tag. |
passed to the parent C<choices> tag. |
|
|
|
<choice> may optionally contain a 'relatedvalue' attribute, which |
|
if present will cause a text entry to appear to the right of the |
|
selection. The value of the relatedvalue attribute is a variable |
|
into which the text entry will be stored e.g.: |
|
<choice computer='numberprovided" relatedvalue="num">Type the number in:</choice> |
|
|
|
<choice> may contain a relatededefault atribute which, if the |
|
relatedvalue attribute is present will be the initial value of the input |
|
box. |
|
|
=back |
=back |
|
|
To create the choices programmatically, either wrap the choices in |
To create the choices programmatically, either wrap the choices in |
Line 1166 sub start_choice {
|
Line 1169 sub start_choice {
|
my $computer = $token->[2]{'computer'}; |
my $computer = $token->[2]{'computer'}; |
my $human = &mt(&Apache::lonxml::get_all_text('/choice', |
my $human = &mt(&Apache::lonxml::get_all_text('/choice', |
$parser)); |
$parser)); |
my $nextstate = $token->[2]{'nextstate'}; |
my $nextstate = $token->[2]{'nextstate'}; |
my $evalFlag = $token->[2]{'eval'}; |
my $evalFlag = $token->[2]{'eval'}; |
|
my $relatedVar = $token->[2]{'relatedvalue'}; |
|
my $relatedDefault = $token->[2]{'relateddefault'}; |
push @{$paramHash->{CHOICES}}, [&mtn($human), $computer, $nextstate, |
push @{$paramHash->{CHOICES}}, [&mtn($human), $computer, $nextstate, |
$evalFlag]; |
$evalFlag, $relatedVar, $relatedDefault]; |
return ''; |
return ''; |
} |
} |
|
|
Line 1279 BUTTONS
|
Line 1284 BUTTONS
|
} |
} |
$result .= qq{id="id$id"}; |
$result .= qq{id="id$id"}; |
my $choiceLabel = $choice->[0]; |
my $choiceLabel = $choice->[0]; |
if ($choice->[4]) { # if we need to evaluate this choice |
if ($choice->[3]) { # if we need to evaluate this choice |
$choiceLabel = "sub { my $helper = shift; my $state = shift;" . |
$choiceLabel = "sub { my $helper = shift; my $state = shift;" . |
$choiceLabel . "}"; |
$choiceLabel . "}"; |
$choiceLabel = eval($choiceLabel); |
$choiceLabel = eval($choiceLabel); |
$choiceLabel = &$choiceLabel($helper, $self); |
$choiceLabel = &$choiceLabel($helper, $self); |
} |
} |
$result .= "/></td><td> ".qq{<label for="id$id">}. |
$result .= "/></td><td> ".qq{<label for="id$id">}. |
$choiceLabel. "</label></td></tr>\n"; |
$choiceLabel. "</label></td>"; |
|
if ($choice->[4]) { |
|
$result .='<td><input type="text" size="5" name="' |
|
.$choice->[4].'.forminput" value="' |
|
.$choice->[5].'" /></td>'; |
|
} |
|
$result .= "</tr>\n"; |
} |
} |
$result .= "</table>\n\n\n"; |
$result .= "</table>\n\n\n"; |
$result .= $buttons; |
$result .= $buttons; |
Line 1320 sub postprocess {
|
Line 1331 sub postprocess {
|
$helper->changeState($choice->[2]); |
$helper->changeState($choice->[2]); |
} |
} |
} |
} |
|
if ($choice->[4]) { |
|
my $varname = $choice->[4]; |
|
$helper->{'VARS'}->{$varname} = $env{'form.'."$varname.forminput"}; |
|
} |
} |
} |
return 1; |
return 1; |
} |
} |
Line 1561 sub render {
|
Line 1576 sub render {
|
my $date; |
my $date; |
|
|
my $time=time; |
my $time=time; |
$date = localtime($time); |
|
$date->min(0); |
|
my ($anytime,$onclick); |
my ($anytime,$onclick); |
|
|
if (defined($self->{DEFAULT_VALUE})) { |
|
|
# first check VARS for a valid new value from the user |
|
# then check DEFAULT_VALUE for a valid default time value |
|
# otherwise pick now as reasonably good time |
|
|
|
if (defined($helper->{VARS}{$var}) |
|
&& $helper->{VARS}{$var} > 0) { |
|
$date = localtime($helper->{VARS}{$var}); |
|
} elsif (defined($self->{DEFAULT_VALUE})) { |
my $valueFunc = eval($self->{DEFAULT_VALUE}); |
my $valueFunc = eval($self->{DEFAULT_VALUE}); |
die('Error in default value code for variable ' . |
die('Error in default value code for variable ' . |
$self->{'variable'} . ', Perl said: ' . $@) if $@; |
$self->{'variable'} . ', Perl said: ' . $@) if $@; |
$time = &$valueFunc($helper, $self); |
$time = &$valueFunc($helper, $self); |
if (lc($time) eq 'anytime') { |
if (lc($time) eq 'anytime') { |
$anytime=1; |
$anytime=1; |
} else { |
$date = localtime(time); |
|
$date->min(0); |
|
} elsif (defined($time) && $time ne 0) { |
$date = localtime($time); |
$date = localtime($time); |
|
} else { |
|
# leave date undefined so it'll default to now |
} |
} |
} else { |
} |
|
|
|
if (!defined($date)) { |
|
$date = localtime(time); |
|
$date->min(0); |
} |
} |
|
|
|
&Apache::lonnet::logthis("date mode "); |
|
|
if ($anytime) { |
if ($anytime) { |
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\""; |
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\""; |
} |
} |
Line 1685 CHECK
|
Line 1716 CHECK
|
if ($anytime) { |
if ($anytime) { |
$result.=' checked="checked" ' |
$result.=' checked="checked" ' |
} |
} |
$result.="name='${var}anytime'/>".&mt('Anytime').'</label>' |
$result.="name='${var}anytime'/>".&mt('Any time').'</label>' |
} |
} |
return $result; |
return $result; |
|
|
Line 1732 sub postprocess {
|
Line 1763 sub postprocess {
|
$helper->{VARS}->{$var} = $chosenDate; |
$helper->{VARS}->{$var} = $chosenDate; |
} |
} |
|
|
|
if (defined($self->{VALIDATOR})) { |
|
my $validator = eval($self->{VALIDATOR}); |
|
die 'Died during evaluation of validator code; Perl said: ' . $@ if $@; |
|
my $invalid = &$validator($helper, $state, $self, $self->getValue()); |
|
if ($invalid) { |
|
$self->{ERROR_MSG} = $invalid; |
|
return 0; |
|
} |
|
} |
|
|
if (defined($self->{NEXTSTATE})) { |
if (defined($self->{NEXTSTATE})) { |
$helper->changeState($self->{NEXTSTATE}); |
$helper->changeState($self->{NEXTSTATE}); |
} |
} |
Line 3233 sub postprocess {
|
Line 3274 sub postprocess {
|
|
|
if (defined($self->{VALIDATOR})) { |
if (defined($self->{VALIDATOR})) { |
my $validator = eval($self->{VALIDATOR}); |
my $validator = eval($self->{VALIDATOR}); |
die 'Died during evaluation of evaulation code; Perl said: ' . $@ if $@; |
die 'Died during evaluation of validator code; Perl said: ' . $@ if $@; |
my $invalid = &$validator($helper, $state, $self, $self->getValue()); |
my $invalid = &$validator($helper, $state, $self, $self->getValue()); |
if ($invalid) { |
if ($invalid) { |
$self->{ERROR_MSG} = $invalid; |
$self->{ERROR_MSG} = $invalid; |