[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Tue, 27 May 2003 19:59:38 -0000
bowersj2 Tue May 27 15:59:38 2003 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
Added in a fairly simple "string" type helper entry which allows the
user to manipulate a simple string. <string> honors defaultvalue.
Also gave <final> the ability to specify an override to the helper
environment to force the user to reinitialize the course at the end of
the helper, which was necessary for the course intialization wizard.
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.33 loncom/interface/lonhelper.pm:1.34
--- loncom/interface/lonhelper.pm:1.33 Wed May 21 09:41:00 2003
+++ loncom/interface/lonhelper.pm Tue May 27 15:59:38 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.33 2003/05/21 13:41:00 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.34 2003/05/27 19:59:38 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1160,7 +1160,7 @@
if (defined($self->{DEFAULT_VALUE})) {
$checkedChoicesFunc = eval ($self->{DEFAULT_VALUE});
die 'Error in default value code for variable ' .
- {'variable'} . ', Perl said:' . $@ if $@;
+ $self->{'variable'} . ', Perl said: ' . $@ if $@;
} else {
$checkedChoicesFunc = sub { return ''; };
}
@@ -2250,6 +2250,96 @@
}
1;
+package Apache::lonhelper::string;
+
+=pod
+
+=head2 Element: string
+
+string elements provide a string entry field for the user. string elements
+take the usual 'variable' and 'nextstate' parameters. string elements
+also pass through 'maxlength' and 'size' attributes to the input tag.
+
+string honors the defaultvalue tag, if given.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+ &Apache::lonhelper::register('Apache::lonhelper::string',
+ ('string'));
+}
+
+sub new {
+ my $ref = Apache::lonhelper::element->new();
+ bless($ref);
+}
+
+# CONSTRUCTION: Construct the message element from the XML
+sub start_string {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ $paramHash->{'variable'} = $token->[2]{'variable'};
+ $helper->declareVar($paramHash->{'variable'});
+ $paramHash->{'nextstate'} = $token->[2]{'nextstate'};
+ $paramHash->{'maxlength'} = $token->[2]{'maxlength'};
+ $paramHash->{'size'} = $token->[2]{'size'};
+
+ return '';
+}
+
+sub end_string {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+ Apache::lonhelper::string->new();
+ return '';
+}
+
+sub render {
+ my $self = shift;
+ my $result = '<input type="string" name="' . $self->{'variable'} . '.forminput"';
+
+ if (defined($self->{'size'})) {
+ $result .= ' size="' . $self->{'size'} . '"';
+ }
+ if (defined($self->{'maxlength'})) {
+ $result .= ' maxlength="' . $self->{'maxlength'} . '"';
+ }
+
+ if (defined($self->{DEFAULT_VALUE})) {
+ my $valueFunc = eval($self->{DEFAULT_VALUE});
+ die 'Error in default value code for variable ' .
+ $self->{'variable'} . ', Perl said: ' . $@ if $@;
+ $result .= ' value="' . &$valueFunc($helper, $self) . '"';
+ }
+
+ $result .= ' />';
+
+ return $result;
+}
+
+# If a NEXTSTATE was given, switch to it
+sub postprocess {
+ my $self = shift;
+ if (defined($self->{NEXTSTATE})) {
+ $helper->changeState($self->{NEXTSTATE});
+ }
+
+ return 1;
+}
+
+1;
+
package Apache::lonhelper::general;
=pod
@@ -2394,6 +2484,11 @@
snippets and collecting the results. Finally, it takes the user out of the
helper, going to a provided page.
+If the parameter "restartCourse" is true, this will override the buttons and
+will make a "Finish Helper" button that will re-initialize the course for them,
+which is useful for the Course Initialization helper so the users never see
+the old values taking effect.
+
=cut
no strict;
@@ -2410,7 +2505,17 @@
bless($ref);
}
-sub start_final { return ''; }
+sub start_final {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ $paramHash->{'restartCourse'} = $token->[2]{'restartCourse'};
+
+ return '';
+}
sub end_final {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
@@ -2473,7 +2578,28 @@
for my $re (@results) {
$result .= ' <li>' . $re . "</li>\n";
}
+
+ if (!@results) {
+ $result .= ' <li>No changes were made to current settings.</li>';
+ }
+
+ if ($self->{'restartCourse'}) {
+ $result .= "<center>\n" .
+ "<form action='/adm/roles' method='post' target='loncapaclient'>\n" .
+ "<input type='button' onclick='history.go(-1)' value='<- Previous' />" .
+ "<input type='hidden' name='orgurl' value='/adm/navmaps' />" .
+ "<input type='hidden' name='selectrole' value='1' />\n" .
+ "<input type='hidden' name='" . $ENV{'request.role'} .
+ "' value='1' />\n<input type='submit' value='Finish Course Initialization' />\n" .
+ "</form></center>";
+ }
+
return $result . '</ul>';
+}
+
+sub overrideForm {
+ my $self = shift;
+ return $self->{'restartCourse'};
}
1;