[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 24 Apr 2006 23:05:37 -0000
albertel Mon Apr 24 19:05:37 2006 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
- add <validator> support to <date> widget
- need to reorganize the current value finder for <date>
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.136 loncom/interface/lonhelper.pm:1.137
--- loncom/interface/lonhelper.pm:1.136 Thu Apr 6 18:30:52 2006
+++ loncom/interface/lonhelper.pm Mon Apr 24 19:05:35 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.136 2006/04/06 22:30:52 foxr Exp $
+# $Id: lonhelper.pm,v 1.137 2006/04/24 23:05:35 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1576,23 +1576,39 @@
my $date;
my $time=time;
- $date = localtime($time);
- $date->min(0);
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});
die('Error in default value code for variable ' .
$self->{'variable'} . ', Perl said: ' . $@) if $@;
$time = &$valueFunc($helper, $self);
if (lc($time) eq 'anytime') {
$anytime=1;
- } else {
+ $date = localtime(time);
+ $date->min(0);
+ } elsif (defined($time) && $time ne 0) {
$date = localtime($time);
+ } else {
+ # leave date undefined so it'll default to now
}
- } else {
+ }
+ if (!defined($date) && !$anytime) {
+ $date = localtime(time);
+ $date->min(0);
}
+
+ &Apache::lonnet::logthis("date mode ");
+
if ($anytime) {
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\"";
}
@@ -1747,6 +1763,16 @@
$helper->{VARS}->{$var} = $chosenDate;
}
+ if (defined($self->{VALIDATOR})) {
+ my $validator = eval($self->{VALIDATOR});
+ die 'Died during evaluation of evaulation code; Perl said: ' . $@ if $@;
+ my $invalid = &$validator($helper, $state, $self, $self->getValue());
+ if ($invalid) {
+ $self->{ERROR_MSG} = $invalid;
+ return 0;
+ }
+ }
+
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}