[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 17 Oct 2005 19:46:14 -0000
albertel Mon Oct 17 15:46:14 2005 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
- making <defaultvalue> work for <resource>
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.123 loncom/interface/lonhelper.pm:1.124
--- loncom/interface/lonhelper.pm:1.123 Mon Oct 17 14:20:59 2005
+++ loncom/interface/lonhelper.pm Mon Oct 17 15:46:12 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.123 2005/10/17 18:20:59 albertel Exp $
+# $Id: lonhelper.pm,v 1.124 2005/10/17 19:46:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2017,6 +2017,17 @@
$mapUrl = $self->{MAP_URL};
}
+ my @defaultSymbs;
+ if (defined($self->{DEFAULT_VALUE})) {
+ my $valueFunc = eval($self->{DEFAULT_VALUE});
+ die 'Error in default value code for variable ' .
+ $self->{'variable'} . ', Perl said: ' . $@ if $@;
+ @defaultSymbs = &$valueFunc($helper, $self);
+ if (!$multichoice) { # only allowed 1
+ @defaultSymbs = ($defaultSymbs[0]);
+ }
+ }
+
# Create the composite function that renders the column on the nav map
# have to admit any language that lets me do this can't be all bad
@@ -2065,13 +2076,21 @@
}
$col .= "<td align='center'><input type='$inputType' name='${var}.forminput' ";
- if (!$checked && !$multichoice) {
- $col .= "checked='checked' ";
- $checked = 1;
- }
- if ($multichoice) { # all resources start checked; see bug 1174
- $col .= "checked='checked' ";
- $checked = 1;
+ if (@defaultSymbs) {
+ my $symb=$resource->symb();
+ if (grep(/\Q$symb\E/,@defaultSymbs)) {
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
+ } else {
+ if (!$checked && !$multichoice) {
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
+ if ($multichoice) { # all resources start checked; see bug 1174
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
}
$col .= "value='" . $resource_name . "' /></td>";