version 1.3, 2003/01/30 19:34:24
|
version 1.17, 2003/03/01 00:07:18
|
Line 5 package Apache::lonwizard;
|
Line 5 package Apache::lonwizard;
|
|
|
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
use Apache::loncommon; |
use Apache::loncommon; |
|
use Apache::lonnet; |
|
|
=head1 lonwizard - HTML "Wizard" framework for LON-CAPA |
=head1 lonwizard - HTML "Wizard" framework for LON-CAPA |
|
|
I know how most developers feel about Wizards, but the fact is they are a well-established UI widget that users feel comfortable with. It can take a complicated multi-dimensional problem the user has (such as the canonical Course Parameter example) and turn in into a series of bite-sized one-dimensional questions. Or take the some four-question form and put it in a Wizard, and present the same user with the same form outside of the Wizard, and the user will *think* the Wizard is easier. |
Wizards are a well-established UI widget that users feel comfortable with. It can take a complicated multi-dimensional problem the user has (such as the canonical Course Parameter example) and turn in into a series of bite-sized one-dimensional questions. Or take the some four-question form and put it in a Wizard, and present the same user with the same form outside of the Wizard, and the user will *think* the Wizard is easier. |
|
|
For the developer, wizards do provide an easy way to bundle easy bits of functionality for the user. It can be easier to write a Wizard then provide another custom interface. |
For the developer, wizards do provide an easy way to bundle easy bits of functionality for the user, without having to write the tedious code for maintaining state between frames. It can be easier to write a Wizard then provide another custom interface. |
|
|
All classes are in the Apache::lonwizard namespace. |
All classes are in the Apache::lonwizard namespace. |
|
|
Line 23 All classes are in the Apache::lonwizard
|
Line 24 All classes are in the Apache::lonwizard
|
use strict; |
use strict; |
|
|
use HTML::Entities; |
use HTML::Entities; |
|
use Apache::loncommon; |
|
|
=pod |
=pod |
|
|
=head1 Class: lonwizard |
=head1 Class: lonwizard |
|
|
|
FIXME: Doc the parameters of the wizard well: Title, Data (Query string), URL. |
|
|
=head2 lonwizard Attributes |
=head2 lonwizard Attributes |
|
|
=over 4 |
=over 4 |
Line 44 use HTML::Entities;
|
Line 48 use HTML::Entities;
|
|
|
=item B<DONE>: A boolean value, true if the wizard has completed. |
=item B<DONE>: A boolean value, true if the wizard has completed. |
|
|
|
=item B<DATA>: The data the wizard is drawing from, which will be passed to Apache::loncommon::get_unprocessed_cgi, and may be used by states that do multi-selection. |
|
|
=back |
=back |
|
|
=cut |
=cut |
Line 53 sub new {
|
Line 59 sub new {
|
my $class = ref($proto) || $proto; |
my $class = ref($proto) || $proto; |
my $self = {}; |
my $self = {}; |
|
|
|
$self->{TITLE} = shift; |
|
$self->{DATA} = shift; |
|
$self->{URL} = shift; |
|
&Apache::loncommon::get_unprocessed_cgi($self->{DATA}); |
|
|
|
|
# If there is a state from the previous form, use that. If there is no |
# If there is a state from the previous form, use that. If there is no |
# state, use the start state parameter. |
# state, use the start state parameter. |
if (defined $ENV{"form.CURRENT_STATE"}) |
if (defined $ENV{"form.CURRENT_STATE"}) |
Line 64 sub new {
|
Line 76 sub new {
|
$self->{STATE} = "START"; |
$self->{STATE} = "START"; |
} |
} |
|
|
# set up return URL: Return the user to the referer page, unless the |
|
# form has stored a value. |
|
if (defined $ENV{"form.RETURN_PAGE"}) |
if (defined $ENV{"form.RETURN_PAGE"}) |
{ |
{ |
$self->{RETURN_PAGE} = $ENV{"form.RETURN_PAGE"}; |
$self->{RETURN_PAGE} = $ENV{"form.RETURN_PAGE"}; |
Line 75 sub new {
|
Line 85 sub new {
|
$self->{RETURN_PAGE} = $ENV{REFERER}; |
$self->{RETURN_PAGE} = $ENV{REFERER}; |
} |
} |
|
|
$self->{TITLE} = shift; |
|
$self->{STATES} = {}; |
$self->{STATES} = {}; |
$self->{VARS} = {}; |
$self->{VARS} = {}; |
$self->{HISTORY} = {}; |
$self->{HISTORY} = {}; |
$self->{DONE} = 0; |
$self->{DONE} = 0; |
|
|
bless($self, $class); |
bless($self, $class); |
return $self; |
return $self; |
} |
} |
Line 92 sub new {
|
Line 102 sub new {
|
|
|
=item * B<new>(title): Returns a new instance of the given wizard type. "title" is the human-readable name of the wizard. A new wizard always starts on the B<START> state name. |
=item * B<new>(title): Returns a new instance of the given wizard type. "title" is the human-readable name of the wizard. A new wizard always starts on the B<START> state name. |
|
|
=item * B<declareVars>(varList): Call this function to declare the var names you want the wizard to maintain for you. The wizard will automatically output the hidden form fields and parse the values for you on the next call. This is a bulk declaration. |
=item * B<declareVars>(varList): Call this function to declare the var names you want the wizard to maintain for you. The wizard will automatically output the hidden form fields and parse the values for you on the next call. |
|
|
=over 2 |
=over 2 |
|
|
=item Note that these variables are reserved for the wizard; if you output other form values in your state, you must use other names. For example, declaring "student" will cause the wizard to emit a form value with the name "student"; if your state emits form entries, do not name them "student". |
=item * B<Note>: These form variables are reserved for the wizard; if you output other form values in your state, you must use other names. For example, declaring "student" will cause the wizard to emit a form value with the name "student"; if your state emits form entries, do not name them "student". If you use the variable name followed by '.forminput', the wizard will automatically store the user's choice in the appropriate form variable. |
|
|
|
=item * B<Note>: If you want to preserve incoming form values, such as ones from the remote, you can simply declare them and the wizard will automatically preserve them. For instance, you might want to store 'url' or 'postdata' from the remote; see lonprintout for example. |
|
|
=back |
=back |
|
|
=cut |
=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 { |
sub declareVars { |
my $self = shift; |
my $self = shift; |
my $varlist = shift; |
my $varlist = shift; |
Line 114 sub declareVars {
|
Line 133 sub declareVars {
|
|
|
# if there's a form in the env, use that instead |
# if there's a form in the env, use that instead |
my $envname = "form." . $element; |
my $envname = "form." . $element; |
if (defined ($ENV{$envname})) |
if (defined ($ENV{$envname})) { |
{ |
|
$self->{VARS}->{$element} = $ENV{$envname}; |
$self->{VARS}->{$element} = $ENV{$envname}; |
} |
} |
|
|
|
# If there's an incoming form submission, use that |
|
$envname = "form." . $element . ".forminput"; |
|
if (defined ($ENV{$envname})) { |
|
$self->{VARS}->{$element} = $ENV{$envname}; |
|
} |
} |
} |
} |
} |
|
|
Line 146 sub _saveVars {
|
Line 170 sub _saveVars {
|
|
|
=pod |
=pod |
|
|
=item B<registerState>(referenceToStateObj): Registers a state as part of the wizard, so the wizard can use it. The 'referenceToStateObj' should be a reference to an instantiated lonwizstate object. This is normally called at the end of the lonwizstate constructor. |
=item B<registerState>(referenceToStateObj): Registers a state as part of the wizard, so the wizard can use it. The 'referenceToStateObj' should be a reference to an instantiated lonwizstate object. This is normally called at the end of the lonwizard::state constructor, so you should not normally need it as a user. |
|
|
=cut |
=cut |
|
|
Line 175 sub changeState {
|
Line 199 sub changeState {
|
|
|
=cut |
=cut |
|
|
# Done in five phases |
# Done in four phases |
# 1: Do the post processing for the previous state. |
# 1: Do the post processing for the previous state. |
# 2: Do the preprocessing for the current state. |
# 2: Do the preprocessing for the current state. |
# 3: Check to see if state changed, if so, postprocess current and move to next. |
# 3: Check to see if state changed, if so, postprocess current and move to next. |
Line 187 sub display {
|
Line 211 sub display {
|
my $result = ""; |
my $result = ""; |
|
|
# Phase 1: Post processing for state of previous screen (which is actually |
# Phase 1: Post processing for state of previous screen (which is actually |
# the current state), if it wasn't the beginning state. |
# the "current state" in terms of the wizard variables), if it wasn't the |
if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->") |
# beginning state. |
{ |
if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->") { |
my $prevState = $self->{STATES}{$self->{STATE}}; |
my $prevState = $self->{STATES}{$self->{STATE}}; |
$prevState->postprocess(); |
$prevState->postprocess(); |
} |
} |
|
|
# Note, to handle errors in a state's input that a user must correct, |
# Note, to handle errors in a state's input that a user must correct, |
Line 202 sub display {
|
Line 226 sub display {
|
my $startState = $self->{STATE}; |
my $startState = $self->{STATE}; |
my $state = $self->{STATES}{$startState}; |
my $state = $self->{STATES}{$startState}; |
|
|
# Error checking |
# Error checking; it is intended that the developer will have |
|
# checked all paths and the user can't see this! |
if (!defined($state)) { |
if (!defined($state)) { |
$result .="Error! The state ". $startState ." is not defined."; |
$result .="Error! The state ". $startState ." is not defined."; |
return $result; |
return $result; |
Line 229 sub display {
|
Line 254 sub display {
|
</head> |
</head> |
$bodytag |
$bodytag |
HEADER |
HEADER |
if (!$state->overrideForm()) { $result.="<form method='GET'>"; } |
if (!$state->overrideForm()) { $result.="<form name='wizform' method='GET'>"; } |
$result .= <<HEADER; |
$result .= <<HEADER; |
<table border="0"><tr><td> |
<table border="0"><tr><td> |
<h2><i>$stateTitle</i></h2> |
<h2><i>$stateTitle</i></h2> |
Line 242 HEADER
|
Line 267 HEADER
|
|
|
if (!$state->overrideForm()) { |
if (!$state->overrideForm()) { |
$result .= '<center>'; |
$result .= '<center>'; |
if ($self->{STATE} ne $self->{START_STATE}) |
if ($self->{STATE} ne $self->{START_STATE}) { |
{ |
|
#$result .= '<input name="SUBMIT" type="submit" value="<- Previous" /> '; |
#$result .= '<input name="SUBMIT" type="submit" value="<- Previous" /> '; |
} |
} |
if ($self->{DONE}) |
if ($self->{DONE}) { |
{ |
|
my $returnPage = $self->{RETURN_PAGE}; |
my $returnPage = $self->{RETURN_PAGE}; |
$result .= "<a href=\"$returnPage\">End Wizard</a>"; |
$result .= "<a href=\"$returnPage\">End Wizard</a>"; |
} |
} |
else |
else { |
{ |
$result .= '<input name="back" type="button" '; |
|
$result .= 'value="<- Previous" onclick="history.go(-1)" /> '; |
$result .= '<input name="SUBMIT" type="submit" value="Next ->" />'; |
$result .= '<input name="SUBMIT" type="submit" value="Next ->" />'; |
} |
} |
$result .= "</center>\n"; |
$result .= "</center>\n"; |
Line 310 sub setVar {
|
Line 334 sub setVar {
|
|
|
=pod |
=pod |
|
|
|
=item B<queryStringVars>(): 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<setDone>(): If a state calls this, the wizard will consider itself completed. The state should display a friendly "Done" message, and the wizard will display a link returning the user to the invoking page, rather then a "Next" button. |
=item B<setDone>(): If a state calls this, the wizard will consider itself completed. The state should display a friendly "Done" message, and the wizard will display a link returning the user to the invoking page, rather then a "Next" button. |
|
|
=cut |
=cut |
Line 342 sub handler {
|
Line 387 sub handler {
|
$r->rflush(); |
$r->rflush(); |
|
|
my $mes = <<WIZBEGIN; |
my $mes = <<WIZBEGIN; |
<p>This wizard will allow you to</p> |
<p>This wizard will allow you to <b>set open, due, and answer dates for problems</b>. You will be asked to select a problem, what kind of date you want to set, and for whom the date should be effective.</p> |
|
|
<ul> |
|
<li>Change assignment parameters, such as due date or open date...</li> |
|
<li>... for a whole class</li> |
|
<li>... for a whole section</li> |
|
<li>... for an individual student</li> |
|
<li>... by folder</li> |
|
<li>... by individual assignment</li> |
|
</ul> |
|
|
|
<p>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.</p> |
<p>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.</p> |
|
|
|
<p>Press <b>Next -></b> to begin, or select <b><- Previous</b> to go back to the previous screen.</p> |
WIZBEGIN |
WIZBEGIN |
|
|
my $wizard = Apache::lonwizard->new("Course Parameter Wizard"); |
my $wizard = Apache::lonwizard->new("Course Parameter Wizard"); |
$wizard->declareVars(['ACTION_TYPE', 'GRANULARITY', 'TARGETS', 'PARM_DATE', 'RESOURCE_ID', 'USER_NAME', 'SECTION_NAME']); |
$wizard->declareVars(['ACTION_TYPE', 'GRANULARITY', 'TARGETS', 'PARM_DATE', 'RESOURCE_ID', 'USER_NAME', 'SECTION_NAME']); |
my %dateTypeHash = ('open_date' => "Opening Date", |
my %dateTypeHash = ('open_date' => "opening date", |
'due_date' => "Due Date", |
'due_date' => "due date", |
'answer_date' => "Answer 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::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "CHOOSE_LEVEL"); |
Apache::lonwizard::switch_state->new($wizard, "CHOOSE_ACTION", "What do you want to do?", "ACTION_TYPE", [ |
Apache::lonwizard::switch_state->new($wizard, "CHOOSE_LEVEL", "Which Problem or Problems?", "GRANULARITY", [ |
["open_date", "Set an Open Date for a problem", "CHOOSE_LEVEL"], |
["whole_course", "<b>Every problem</b> in the course", "CHOOSE_ACTION"], |
["due_date", "Set a Due Date for a problem", "CHOOSE_LEVEL"], |
["map", "Every problem in a particular <b>folder</b>", "CHOOSE_FOLDER"], |
["answer_date", "Set an Answer Open Date for a problem", "CHOOSE_LEVEL" ] ]); |
["resource", "One particular <b>problem</b>", "CHOOSE_RESOURCE"]], |
Apache::lonwizard::switch_state->new($wizard, "CHOOSE_LEVEL", "Parameter Granularity", "GRANULARITY", [ |
"Which problems do you wish to change a date for?"); |
["whole_course", "Set for Whole Course", "CHOOSE_STUDENT_LEVEL"], |
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();}); |
["map", "Set for a Folder/Map", "CHOOSE_FOLDER"], |
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(); }); |
["resource", "Set for a Particular Problem", "CHOOSE_RESOURCE"]], |
my $levelType = $levelTypeHash{$wizard->{VARS}->{GRANULARITY}}; |
"How general should this setting be?"); |
Apache::lonwizard::switch_state->new($wizard, "CHOOSE_ACTION", "Parameter Type", "ACTION_TYPE", [ |
Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_FOLDER", "Select Folder", "", "", "CHOOSE_STUDENT_LEVEL", "RESOURCE_ID", sub {my $res = shift; return $res->is_map();}); |
["open_date", "Set an <b>open date</b>", "CHOOSE_DATE"], |
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(); }); |
["due_date", "Set a <b>due date</b>", "CHOOSE_DATE"], |
Apache::lonwizard::switch_state->new($wizard, "CHOOSE_STUDENT_LEVEL", "Parameter Targets", "TARGETS", [ |
["answer_date", "Set an <b>answer open date</b>", "CHOOSE_DATE" ] ], |
["course", "Set for All Students in Course", "CHOOSE_DATE"], |
"What parameters do you want to set for $levelType?"); |
["section", "Set for Section", "CHOOSE_SECTION"], |
|
["student", "Set for an Individual Student", "CHOOSE_STUDENT"]], |
|
"Whom should this setting affect?"); |
|
|
|
my $dateType = $dateTypeHash{$wizard->{VARS}->{ACTION_TYPE}}; |
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::date_state->new($wizard, "CHOOSE_DATE", "Set Date", "PARM_DATE", "CHOOSE_STUDENT_LEVEL", "What should the $dateType be set to?"); |
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::switch_state->new($wizard, "CHOOSE_STUDENT_LEVEL", "Students Affected", "TARGETS", [ |
Apache::lonwizard::date_state->new($wizard, "CHOOSE_DATE", "Set Date", "PARM_DATE", "FINISH", "What should the $dateType be set to?"); |
["course", ". . . for <b>all students</b> in the course", "FINISH"], |
|
["section", ". . . for a particular <b>section</b>", "CHOOSE_SECTION"], |
|
["student", ". . . for an individual <b>student</b>", "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"); |
Apache::lonwizard::parmwizfinal->new($wizard, "FINISH", "Confirm Selection"); |
|
|
$r->print($wizard->display()); |
$r->print($wizard->display()); |
Line 405 It is importent to remember when constru
|
Line 448 It is importent to remember when constru
|
|
|
None of the pre-packaged states correctly handle there being B<no> input, as the wizard does not currently have any protection against errors in the states themselves. (The closest thing you can do is set the wizard to be done and display an error message, which should be adequate.) |
None of the pre-packaged states correctly handle there being B<no> input, as the wizard does not currently have any protection against errors in the states themselves. (The closest thing you can do is set the wizard to be done and display an error message, which should be adequate.) |
|
|
|
By default, the wizard framework will take form elements of the form {VAR_NAME}.forminput and automatically insert the contents of that form element into the wizard variable {VAR_NAME}. You only need to use postprocess to do something fancy if that is not sufficient, for instance, processing a multi-element selection. (See resource choice for an example of that.) |
|
|
=head2 lonwizstate methods |
=head2 lonwizstate methods |
|
|
These methods should be overridden in derived states, except B<new> which may be sufficient. |
These methods should be overridden in derived states, except B<new> which may be sufficient. |
Line 423 These methods should be overridden in de
|
Line 468 These methods should be overridden in de
|
|
|
=item B<render>(): render returns a string of itself to be rendered to the screen, which the wizard will display. |
=item B<render>(): render returns a string of itself to be rendered to the screen, which the wizard will display. |
|
|
=back |
|
|
|
=cut |
=cut |
|
|
package Apache::lonwizard::state; |
package Apache::lonwizard::state; |
Line 461 sub preprocess {
|
Line 504 sub preprocess {
|
return 1; |
return 1; |
} |
} |
|
|
|
=pod |
|
|
|
=item * B<process_multiple_choices>(formname, var_name): A service function that correctly handles resources with multiple selections, such as checkboxes. It delimits the selections with triple pipes and stores them in the given wizard variable. 'formname' is the name of the form element to process. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
sub process_multiple_choices { |
|
my $self = shift; |
|
my $formname = shift; |
|
my $var = shift; |
|
my $wizard = $self->{WIZARD}; |
|
|
|
my $formvalue = $ENV{'form.' . $formname}; |
|
if ($formvalue) { |
|
# Must extract values from $wizard->{DATA} directly, as there |
|
# may be more then one. |
|
my @values; |
|
for my $formparam (split (/&/, $wizard->{DATA})) { |
|
my ($name, $value) = split(/=/, $formparam); |
|
if ($name ne $formname) { |
|
next; |
|
} |
|
$value =~ tr/+/ /; |
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
|
push @values, $value; |
|
} |
|
$wizard->setVar($var, join('|||', @values)); |
|
} |
|
|
|
return; |
|
} |
|
|
sub render { |
sub render { |
return "This is the empty state. If you can see this, it's a bug.\n" |
return "This is the empty state. If you can see this, it's a bug.\n" |
} |
} |
Line 545 If there is only one choice, the state w
|
Line 622 If there is only one choice, the state w
|
|
|
=over 4 |
=over 4 |
|
|
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, choiceHash): messageBefore is the HTML text that will be displayed before the choice display, messageAfter will display after. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it. |
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, nextState, varName, choiceHash, multichoice): messageBefore is the HTML text that will be displayed before the choice display. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it. multichoice is true if the user can make multiple choices, false otherwise. (Multiple choices will be seperated with ||| in the wizard variable. |
|
|
=back |
=back |
|
|
Line 557 sub new {
|
Line 634 sub new {
|
my $self = bless $proto->SUPER::new(shift, shift, shift); |
my $self = bless $proto->SUPER::new(shift, shift, shift); |
|
|
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_AFTER} = shift; |
|
$self->{NEXT_STATE} = shift; |
$self->{NEXT_STATE} = shift; |
$self->{VAR_NAME} = shift; |
$self->{VAR_NAME} = shift; |
$self->{CHOICE_HASH} = shift; |
$self->{CHOICE_HASH} = shift; |
|
$self->{MULTICHOICE} = shift; |
$self->{NO_CHOICES} = 0; |
$self->{NO_CHOICES} = 0; |
|
|
return $self; |
return $self; |
Line 598 sub preprocess {
|
Line 675 sub preprocess {
|
} |
} |
|
|
sub determineChoices { |
sub determineChoices { |
return {"NO_CHOICE" => "No choices were given."}; |
# Return no choices, which will terminate the wizard |
|
return {}; |
} |
} |
|
|
sub render { |
sub render { |
my $self = shift; |
my $self = shift; |
my $result = ""; |
my $result = ""; |
my $var = $self->{VAR_NAME}; |
my $var = $self->{VAR_NAME}; |
|
my $buttons = ''; |
|
|
|
if ($self->{MULTICHOICE}) { |
|
$result = <<SCRIPT; |
|
<script> |
|
function checkall(value) { |
|
for (i=0; i<document.forms.wizform.elements.length; i++) { |
|
document.forms.wizform.elements[i].checked=value; |
|
} |
|
} |
|
</script> |
|
SCRIPT |
|
$buttons = <<BUTTONS; |
|
<input type="button" onclick="checkall(true)" value="Select All" /> |
|
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
|
<br /> |
|
BUTTONS |
|
} |
|
|
if (defined $self->{ERROR_MSG}) { |
if (defined $self->{ERROR_MSG}) { |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
if (defined $self->{MESSAGE_BEFORE}) |
if (defined $self->{MESSAGE_BEFORE}) { |
{ |
|
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />'; |
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />'; |
} |
} |
|
|
|
$result .= $buttons; |
|
|
my $choices = $self->{CHOICE_HASH}; |
my $choices = $self->{CHOICE_HASH}; |
my @keys = keys (%$choices); |
my @keys = keys (%$choices); |
|
|
$result .= "<select name=\"$var.forminput\" size=\"10\">\n"; |
my $type = "radio"; |
foreach (@keys) |
if ($self->{MULTICHOICE}) { $type = 'checkbox'; } |
{ |
foreach (@keys) { |
$result .= "<option value=\"" . HTML::Entities::encode($choices->{$_}) |
|
. "\">" . HTML::Entities::encode($_) . "\n"; |
$result .= "<input type='$type' name='" . |
} |
$self->{VAR_NAME} . '.forminput' . |
$result .= "</select>\n\n"; |
"' value=\"" . |
|
HTML::Entities::encode($choices->{$_}) |
if (defined $self->{MESSAGE_AFTER}) |
. "\"/> " . HTML::Entities::encode($_) . "<br />\n"; |
{ |
|
$result .= '<br /><br />' . $self->{MESSAGE_AFTER}; |
|
} |
} |
|
|
return $result; |
return $result; |
Line 639 sub postprocess {
|
Line 734 sub postprocess {
|
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; |
my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; |
if ($formvalue) { |
if ($formvalue) { |
$wizard->setVar($self->{VAR_NAME}, $formvalue); |
if ($self->{MULTICHOICE}) { |
|
$self->process_multiple_choices($self->{VAR_NAME}.'.forminput', |
|
$self->{VAR_NAME}); |
|
} |
|
# For non-multichoice, value already stored by Wizard |
$wizard->changeState($self->{NEXT_STATE}); |
$wizard->changeState($self->{NEXT_STATE}); |
} else { |
} else { |
$self->{ERROR_MSG} = "Can't continue the wizard because you must make" |
$self->{ERROR_MSG} = "Can't continue the wizard because you must make" |
Line 664 Each choice may have arbitrary HTML asso
|
Line 763 Each choice may have arbitrary HTML asso
|
|
|
=over 4 |
=over 4 |
|
|
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, varName, choiceList, messageBefore, messageAfter): varName is the name of the wizard variable the state will set with the choice made. choiceHash is list reference of a list of list references to three element lists, where the first element is what the wizard var varName will be set to, the second is the HTML that will be displayed for that choice, and the third is the destination state. messageBefore is an optional HTML string that will be placed before the message, messageAfter an optional HTML string that will be placed before. |
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, varName, choiceList, messageBefore): varName is the name of the wizard variable the state will set with the choice made. choiceHash is list reference of a list of list references to three element lists, where the first element is what the wizard var varName will be set to, the second is the HTML that will be displayed for that choice, and the third is the destination state. The special setting 'ILLEGAL' can be used in the first place to state that it is not a legal chocie (see lonprintout.pm for real-life usage of that). messageBefore is an optional HTML string that will be placed before the message. |
|
|
|
Note that ILLEGAL is desirable because some choices may not always be good choices, but they should not necessarily disappear with no explanantion of why they are no good. In lonprintout.pm, for instance, the choice "Problems from current sequence" may be no good because there are no problems in the sequence, but it should not silently disappear; it should announce that there are no problems in the sequence. |
|
|
An example of a legit choiceList: C<my $choicelist = [ ["flunk", "Flunk Student", "FLUNK_STATE"], ["pass", "Pass Student", "PASS_STATE"] ];> |
An example of a legit choiceList: C<my $choicelist = [ ["flunk", "Flunk Student", "FLUNK_STATE"], ["pass", "Pass Student", "PASS_STATE"] ];> |
|
|
=back |
=back |
|
|
Line 680 sub new {
|
Line 781 sub new {
|
$self->{VAR_NAME} = shift; |
$self->{VAR_NAME} = shift; |
$self->{CHOICE_LIST} = shift; |
$self->{CHOICE_LIST} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_AFTER} = shift; |
|
|
|
return $self; |
return $self; |
} |
} |
Line 696 sub render {
|
Line 796 sub render {
|
|
|
$result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE}); |
$result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE}); |
|
|
if (!$curVal) { |
|
$curVal = $self->{CHOICE_LIST}->[0]->[0]; # top is default |
|
} |
|
|
|
$result .= "<table>\n\n"; |
$result .= "<table>\n\n"; |
|
|
foreach my $choice (@choices) |
my $checked = 0; |
{ |
foreach my $choice (@choices) { |
my $value = $choice->[0]; |
my $value = $choice->[0]; |
my $text = $choice->[1]; |
my $text = $choice->[1]; |
|
|
$result .= "<tr>\n<td width='20'> </td>\n<td>"; |
$result .= "<tr>\n<td width='20'> </td>\n<td>"; |
$result .= "<td valign=\"top\"><input type=\"radio\" name=\"$var.forminput\""; |
$result .= "<td valign=\"top\"><input type=\"radio\" name=\"$var.forminput\""; |
$result .= " checked" if ($value eq $curVal); |
if (!$checked) { |
|
$result .= " checked"; |
|
$checked = 1; |
|
} |
$result .= " value=\"$value\"></td>\n<td>$text</td>\n</tr>\n\n"; |
$result .= " value=\"$value\"></td>\n<td>$text</td>\n</tr>\n\n"; |
} |
} |
|
|
$result .= "<table>\n\n"; |
$result .= "<table>\n\n"; |
|
|
$result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER}); |
|
|
|
return $result; |
return $result; |
} |
} |
|
|
sub postprocess { |
sub postprocess { |
|
# Value already stored by wizard |
my $self = shift; |
my $self = shift; |
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . '.forminput'}; |
my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . '.forminput'}; |
$wizard->setVar($self->{VAR_NAME}, $chosenValue) |
|
if (defined ($self->{VAR_NAME})); |
|
|
|
foreach my $choice (@{$self->{CHOICE_LIST}}) |
foreach my $choice (@{$self->{CHOICE_LIST}}) { |
{ |
if ($choice->[0] eq $chosenValue) { |
if ($choice->[0] eq $chosenValue) |
|
{ |
|
$wizard->changeState($choice->[2]); |
$wizard->changeState($choice->[2]); |
} |
} |
} |
} |
Line 742 sub preprocess {
|
Line 836 sub preprocess {
|
my $choiceList = $self->{CHOICE_LIST}; |
my $choiceList = $self->{CHOICE_LIST}; |
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
|
|
if (scalar(@{$choiceList}) == 1) |
if (scalar(@{$choiceList}) == 1) { |
{ |
|
my $choice = $choiceList->[0]; |
my $choice = $choiceList->[0]; |
my $chosenVal = $choice->[0]; |
my $chosenVal = $choice->[0]; |
my $nextState = $choice->[2]; |
my $nextState = $choice->[2]; |
Line 777 Date state provides a state for selectin
|
Line 870 Date state provides a state for selectin
|
|
|
=over 4 |
=over 4 |
|
|
=item overriddent method B<new>(parentLonWizReference, stateName, stateTitle, varName, nextState, messageBefore, messageAfter, displayJustDate): varName is where the date/time will be stored as seconds since the epoch. messageBefore and messageAfter as other states. displayJustDate is a flag defaulting to false that if true, will only display the date selection (defaulting to midnight on that date). Otherwise, minutes and hours will be shown. |
=item overriddent method B<new>(parentLonWizReference, stateName, stateTitle, varName, nextState, messageBefore, displayJustDate): varName is where the date/time will be stored as seconds since the epoch. messageBefore and messageAfter as other states. displayJustDate is a flag defaulting to false that if true, will only display the date selection (defaulting to midnight on that date). Otherwise, minutes and hours will be shown. |
|
|
=back |
=back |
|
|
Line 791 sub new {
|
Line 884 sub new {
|
$self->{VAR_NAME} = shift; |
$self->{VAR_NAME} = shift; |
$self->{NEXT_STATE} = shift; |
$self->{NEXT_STATE} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_AFTER} = shift; |
|
$self->{DISPLAY_JUST_DATE} = shift; |
$self->{DISPLAY_JUST_DATE} = shift; |
if (!defined($self->{DISPLAY_JUST_DATE})) {$self->{DISPLAY_JUST_DATE} = 0;} |
if (!defined($self->{DISPLAY_JUST_DATE})) {$self->{DISPLAY_JUST_DATE} = 0;} |
return $self; |
return $self; |
Line 806 sub render {
|
Line 898 sub render {
|
|
|
my $date; |
my $date; |
|
|
# Pick default date: Now, or previous choice |
# Default date: Now |
if (defined ($wizvars->{$var}) && $wizvars->{$var} ne "") |
$date = localtime($wizvars->{$var}); |
{ |
|
$date = localtime($wizvars->{$var}); |
|
} |
|
else |
|
{ |
|
$date = localtime(); |
|
} |
|
|
|
if (defined $self->{ERROR_MSG}) { |
if (defined $self->{ERROR_MSG}) { |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
Line 834 sub render {
|
Line 919 sub render {
|
} else { |
} else { |
$result .= "<option value='$i'>"; |
$result .= "<option value='$i'>"; |
} |
} |
$result .= @months[$i] . "\n"; |
$result .= $months[$i] . "</option>\n"; |
} |
} |
$result .= "</select>\n"; |
$result .= "</select>\n"; |
|
|
Line 846 sub render {
|
Line 931 sub render {
|
} else { |
} else { |
$result .= '<option>'; |
$result .= '<option>'; |
} |
} |
$result .= "$i\n"; |
$result .= "$i</option>\n"; |
} |
} |
$result .= "</select>,\n"; |
$result .= "</select>,\n"; |
|
|
Line 858 sub render {
|
Line 943 sub render {
|
} else { |
} else { |
$result .= "<option>"; |
$result .= "<option>"; |
} |
} |
$result .= "$i\n"; |
$result .= "$i</option>\n"; |
} |
} |
$result .= "</select>,\n"; |
$result .= "</select>,\n"; |
|
|
# Display Hours and Minutes if they are called for |
# Display Hours and Minutes if they are called for |
if (!$self->{DISPLAY_JUST_DATE}) { |
if (!$self->{DISPLAY_JUST_DATE}) { |
|
# Build hour |
$result .= "<select name='$self->{VAR_NAME}hour'>\n"; |
$result .= "<select name='$self->{VAR_NAME}hour'>\n"; |
if ($date->hour == 12) { $result .= "<option selected>12\n"; } |
$result .= "<option " . ($date->hour == 0 ? 'selected ':'') . |
else { $result .= "<option>12\n" } |
" value='0'>midnight</option>\n"; |
for ($i = 1; $i < 12; $i++) { |
for ($i = 1; $i < 12; $i++) { |
if (($date->hour) % 12 == $i % 12) { |
if ($date->hour == $i) { |
$result .= "<option selected>"; |
$result .= "<option selected value='$i'>$i a.m.</option>\n"; |
} else { |
} else { |
$result .= "<option>"; |
$result .= "<option value='$i'>$i a.m</option>\n"; |
|
} |
|
} |
|
$result .= "<option " . ($date->hour == 12 ? 'selected ':'') . |
|
" value='12'>noon</option>\n"; |
|
for ($i = 13; $i < 24; $i++) { |
|
my $printedHour = $i - 12; |
|
if ($date->hour == $i) { |
|
$result .= "<option selected value='$i'>$printedHour p.m.</option>\n"; |
|
} else { |
|
$result .= "<option value='$i'>$printedHour p.m.</option>\n"; |
} |
} |
$result .= "$i\n"; |
|
} |
} |
|
|
$result .= "</select> :\n"; |
$result .= "</select> :\n"; |
|
|
$result .= "<select name='$self->{VAR_NAME}minute'>\n"; |
$result .= "<select name='$self->{VAR_NAME}minute'>\n"; |
for ($i = 0; $i < 60; $i++) { |
for ($i = 0; $i < 60; $i++) { |
|
my $printedMinute = $i; |
|
if ($i < 10) { |
|
$printedMinute = "0" . $printedMinute; |
|
} |
if ($date->min == $i) { |
if ($date->min == $i) { |
$result .= "<option selected>"; |
$result .= "<option selected>"; |
} else { |
} else { |
$result .= "<option>"; |
$result .= "<option>"; |
} |
} |
$result .= "$i\n"; |
$result .= "$printedMinute</option>\n"; |
} |
} |
$result .= "</select>\n"; |
$result .= "</select>\n"; |
|
|
$result .= "<select name='$self->{VAR_NAME}meridian'>\n"; |
|
if ($date->hour < 12) { |
|
$result .= "<option selected>A.M.\n<option>P.M.\n"; |
|
} else { |
|
$result .= "<option>A.M.\n<option selected>P.M.\n"; |
|
} |
|
$result .= "</select>"; |
|
} |
} |
|
|
if (defined ($self->{MESSAGE_AFTER})) { |
if (defined ($self->{MESSAGE_AFTER})) { |
Line 943 sub postprocess {
|
Line 1035 sub postprocess {
|
package Apache::lonwizard::parmwizfinal; |
package Apache::lonwizard::parmwizfinal; |
|
|
# This is the final state for the parmwizard. It is not generally useful, |
# This is the final state for the parmwizard. It is not generally useful, |
# so it is not perldoc'ed. It does it's own processing. |
# so it is not perldoc'ed. It does its own processing. |
|
|
no strict; |
no strict; |
@ISA = ('Apache::lonwizard::state'); |
@ISA = ('Apache::lonwizard::state'); |
Line 973 sub render {
|
Line 1065 sub render {
|
'due_date' => "0_duedate", |
'due_date' => "0_duedate", |
'answer_date' => "0_answerdate"); |
'answer_date' => "0_answerdate"); |
|
|
my $result = "<form method='get' action='/adm/parmset'>\n"; |
my $result = "<form name='wizform' method='get' action='/adm/parmset'>\n"; |
$result .= '<p>Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.<ul>'; |
$result .= '<p>Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.<ul>'; |
my $affectedResourceId = ""; |
my $affectedResourceId = ""; |
my $parm_name = $parmTypeHash{$wizvars->{ACTION_TYPE}}; |
my $parm_name = $parmTypeHash{$wizvars->{ACTION_TYPE}}; |
Line 1075 package Apache::lonwizard::resource_choi
|
Line 1167 package Apache::lonwizard::resource_choi
|
|
|
=head2 Class: resource_choice |
=head2 Class: resource_choice |
|
|
folder_choice gives the user an opportunity to select one resource from the current course, and will stick the ID of that choice (#.#) into the desired variable. |
resource_choice gives the user an opportunity to select one resource from the current course, and will stick the ID of that choice (#.#) into the desired variable. |
|
|
Note this state will not automatically advance if there is only one choice, because it might confuse the user in this case. |
Note this state will not automatically advance if there is only one choice, because it might confuse the user in this case. |
|
|
=over 4 |
=over 4 |
|
|
=item overriddent method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, filterFunction, choiceFunction): messageBefore and messageAfter appear before and after the state choice, respectively. nextState is the state to proceed to after the choice. varName is the wizard variable to store the choice in. |
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, nextState, varName, filterFunction, choiceFunction): messageBefore and messageAfter appear before and after the state choice, respectively. nextState is the state to proceed to after the choice. varName is the wizard variable to store the choice in. |
|
|
filterFunction is a function reference that receives the current resource as an argument, and returns 1 if it should be displayed, and 0 if it should not be displayed. By default, the class will use sub {return 1;}, which will show all resources. choiceFunction is a reference to a function that receives the resource object as a parameter and returns 1 if it should be a *selectable choice*, and 0 if not. By default, this is the same as the filterFunction, which means all displayed choices will be choosable. See parm wizard for an example of this in the resource selection routines. |
filterFunction is a function reference that receives the current resource as an argument, and returns 1 if it should be displayed, and 0 if it should not be displayed. By default, the class will use sub {return 1;}, which will show all resources. choiceFunction is a reference to a function that receives the resource object as a parameter and returns 1 if it should be a *selectable choice*, and 0 if not. By default, this is the same as the filterFunction, which means all displayed choices will be choosable. See parm wizard for an example of this in the resource selection routines. |
|
|
Line 1099 sub new {
|
Line 1191 sub new {
|
my $self = bless $proto->SUPER::new(shift, shift, shift); |
my $self = bless $proto->SUPER::new(shift, shift, shift); |
|
|
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_BEFORE} = shift; |
$self->{MESSAGE_AFTER} = shift; |
|
$self->{NEXT_STATE} = shift; |
$self->{NEXT_STATE} = shift; |
$self->{VAR_NAME} = shift; |
$self->{VAR_NAME} = shift; |
$self->{FILTER_FUNC} = shift; |
$self->{FILTER_FUNC} = shift; |
Line 1115 sub new {
|
Line 1206 sub new {
|
sub postprocess { |
sub postprocess { |
my $self = shift; |
my $self = shift; |
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . ".forminput"}; |
|
$wizard->setVar($self->{VAR_NAME}, $chosenValue) |
# If we were just manipulating a folder, do not proceed to the |
if (defined($self->{VAR_NAME})); |
# next state |
|
if ($ENV{'form.folderManip'}) { |
|
return; |
|
} |
|
|
|
if (!$ENV{'form.' . $self->{VAR_NAME} . '.forminput'}) { |
|
$self->{ERROR_MSG} = "Can't continue wizard because you must ". |
|
"select a resource."; |
|
return; |
|
} |
|
|
|
|
|
# Value stored by wizard framework |
|
|
$wizard->changeState($self->{NEXT_STATE}); |
$wizard->changeState($self->{NEXT_STATE}); |
} |
} |
|
|
|
# A note, in case I don't get to this before I leave. |
|
# If someone complains about the "Back" button returning them |
|
# to the previous folder state, instead of returning them to |
|
# the previous wizard state, the *correct* answer is for the wizard |
|
# to keep track of how many times the user has manipulated the folders, |
|
# and feed that to the history.go() call in the wizard rendering routines. |
|
# If done correctly, the wizard itself can keep track of how many times |
|
# it renders the same states, so it doesn't go in just this state, and |
|
# you can lean on the browser back button to make sure it all chains |
|
# correctly. |
|
# Either that, or force all folders open and don't allow the user |
|
# to close them. |
|
|
sub render { |
sub render { |
my $self = shift; |
my $self = shift; |
|
my $wizard = $self->{WIZARD}; |
my $result = ""; |
my $result = ""; |
my $var = $self->{VAR_NAME}; |
my $var = $self->{VAR_NAME}; |
my $curVal = $self->{WIZARD}->{VARS}->{$var}; |
my $curVal = $self->{WIZARD}->{VARS}->{$var}; |
|
my $vals = {}; |
|
if ($curVal =~ /,/) { # multiple choices |
|
foreach (split /,/, $curVal) { |
|
$vals->{$_} = 1; |
|
} |
|
} else { |
|
$vals->{$curVal} = 1; |
|
} |
|
|
$result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE}); |
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
# Get the course nav map |
|
my $navmap = Apache::lonnavmaps::navmap->new( |
|
$ENV{"request.course.fn"}.".db", |
|
$ENV{"request.course.fn"}."_parms.db", 0, 0); |
|
|
|
if (!defined($navmap)) { |
|
return "<font color='red' size='+1'>Something has gone wrong with the map selection feature. Please contact your administrator.</font>"; |
|
} |
} |
|
|
my $iterator = $navmap->getIterator(undef, undef, undef, 1, 0); |
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />' |
my $depth = 1; |
if (defined $self->{MESSAGE_BEFORE}); |
$iterator->next(); # discard first BEGIN_MAP |
|
my $curRes = $iterator->next(); |
|
my $i; |
|
my $padding = " "; |
|
my $isChoosable = 0; |
|
my $filterFunc = $self->{FILTER_FUNC}; |
my $filterFunc = $self->{FILTER_FUNC}; |
my $choiceFunc = $self->{CHOICE_FUNC}; |
my $choiceFunc = $self->{CHOICE_FUNC}; |
|
|
$result .= "<table border='0'>\n"; |
# 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 |
while ($depth > 0) { |
# - Jeremy (Pythonista) ;-) |
if ($curRes == $iterator->BEGIN_MAP()) { $depth++; } |
my $checked = 0; |
if ($curRes == $iterator->END_MAP()) { $depth--; } |
my $renderColFunc = sub { |
|
my ($resource, $part, $params) = @_; |
if (ref($curRes) && &$filterFunc($curRes)) { |
|
$result .= "<tr><td>"; |
if (!&$choiceFunc($resource)) { |
|
return '<td> </td>'; |
if (&$choiceFunc($curRes)) { |
} else { |
if (!$curVal) { |
my $col = "<td><input type='radio' name='${var}.forminput' "; |
# Set this to the first one if they have no previous |
if (!$checked) { |
# selection. |
$col .= "checked "; |
$curVal = $curRes->{ID}; |
$checked = 1; |
} |
|
|
|
$isChoosable = 1; |
|
$result .= "<input type='radio' name='${var}.forminput'"; |
|
if ($curRes->{ID} eq $curVal) { |
|
$result .= " checked"; |
|
} |
|
$result .= ' value="' . $curRes->{ID} . '" />'; |
|
} |
} |
|
$col .= "value='" . $resource->{ID} . "' /></td>"; |
|
return $col; |
|
} |
|
}; |
|
|
$result .= "</td><td>"; |
$result .= |
|
&Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, |
|
Apache::lonnavmaps::resource()], |
|
'showParts' => 0, |
|
'queryString' => $wizard->queryStringVars() . '&folderManip=1', |
|
'url' => $wizard->{URL}, |
|
'filterFunc' => $filterFunc } ); |
|
|
|
return $result; |
|
} |
|
|
|
1; |
|
|
for ($i = 0; $i < $depth; $i++) { |
package Apache::lonwizard::resource_multichoice; |
$result .= $padding; |
|
} |
=pod |
|
|
|
=head2 Class: resource_multichoice |
|
|
|
resource_multichoice gives the user an opportunity to select multiple resources from some map in the current course, and will stick a list of the IDs of those choices in its variable. |
|
|
|
Note this state will not automatically advance if there is only one choice, because it might confuse the user. Also, the state will not advance until at least I<one> choice is taken, because it is generally nonsense to select nothing when this state is used. |
|
|
|
This is generally intended for use on a specific sequence, not the entire course, as for technical reasons the user can't open and close folders, so they must all be shown as open. To fix this would require making the folders image form submitters and remembering the selected state of each resource, which is not impossible but is too much error-prone work to do until it seems many people will want that feature. |
|
|
|
Note this class is generally useful for multi-choice selections, by overridding "determineChoices" to return the choice hash. |
|
|
|
=over 4 |
|
|
|
=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, nextState, varName, filterFunction, choiceFunction, map): Arguments like resource_choice. map is the ID number of a specific map that, if given is all that will be shown to the user, instead of the whole course. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonwizard::state"); |
|
use strict; |
|
|
|
sub new { |
|
my $proto = shift; |
|
my $class = ref($proto) || $proto; |
|
my $self = bless $proto->SUPER::new(shift, shift, shift); |
|
|
|
$self->{MESSAGE_BEFORE} = shift; |
|
$self->{NEXT_STATE} = shift; |
|
$self->{VAR_NAME} = shift; |
|
$self->{FILTER_FUNC} = shift; |
|
if (!defined($self->{FILTER_FUNC})) { |
|
$self->{FILTER_FUNC} = sub {return 1;}; |
|
} |
|
$self->{CHOICE_FUNC} = shift; |
|
if (!defined($self->{CHOICE_FUNC})) { |
|
$self->{CHOICE_FUNC} = $self->{FILTER_FUNC}; |
|
} |
|
$self->{MAP} = shift; |
|
if (!defined($self->{MAP})) { |
|
$self->{MAP} = 1; # 0? trying to default to entire course |
|
} |
|
} |
|
|
|
sub postprocess { |
|
my $self = shift; |
|
my $wizard = $self->{WIZARD}; |
|
|
#$result .= "<img border='0' src='/adm/lonIcons/navmap.folder.open.gif'>"; |
$self->process_multiple_choices($self->{VAR_NAME}.'.forminput', |
$result .= $curRes->compTitle . "</td></tr>\n"; |
$self->{VAR_NAME}); |
|
|
|
# If nothing was selected... |
|
if (!$wizard->{VARS}->{$self->{VAR_NAME}}) { |
|
$self->{ERROR_MSG} = "You must select one or more resources to continue."; |
|
return; |
|
} |
|
|
|
$wizard->changeState($self->{NEXT_STATE}); |
|
} |
|
|
|
sub render { |
|
my $self = shift; |
|
my $wizard = $self->{WIZARD}; |
|
my $var = $self->{VAR_NAME}; |
|
my $result = <<SCRIPT; |
|
<script> |
|
function checkall(value) { |
|
for (i=0; i<document.forms.wizform.elements.length; i++) { |
|
document.forms.wizform.elements[i].checked=value; |
} |
} |
|
} |
|
</script> |
|
SCRIPT |
|
|
|
my $buttons = <<BUTTONS; |
|
<input type="button" onclick="checkall(true)" value="Select All" /> |
|
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
|
<br /> |
|
BUTTONS |
|
|
$curRes = $iterator->next(); |
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
$result .= "</table>\n"; |
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />' |
|
if (defined $self->{MESSAGE_BEFORE}); |
|
|
$navmap->untieHashes(); |
my $filterFunc = $self->{FILTER_FUNC}; |
|
my $choiceFunc = $self->{CHOICE_FUNC}; |
|
|
if (!$isChoosable) { |
# Create the composite function that renders the column on the nav map |
# FIXME: Check all the wiz vars for this. |
my $renderColFunc = sub { |
$result .= "<p><font color='#ff0000'>There are no valid resources to select in this course.</font> The entire course will be selected by default (as if 1you selected "Set for Whole Course" on the previous screen).</p>"; |
my ($resource, $part, $params) = @_; |
$result .= "<input type='hidden' name='${var}.forminput' value='0.0' />\n"; |
|
} |
|
|
|
$result .= "<p>(Note: I need to add the icons in.)</p>"; |
if (!&$choiceFunc($resource)) { |
$result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER}); |
return '<td> </td>'; |
|
} else { |
|
my $col = "<td><input type='checkbox' name='${var}.forminput'". |
|
" value='" . $resource->{ID} . "' /></td>"; |
|
return $col; |
|
} |
|
}; |
|
|
|
$result .= $buttons; |
|
|
|
$result .= |
|
&Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, |
|
Apache::lonnavmaps::resource()], |
|
'showParts' => 0, |
|
'filterFunc' => $filterFunc, |
|
'iterator_map' => $self->{MAP}, |
|
'resource_no_folder_link' => 1 } ); |
|
|
|
$result .= $buttons; |
|
|
return $result; |
return $result; |
} |
} |
|
|
1; |
1; |
|
|
package Apache::lonwizard::choose_student; |
package Apache::lonwizard::choose_student; |
|
|
no strict; |
no strict; |
@ISA = ("Apache::lonwizard::choice_state"); |
@ISA = ("Apache::lonwizard::state"); |
use strict; |
use strict; |
|
|
sub new { |
sub new { |
my $proto = shift; |
my $proto = shift; |
my $class = ref($proto) || $proto; |
my $class = ref($proto) || $proto; |
my $self = bless $proto->SUPER::new(shift, shift, shift, shift, |
my $self = bless $proto->SUPER::new(shift, shift, shift); |
shift, shift, shift); |
|
|
$self->{MESSAGE_BEFORE} = shift; |
|
$self->{NEXT_STATE} = shift; |
|
$self->{VAR_NAME} = shift; |
|
$self->{MULTICHOICE} = shift; |
|
|
return $self; |
return $self; |
} |
} |
|
|
sub determineChoices { |
sub render { |
my %choices; |
my $self = shift; |
|
my $result = ''; |
|
my $var = $self->{VAR_NAME}; |
|
my $buttons = ''; |
|
|
my $classlist = Apache::loncoursedata::get_classlist(); |
if ($self->{MULTICHOICE}) { |
foreach (keys %$classlist) { |
$result = <<SCRIPT; |
$choices{$classlist->{$_}->[6]} = $_; |
<script> |
|
function checkall(value) { |
|
for (i=0; i<document.forms.wizform.elements.length; i++) { |
|
document.forms.wizform.elements[i].checked=value; |
|
} |
} |
} |
|
</script> |
return \%choices; |
SCRIPT |
|
$buttons = <<BUTTONS; |
|
<input type="button" onclick="checkall(true)" value="Select All" /> |
|
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
|
<br /> |
|
BUTTONS |
|
} |
|
|
|
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
|
} |
|
|
|
if (defined $self->{MESSAGE_BEFORE}) { |
|
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />'; |
|
} |
|
|
|
$result .= $buttons; |
|
|
|
my $choices = &Apache::loncoursedata::get_classlist(); |
|
|
|
my @keys = keys %{$choices}; |
|
# Sort by: Section, name |
|
|
|
my $section = Apache::loncoursedata::CL_SECTION(); |
|
my $fullname = Apache::loncoursedata::CL_FULLNAME(); |
|
|
|
@keys = sort { |
|
if ($choices->{$a}->[$section] ne $choices->{$b}->[$section]) { |
|
return $choices->{$a}->[$section] cmp $choices->{$b}->[$section]; |
|
} |
|
return $choices->{$a}->[$fullname] cmp $choices->{$b}->[$fullname]; |
|
} @keys; |
|
|
|
my $type = 'radio'; |
|
if ($self->{MULTICHOICE}) { $type = 'checkbox'; } |
|
$result .= "<table cellspacing='2' cellpadding='2' border='0'>\n"; |
|
$result .= "<tr><td></td><td align='center'><b>Student Name</b></td>". |
|
"<td align='center'><b>Section</b></td></tr>"; |
|
|
|
foreach (@keys) { |
|
$result .= "<tr><td><input type='$type' name='" . |
|
$self->{VAR_NAME} . '.forminput' . |
|
"' value='" . HTML::Entities::encode($_) |
|
. "' /></td><td>" |
|
. HTML::Entities::encode($choices->{$_}->[$fullname]) |
|
. "</td><td align='center'>" |
|
. HTML::Entities::encode($choices->{$_}->[$section]) |
|
. "</td></tr>\n"; |
|
} |
|
|
|
$result .= "</table>\n\n"; |
|
$result .= $buttons; |
|
|
|
return $result; |
|
} |
|
|
|
sub postprocess { |
|
my $self = shift; |
|
my $wizard = $self->{WIZARD}; |
|
my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; |
|
if ($formvalue) { |
|
if ($self->{MULTICHOICE}) { |
|
$self->process_multiple_choices($self->{VAR_NAME}.'.forminput', |
|
$self->{VAR_NAME}); |
|
} |
|
$wizard->changeState($self->{NEXT_STATE}); |
|
} else { |
|
$self->{ERROR_MSG} = "Can't continue the wizard because you must make" |
|
. ' a selection to continue.'; |
|
} |
|
return 1; |
} |
} |
|
|
|
|
1; |
1; |
|
|
package Apache::lonwizard::choose_section; |
package Apache::lonwizard::choose_section; |
Line 1263 sub determineChoices {
|
Line 1561 sub determineChoices {
|
|
|
1; |
1; |
|
|
|
package Apache::lonwizard::choose_files; |
|
|
|
=pod |
|
|
|
=head2 Class: choose_file |
|
|
|
choose_file offers a choice of files from a given directory. It will store them as a triple-pipe delimited list in its given wizard variable, in the standard HTML multiple-selection tradition. A filter function can be passed, which will examine the filename and return 1 if it should be displayed, or 0 if not. |
|
|
|
=over 4 |
|
|
|
=item * overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, nextState, varName, subdir, filterFunc): As in previous states, where filterFunc is as described in choose_file. subdir is the name of the subdirectory to offer choices from. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonwizard::state"); |
|
use strict; |
|
|
|
sub new { |
|
my $proto = shift; |
|
my $class = ref($proto) || $proto; |
|
my $self = bless $proto->SUPER::new(shift, shift, shift); |
|
|
|
$self->{MESSAGE_BEFORE} = shift; |
|
$self->{NEXT_STATE} = shift; |
|
$self->{VAR_NAME} = shift; |
|
$self->{SUB_DIR} = shift; |
|
$self->{FILTER_FUNC} = shift; |
|
|
|
if (!defined($self->{FILTER_FUNC})) { |
|
$self->{FILTER_FUNC} = sub {return 1;}; |
|
} |
|
|
|
return $self; |
|
} |
|
|
|
sub render { |
|
my $self = shift; |
|
my $result = ''; |
|
my $var = $self->{VAR_NAME}; |
|
my $subdir = $self->{SUB_DIR}; |
|
my $filterFunc = $self->{FILTER_FUNC}; |
|
|
|
$result = <<SCRIPT; |
|
<script> |
|
function checkall(value) { |
|
for (i=0; i<document.forms.wizform.elements.length; i++) { |
|
ele = document.forms.wizform.elements[i]; |
|
if (ele.type == "checkbox") { |
|
document.forms.wizform.elements[i].checked=value; |
|
} |
|
} |
|
} |
|
</script> |
|
SCRIPT |
|
|
|
my $buttons = <<BUTTONS; |
|
<br /> |
|
<input type="button" onclick="checkall(true)" value="Select All" /> |
|
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
|
<br /> |
|
BUTTONS |
|
|
|
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
|
} |
|
|
|
if ($self->{MESSAGE_BEFORE}) { |
|
$result .= $self->{MESSAGE_BEFORE} . '<br />'; |
|
} |
|
|
|
# Get the list of files in this directory. |
|
my @fileList; |
|
|
|
# If the subdirectory is in local CSTR space |
|
if ($subdir =~ m|/home/([^/]+)/public_html|) { |
|
my $user = $1; |
|
my $domain = $Apache::lonnet::perlvar{'lonDefDomain'}; |
|
@fileList = &Apache::lonnet::dirlist($subdir, $domain, $user, ''); |
|
} else { |
|
# local library server resource space |
|
@fileList = &Apache::lonnet::dirlist($subdir, $ENV{'user.domain'}, $ENV{'user.name'}, ''); |
|
} |
|
|
|
$result .= $buttons; |
|
|
|
$result .= '<table border="0" cellpadding="1" cellspacing="1">'; |
|
|
|
# Keeps track if there are no choices, prints appropriate error |
|
# if there are none. |
|
my $choices = 0; |
|
# Print each legitimate file choice. |
|
for my $file (@fileList) { |
|
$file = (split(/&/, $file))[0]; |
|
my $fileName = $subdir .'/'. $file; |
|
if (&$filterFunc($file)) { |
|
$result .= '<tr><td align="right">' . |
|
"<input type='checkbox' name='" . $self->{VAR_NAME} |
|
. ".forminput' value='" . HTML::Entities::encode($fileName) . |
|
"' /></td><td>" . $file . "</td></tr>\n"; |
|
$choices++; |
|
} |
|
} |
|
|
|
$result .= "</table>\n"; |
|
|
|
if (!$choices) { |
|
$result .= '<font color="#FF0000">There are no files available to select in this directory. Please go back and select another option.</font><br /><br />'; |
|
} |
|
|
|
$result .= $buttons; |
|
|
|
return $result; |
|
} |
|
|
|
sub postprocess { |
|
my $self = shift; |
|
print $self->{NEXT_STATE}; |
|
my $wizard = $self->{WIZARD}; |
|
|
|
$self->process_multiple_choices($self->{VAR_NAME}.'.forminput', |
|
$self->{VAR_NAME}); |
|
|
|
if (!$wizard->{VARS}->{$self->{VAR_NAME}}) { |
|
$self->{ERROR_MSG} = "Can't continue the wizard because you ". |
|
"must make a selection to continue."; |
|
} |
|
return 1; |
|
} |
|
|
|
1; |