[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Fri, 11 Apr 2003 17:21:18 -0000
bowersj2 Fri Apr 11 13:21:18 2003 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
This goes a long ways towards cleaning up a lot of the worst problems.
Elements now prevent states from advancing if there is an error, and
they print error messages now.
There are still some data-loss cases if you routinely use multiple
elements where both of them might have user-input errors, but by-and-large
that should not be a normal wizard, so I'm not inclined to blow time
fixing those corner cases until a situation develops where we need to.
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.5 loncom/interface/lonhelper.pm:1.6
--- loncom/interface/lonhelper.pm:1.5 Thu Apr 10 14:02:09 2003
+++ loncom/interface/lonhelper.pm Fri Apr 11 13:21:18 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.5 2003/04/10 18:02:09 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.6 2003/04/11 17:21:18 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -472,11 +472,26 @@
}
}
+# FIXME: Document that all postprocesses must return a true value or
+# the state transition will be overridden
sub postprocess {
my $self = shift;
-
+
+ # Save the state so we can roll it back if we need to.
+ my $originalState = $helper->{STATE};
+ my $everythingSuccessful = 1;
+
for my $element (@{$self->{ELEMENTS}}) {
- $element->postprocess();
+ my $result = $element->postprocess();
+ if (!$result) { $everythingSuccessful = 0; }
+ }
+
+ # If not all the postprocesses were successful, override
+ # any state transitions that may have occurred. It is the
+ # responsibility of the states to make sure they have
+ # error handling in that case.
+ if (!$everythingSuccessful) {
+ $helper->{STATE} = $originalState;
}
}
@@ -690,6 +705,8 @@
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
+
+ return 1;
}
1;
@@ -826,7 +843,7 @@
my $result = '';
if ($self->{'multichoice'}) {
- $result = <<SCRIPT;
+ $result .= <<SCRIPT;
<script>
function checkall(value) {
for (i=0; i<document.forms.wizform.elements.length; i++) {
@@ -839,16 +856,16 @@
<br />
<input type="button" onclick="checkall(true)" value="Select All" />
<input type="button" onclick="checkall(false)" value="Unselect All" />
-<br />
+<br />
BUTTONS
}
if (defined $self->{ERROR_MSG}) {
- $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
+ $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
}
$result .= $buttons;
-
+
$result .= "<table>\n\n";
my $type = "radio";
@@ -878,6 +895,17 @@
my $self = shift;
my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'};
+ if (!$chosenValue) {
+ $self->{ERROR_MSG} = "You must choose one or more choices to" .
+ " continue.";
+ return 0;
+ }
+
+ if ($self->{'multichoice'}) {
+ $self->process_multiple_choices($self->{'variable'}.'.forminput',
+ $self->{'variable'});
+ }
+
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
@@ -889,6 +917,7 @@
}
}
}
+ return 1;
}
1;
@@ -1089,7 +1118,7 @@
$checkDate->year + 1900 != $year) {
$self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "
. "date because it doesn't exist. Please enter a valid date.";
- return;
+ return 0;
}
$helper->{VARS}->{$var} = $chosenDate;
@@ -1097,6 +1126,8 @@
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
+
+ return 1;
}
1;
@@ -1304,6 +1335,8 @@
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
+
+ return 1;
}
1;
@@ -1434,6 +1467,27 @@
return $result;
}
+sub postprocess {
+ my $self = shift;
+
+ my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'};
+ if (!$result) {
+ $self->{ERROR_MSG} = 'You must choose at least one student '.
+ 'to continue.';
+ return 0;
+ }
+
+ if ($self->{'multichoice'}) {
+ $self->process_multiple_choices($self->{'variable'}.'.forminput',
+ $self->{'variable'});
+ }
+ if (defined($self->{NEXTSTATE})) {
+ $helper->changeState($self->{NEXTSTATE});
+ }
+
+ return 1;
+}
+
1;
package Apache::lonhelper::files;
@@ -1579,6 +1633,10 @@
$result .= $buttons;
+ if (defined $self->{ERROR_MSG}) {
+ $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
+ }
+
$result .= '<table border="0" cellpadding="1" cellspacing="1">';
# Keeps track if there are no choices, prints appropriate error
@@ -1621,6 +1679,13 @@
sub postprocess {
my $self = shift;
+ my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'};
+ if (!$result) {
+ $self->{ERROR_MSG} = 'You must choose at least one file '.
+ 'to continue.';
+ return 0;
+ }
+
if ($self->{'multichoice'}) {
$self->process_multiple_choices($self->{'variable'}.'.forminput',
$self->{'variable'});
@@ -1628,6 +1693,8 @@
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
+
+ return 1;
}
1;