--- loncom/interface/Attic/lonwizard.pm 2003/01/30 19:34:24 1.3
+++ loncom/interface/Attic/lonwizard.pm 2003/02/13 23:46:27 1.8
@@ -5,6 +5,7 @@ package Apache::lonwizard;
use Apache::Constants qw(:common :http);
use Apache::loncommon;
+use Apache::lonnet;
=head1 lonwizard - HTML "Wizard" framework for LON-CAPA
@@ -102,6 +103,13 @@ sub new {
=cut
+# Sometimes the wizard writer will want to use the result of the previous
+# state to change the text of the next state. In order to do that, it
+# has to be done during the declaration of the states, or it won't be
+# available. Therefore, basic form processing must occur before the
+# actual display routine is called and the actual pre-process is called,
+# or it won't be available.
+# This also factors common code out of the preprocess calls.
sub declareVars {
my $self = shift;
my $varlist = shift;
@@ -118,6 +126,12 @@ sub declareVars {
{
$self->{VARS}->{$element} = $ENV{$envname};
}
+
+ # If there's an incoming form submission, use that
+ my $envname = "form." . $element . ".forminput";
+ if (defined ($ENV{$envname})) {
+ $self->{VARS}->{$element} = $ENV{$envname};
+ }
}
}
@@ -253,6 +267,8 @@ HEADER
}
else
{
+ $result .= '(): Returns a string representing the current state of the wizard, suitable for use directly as part of a query string. (See resource_state for an example.)
+
+=cut
+
+sub queryStringVars {
+ my $self = shift;
+
+ my @queryString = ();
+
+ for my $varname (keys %{$self->{VARS}}) {
+ push @queryString, Apache::lonnet::escape($varname) . "=" .
+ Apache::lonnet::escape($self->{VARS}{$varname});
+ }
+ push @queryString, 'CURRENT_STATE=' . Apache::lonnet::escape($self->{STATE});
+ push @queryString, 'RETURN_PAGE=' . Apache::lonnet::escape($self->{RETURN_PAGE});
+
+ return join '&', @queryString;
+}
+
+=pod
+
=item B
This wizard will allow you to set open, due, and answer dates for problems. You will be asked to select a problem, what kind of date you want to set, and for whom the date should be effective.
After the wizard is done, you will be shown where in the advanced interface you would have gone to change the parameter you have chosen, so in the future you can do it directly.
+ +Press Next -> to begin, or select <- Previous to go back to the previous screen.
WIZBEGIN my $wizard = Apache::lonwizard->new("Course Parameter Wizard"); $wizard->declareVars(['ACTION_TYPE', 'GRANULARITY', 'TARGETS', 'PARM_DATE', 'RESOURCE_ID', 'USER_NAME', 'SECTION_NAME']); - my %dateTypeHash = ('open_date' => "Opening Date", - 'due_date' => "Due Date", - 'answer_date' => "Answer Date"); + my %dateTypeHash = ('open_date' => "opening date", + 'due_date' => "due date", + 'answer_date' => "answer date"); + my %levelTypeHash = ('whole_course' => "all problems in the course", + 'map' => 'the selected folder', + 'resource' => 'the selected problem'); - Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "CHOOSE_ACTION"); - Apache::lonwizard::switch_state->new($wizard, "CHOOSE_ACTION", "What do you want to do?", "ACTION_TYPE", [ - ["open_date", "Set an Open Date for a problem", "CHOOSE_LEVEL"], - ["due_date", "Set a Due Date for a problem", "CHOOSE_LEVEL"], - ["answer_date", "Set an Answer Open Date for a problem", "CHOOSE_LEVEL" ] ]); - Apache::lonwizard::switch_state->new($wizard, "CHOOSE_LEVEL", "Parameter Granularity", "GRANULARITY", [ - ["whole_course", "Set for Whole Course", "CHOOSE_STUDENT_LEVEL"], - ["map", "Set for a Folder/Map", "CHOOSE_FOLDER"], - ["resource", "Set for a Particular Problem", "CHOOSE_RESOURCE"]], - "How general should this setting be?"); - Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_FOLDER", "Select Folder", "", "", "CHOOSE_STUDENT_LEVEL", "RESOURCE_ID", sub {my $res = shift; return $res->is_map();}); - Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_RESOURCE", "Select Resource", "", "", "CHOOSE_STUDENT_LEVEL", "RESOURCE_ID", sub {my $res = shift; return $res->is_map() || $res->is_problem();}, sub {my $res = shift; return $res->is_problem(); }); - Apache::lonwizard::switch_state->new($wizard, "CHOOSE_STUDENT_LEVEL", "Parameter Targets", "TARGETS", [ - ["course", "Set for All Students in Course", "CHOOSE_DATE"], - ["section", "Set for Section", "CHOOSE_SECTION"], - ["student", "Set for an Individual Student", "CHOOSE_STUDENT"]], - "Whom should this setting affect?"); - + Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "CHOOSE_LEVEL"); + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_LEVEL", "Which Problem or Problems?", "GRANULARITY", [ + ["whole_course", "Every problem in the course", "CHOOSE_ACTION"], + ["map", "Every problem in a particular folder", "CHOOSE_FOLDER"], + ["resource", "One particular problem", "CHOOSE_RESOURCE"]], + "Which problems do you wish to change a date for?"); + Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_FOLDER", "Select Folder", "Select the folder you wish to set the date for:", "", "CHOOSE_ACTION", "RESOURCE_ID", sub {my $res = shift; return $res->is_map();}); + Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_RESOURCE", "Select Resource", "", "", "CHOOSE_ACTION", "RESOURCE_ID", sub {my $res = shift; return $res->is_map() || $res->is_problem();}, sub {my $res = shift; return $res->is_problem(); }); + my $levelType = $levelTypeHash{$wizard->{VARS}->{GRANULARITY}}; + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_ACTION", "Parameter Type", "ACTION_TYPE", [ + ["open_date", "Set an open date", "CHOOSE_DATE"], + ["due_date", "Set a due date", "CHOOSE_DATE"], + ["answer_date", "Set an answer open date", "CHOOSE_DATE" ] ], + "What parameters do you want to set for $levelType?"); my $dateType = $dateTypeHash{$wizard->{VARS}->{ACTION_TYPE}}; - Apache::lonwizard::choose_section->new($wizard, "CHOOSE_SECTION", "Select Section", "Please select the section you wish to set the $dateType for:", "", "CHOOSE_DATE", "SECTION_NAME"); - Apache::lonwizard::choose_student->new($wizard, "CHOOSE_STUDENT", "Select Student", "Please select the student you wish to set the $dateType for:", "", "CHOOSE_DATE", "USER_NAME"); - Apache::lonwizard::date_state->new($wizard, "CHOOSE_DATE", "Set Date", "PARM_DATE", "FINISH", "What should the $dateType be set to?"); + Apache::lonwizard::date_state->new($wizard, "CHOOSE_DATE", "Set Date", "PARM_DATE", "CHOOSE_STUDENT_LEVEL", "What should the $dateType be set to?"); + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_STUDENT_LEVEL", "Students Affected", "TARGETS", [ + ["course", ". . . for all students in the course", "FINISH"], + ["section", ". . . for a particular section", "CHOOSE_SECTION"], + ["student", ". . . for an individual student", "CHOOSE_STUDENT"]], + "Set $dateType of $levelType for. . ."); + + Apache::lonwizard::choose_section->new($wizard, "CHOOSE_SECTION", "Select Section", "Please select the section you wish to set the $dateType for:", "", "FINISH", "SECTION_NAME"); + Apache::lonwizard::choose_student->new($wizard, "CHOOSE_STUDENT", "Select Student", "Please select the student you wish to set the $dateType for:", "", "FINISH", "USER_NAME"); Apache::lonwizard::parmwizfinal->new($wizard, "FINISH", "Confirm Selection"); $r->print($wizard->display()); @@ -405,6 +440,8 @@ It is importent to remember when constru None of the pre-packaged states correctly handle there being B"; - - if (&$choiceFunc($curRes)) { - if (!$curVal) { - # Set this to the first one if they have no previous - # selection. - $curVal = $curRes->{ID}; - } - - $isChoosable = 1; - $result .= "{ID} eq $curVal) { - $result .= " checked"; - } - $result .= ' value="' . $curRes->{ID} . '" />'; - } - - $result .= " | "; - - for ($i = 0; $i < $depth; $i++) { - $result .= $padding; + # Create the composite function that renders the column on the nav map + my $renderColFunc = sub { + my ($resource, $part, $params) = @_; + + if (!&$choiceFunc($resource)) { + return ' | '; + } else { + my $col = " | {$resource->{ID}}) {
+ $col .= "checked ";
}
-
- #$result .= "![]() |
There are no valid resources to select in this course. The entire course will be selected by default (as if 1you selected "Set for Whole Course" on the previous screen).
"; - $result .= "\n"; - } - - $result .= "(Note: I need to add the icons in.)
"; + $result .= + &Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, + Apache::lonnavmaps::resource()], + 'showParts' => 0, + 'queryString' => $wizard->queryStringVars() . '&folderManip=1', + 'url' => '/adm/wizard', + 'filterFunc' => $filterFunc } ); + $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER}); return $result;