--- loncom/interface/Attic/lonwizard.pm 2002/08/09 14:48:31 1.1 +++ loncom/interface/Attic/lonwizard.pm 2003/01/30 19:34:24 1.3 @@ -90,9 +90,9 @@ sub new { =over 2 -=item B(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 state name. +=item * B(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 state name. -=item B(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. +=item * B(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. =over 2 @@ -127,7 +127,6 @@ sub declareVars { sub _saveVars { my $self = shift; my $result = ""; - print $self->{VARS}{VAR1}; foreach my $varname (keys %{$self->{VARS}}) { $result .= 'preprocess(); # Phase 3: While the current state is different from the previous state, @@ -215,43 +220,54 @@ sub display { # Phase 4: Display. my $stateTitle = $state->title(); + my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'',''); $result .= < - LON-CAPA Wizard: $self->{NAME} + LON-CAPA Wizard: $self->{TITLE} - -

LON-CAPA Wizard: $self->{TITLE}

- -

$stateTitle

- -
+ $bodytag +HEADER + if (!$state->overrideForm()) { $result.=""; } + $result .= < +

$stateTitle

HEADER - $result .= $self->_saveVars(); + if (!$state->overrideForm()) { + $result .= $self->_saveVars(); + } $result .= $state->render() . "

 

"; - if ($self->{STATE} ne $self->{START_STATE}) - { - $result .= '  '; - } - if ($self->{DONE}) - { - my $returnPage = $self->{RETURN_PAGE}; - $result .= "End Wizard"; + if (!$state->overrideForm()) { + $result .= '
'; + if ($self->{STATE} ne $self->{START_STATE}) + { + #$result .= '  '; + } + if ($self->{DONE}) + { + my $returnPage = $self->{RETURN_PAGE}; + $result .= "End Wizard"; + } + else + { + $result .= ''; + } + $result .= "
\n"; } - else - { - $result .= ''; - } - $result .= < + + FOOTER + + return $result; } =pod @@ -284,12 +300,12 @@ sub getVars { =cut +# This may look trivial, but it's here as a hook for possible later processing sub setVar { my $self = shift; my $key = shift; my $val = shift; $self->{VARS}{$key} = $val; - print "set $key to $val
"; } =pod @@ -304,15 +320,72 @@ sub handler { my $r = shift; Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - - my $mes = "Using this wizard, you can
  • change the due date of an assignment
  • change the due date for a whole map of assignments
  • change the due date for just one person
"; - my $wizard = Apache::lonwizard->new("Test Wizard"); + if ($r->header_only) { + if ($ENV{'browser.mathml'}) { + $r->content_type('text/xml'); + } else { + $r->content_type('text/html'); + } + $r->send_http_header; + return OK; + } + + # Send header, don't cache this page + if ($ENV{'browser.mathml'}) { + $r->content_type('text/xml'); + } else { + $r->content_type('text/html'); + } + &Apache::loncommon::no_cache($r); + $r->send_http_header; + $r->rflush(); + + my $mes = <This wizard will allow you to

+ +
    +
  • Change assignment parameters, such as due date or open date...
  • +
  • ... for a whole class
  • +
  • ... for a whole section
  • +
  • ... for an individual student
  • +
  • ... by folder
  • +
  • ... by individual assignment
  • +
- my $mesState = Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "NEXT"); - my $mesState2 = Apache::lonwizard::choice_state->new($wizard, "NEXT", "Fucking the Cow", "How should the cow be fucked?", "Wow, with so many wonderful choices, how will you choose!?!", "START", "VAR1", {'standing & dildoated','standing & didldoated', 'rotten','rotten', 'sitting','sitting'}); - $wizard->declareVars( ["VAR1", "VAR2", "VAR3"] ); +

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.

+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"); + + 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?"); + + 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::parmwizfinal->new($wizard, "FINISH", "Confirm Selection"); + $r->print($wizard->display()); return OK; @@ -328,6 +401,10 @@ A "lonwizstate" object represents a lonw Several pre-prepared child classes are include in lonwizard. If you create a new wizard type, be sure to add it to lonwizard.pm so others can use it too. +It is importent to remember when constructing states that the user may use the "Previous" button to go back and revisit a state previously filled out. Thus, states should consult the wizard variables they are intended to set to see if the user has already selected something, and when displaying themselves should reselect the same values, such that the user paging from the end to the beginning, back to the end, will not change any settings. + +None of the pre-packaged states correctly handle there being B 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.) + =head2 lonwizstate methods These methods should be overridden in derived states, except B which may be sufficient. @@ -392,6 +469,12 @@ sub postprocess { return 1; } +# If this is 1, the wizard assumes the state will override the +# wizard's form, useful for some final states +sub overrideForm { + return 0; +} + 1; =pod @@ -408,7 +491,7 @@ message_state is a state the simply disp =over 4 -=item overridden method B(parentLonWizReference, stateName, message, nextState): Two new parameters "message" will be the HTML message displayed to the user, and "nextState" is the name of the next state. +=item overridden method B(parentLonWizReference, stateName, stateTitle, message, nextState): Two new parameters "message" will be the HTML message displayed to the user, and "nextState" is the name of the next state. =back @@ -424,6 +507,7 @@ sub new { my $proto = shift; my $class = ref($proto) || $proto; + # This cute looking statement correctly handles subclassing my $self = bless $proto->SUPER::new(shift, shift, shift); $self->{MESSAGE} = shift; @@ -451,19 +535,6 @@ 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->{MESSAGE_AFTER} = shift; - $self->{NEXT_STATE} = shift; - $self->{VAR_NAME} = shift; - $self->{CHOICE_HASH} = shift; - $self->{NO_CHOICES} = 0; -} - =pod =head2 Class: choice_state @@ -476,27 +547,47 @@ If there is only one choice, the state w =item overridden method B(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. +=back + =cut +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = bless $proto->SUPER::new(shift, shift, shift); + + $self->{MESSAGE_BEFORE} = shift; + $self->{MESSAGE_AFTER} = shift; + $self->{NEXT_STATE} = shift; + $self->{VAR_NAME} = shift; + $self->{CHOICE_HASH} = shift; + $self->{NO_CHOICES} = 0; + + return $self; +} + sub preprocess { my $self = shift; - my %choices = %{$self->{CHOICE_HASH}}; - my %wizvars = %{$self->{WIZARD}->getVars()}; + my $choices = $self->{CHOICE_HASH}; + if (!defined($self->{CHOICE_HASH})) { + $choices = $self->{CHOICE_HASH} = $self->determineChoices(); + } + my $wizvars = $self->{WIZARD}->getVars(); - my @keys = keys(%choices); + my @keys = keys(%$choices); @keys = sort @keys; if (scalar(@keys) == 0) { # No choices... so prepare to display error message and cancel further execution. $self->{NO_CHOICES} = 1; - $self->{WIZARD}->setDone(); + $self->{WIZARD}->{DONE} = 1; return; } if (scalar(@keys) == 1) { # If there is only one choice, pick it and move on. - $wizvars{$self->{VAR_NAME}} = $choices{$keys[0]}; + $wizvars->{$self->{VAR_NAME}} = $choices->{$keys[0]}; $self->{WIZARD}->changeState($self->{NEXT_STATE}); return; } @@ -514,33 +605,46 @@ sub render { my $self = shift; my $result = ""; my $var = $self->{VAR_NAME}; - my %choices = %{$self->{CHOICE_HASH}}; - if (!defined ($self->{CHOICE_HASH})) - { - $self->determineChoices(); + if (defined $self->{ERROR_MSG}) { + $result .= '' . $self->{ERROR_MSG} . '

'; } - my %choices = %{$self->{CHOICE_HASH}}; - my @keys = keys (%choices); + if (defined $self->{MESSAGE_BEFORE}) + { + $result .= $self->{MESSAGE_BEFORE} . '

'; + } - $result .= "\n"; foreach (@keys) { - $result .= "