--- loncom/interface/lonhelper.pm 2005/10/11 22:05:20 1.122 +++ loncom/interface/lonhelper.pm 2005/10/17 19:46:12 1.124 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.122 2005/10/11 22:05:20 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 @@ BUTTONS $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 @@ BUTTONS } $col .= "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 . "' />"; @@ -2189,6 +2208,10 @@ selection. Defaults to false. If true, only active students and course personnel will be shown. Defaults to false. +=item * B: + +If true, the selection of no users is allowed. Defaults to false. + =back =cut @@ -2224,6 +2247,7 @@ sub start_student { if (defined($token->[2]{'nextstate'})) { $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; } + $paramHash->{'emptyallowed'} = $token->[2]{'emptyallowed'}; } @@ -2485,9 +2509,14 @@ sub postprocess { my $self = shift; my $result = $env{'form.' . $self->{'variable'} . '.forminput'}; - if (!$result) { - $self->{ERROR_MSG} = - &mt('You must choose at least one student to continue.'); + if (!$result && !$self->{'emptyallowed'}) { + if ($self->{'coursepersonnel'}) { + $self->{ERROR_MSG} = + &mt('You must choose at least one user to continue.'); + } else { + $self->{ERROR_MSG} = + &mt('You must choose at least one student to continue.'); + } return 0; }