From: Sam H. v. a. <we...@ma...> - 2005-08-11 22:10:38
|
Log Message: ----------- added implementation of options() which call optionsMacro(). the version in Problem.pm takes care to preserve the editMode and sourceFilePath parameters. Modified Files: -------------- webwork2/htdocs/css: ur.css webwork2/lib/WeBWorK: ContentGenerator.pm webwork2/lib/WeBWorK/ContentGenerator: Problem.pm ProblemSet.pm Revision Data ------------- Index: ur.css =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/css/ur.css,v retrieving revision 1.4 retrieving revision 1.5 diff -Lhtdocs/css/ur.css -Lhtdocs/css/ur.css -u -r1.4 -r1.5 --- htdocs/css/ur.css +++ htdocs/css/ur.css @@ -47,6 +47,7 @@ div.Message { font-style: italic; } div.Body { } div.Warnings { } +div.viewOptions { border: thin groove; padding: 1ex; margin: 2ex align: left; } /* background colors for success and failure messages */ div.ResultsWithoutError { background-color: #66ff99 } /* light green */ Index: ContentGenerator.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator.pm,v retrieving revision 1.143 retrieving revision 1.144 diff -Llib/WeBWorK/ContentGenerator.pm -Llib/WeBWorK/ContentGenerator.pm -u -r1.143 -r1.144 --- lib/WeBWorK/ContentGenerator.pm +++ lib/WeBWorK/ContentGenerator.pm @@ -737,105 +737,14 @@ =item options() -Default is defined in this package. +Not defined in this package. -Print an auxiliary options form, related to the content displayed in the -C<body>. +View options related to the content displayed in the body or info areas. See also +optionsMacro(). =cut -sub options { - my ($self) = @_; - - return "" if $self->{invalidProblem}; - my $sourceFilePathfield = ''; - if($self->r->param("sourceFilePath")) { - $sourceFilePathfield = CGI::hidden(-name => "sourceFilePath", - -value => $self->r->param("sourceFilePath")); - } - - my $r = $self->{r}; - my $ce = $self->{ce}; - # insure that certain defaults are defined - $self->{must} = {} unless defined $self->{must}; - $self->{can} = {} unless defined $self->{can}; - $self->{will} = {} unless defined $self->{will}; - - # displayMode - my $displayMode = $r->param("displayMode") || $ce->{pg}->{options}->{displayMode}; - $self->{displayMode} = $displayMode unless defined $self->{displayMode}; - - # showOldAnswers - my $want_to_showOldAnswers = defined($r->param("showOldAnswers")) ? - $r->param("showOldAnswers") : $ce->{pg}->{options}->{showOldAnswers}; - $self->{can}->{showOldAnswers} = 1; - $self->{will}->{showOldAnswers} = $self->{can}->{showOldAnswers} && $want_to_showOldAnswers; - - return join("", - CGI::start_form("POST", $self->{r}->uri), - $self->hidden_authen_fields, - $sourceFilePathfield, - CGI::hr(), - CGI::start_div({class=>"viewOptions"}), - $self->viewOptions(), - CGI::end_div(), - CGI::end_form() - ); -} - -sub viewOptions { - my ($self) = @_; - my $ce = $self->r->ce; - - # don't show options if we don't have anything to show - return if $self->{invalidSet} or $self->{invalidProblem}; - #return unless $self->{isOpen}; - - my $displayMode = $self->{displayMode}; - my %must = %{ $self->{must} }; - my %can = %{ $self->{can} }; - my %will = %{ $self->{will} }; - - my $optionLine; - $can{showOldAnswers} and $optionLine .= join "", - "Show saved answers?".CGI::br(), - CGI::radio_group( - -name => "showOldAnswers", - -values => [1,0], - -default => $will{showOldAnswers}, - -labels => { - 0 => 'No', - 1 => 'Yes', - }, - ), .CGI::br(); - - $optionLine and $optionLine .= join "", CGI::br(); - - my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; - my @active_modes = grep { exists $display_modes{$_} } - @{$ce->{pg}->{displayModes}}; - my $modeLine = (scalar(@active_modes) > 1) ? - "View equations as: ".CGI::br(). - CGI::radio_group( - -name => "displayMode", - -values => \@active_modes, - -default => $displayMode, - -linebreak=>'true', - -labels => { - plainText => "plain", - formattedText => "formatted", - images => "images", - jsMath => "jsMath", - asciimath => "asciimath", - }, - ). CGI::br().CGI::hr() : ''; - - return CGI::div({-style=>"border: thin groove; padding: 1ex; margin: 2ex align: left"}, - $modeLine, - $optionLine, - CGI::submit(-name=>"redisplay", -label=>"Apply Options"), - ); -} +#sub options { } =item path($args) @@ -1375,6 +1284,75 @@ CGI::img({src=>$imageURL})); } +=item optionsMacro(options_to_show => \@options_to_show, extra_params => \@extra_params) + +Helper macro for displaying the View Options panel. + +@options_to_show lists the options to show, from among this list "displayMode", +"showOldAnswers", "showHints", "showSolutions". If no options are given, +"displayMode" is assumed. + +@extraParams is dereferenced and passed to the hidden_fields() method. Use this +to preserve state from the content generator calling optionsMacro(). + +This macro is intended to be called from an implementation of the options() +method. The simplest way to to this is: + + sub options { shift->optionsMacro } + +=cut + +sub optionsMacro { + my ($self, %options) = @_; + + my @options_to_show = @{$options{options_to_show}} if exists $options{options_to_show}; + @options_to_show = "displayMode" unless @options_to_show; + my %options_to_show; @options_to_show{@options_to_show} = (); # make hash for easy lookups + my @extra_params = @{$options{extra_params}} if exists $options{extra_params}; + + my $result = CGI::start_form("POST", $self->r->uri); + $result .= $self->hidden_authen_fields; + $result .= $self->hidden_fields(@extra_params) if @extra_params; + $result .= CGI::start_div({class=>"viewOptions"}); + + if (exists $options_to_show{displayMode}) { + my $curr_displayMode = $self->r->param("displayMode") || $self->r->ce->{pg}->{options}->{displayMode}; + my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; + my @active_modes = grep { exists $display_modes{$_} } @{$self->r->ce->{pg}->{displayModes}}; + if (@active_modes > 1) { + $result .= "View equations as: "; + $result .= CGI::br(); + $result .= CGI::radio_group( + -name => "displayMode", + -values => \@active_modes, + -default => $curr_displayMode, + -linebreak=>'true', + ); + $result .= CGI::br(); + } + } + + if (exists $options_to_show{showOldAnswers}) { + my $curr_showOldAnswers = $self->r->param("showOldAnswers"); + $result .= "Show saved answers?"; + $result .= CGI::br(); + $result .= CGI::radio_group( + -name => "showOldAnswers", + -values => [1,0], + -default => $curr_showOldAnswers, + -labels => { 0=>'No', 1=>'Yes' }, + ); + $result .= CGI::br(); + } + + $result .= CGI::br(); + $result .= CGI::submit(-name=>"redisplay", -label=>"Apply Options"); + $result .= CGI::end_div(); + $result .= CGI::end_form(); + + return $result; +} + =back =cut Index: Problem.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm,v retrieving revision 1.177 retrieving revision 1.178 diff -Llib/WeBWorK/ContentGenerator/Problem.pm -Llib/WeBWorK/ContentGenerator/Problem.pm -u -r1.177 -r1.178 --- lib/WeBWorK/ContentGenerator/Problem.pm +++ lib/WeBWorK/ContentGenerator/Problem.pm @@ -644,27 +644,27 @@ return $self->{pg}->{head_text} if $self->{pg}->{head_text}; } -# sub options { -# my ($self) = @_; -# warn "doing options in Problem"; -# return "" if $self->{invalidProblem}; -# my $sourceFilePathfield = ''; -# if($self->r->param("sourceFilePath")) { -# $sourceFilePathfield = CGI::hidden(-name => "sourceFilePath", -# -value => $self->r->param("sourceFilePath")); -# } -# -# return join("", -# CGI::start_form("POST", $self->{r}->uri), -# $self->hidden_authen_fields, -# $sourceFilePathfield, -# CGI::hr(), -# CGI::start_div({class=>"viewOptions"}), -# $self->viewOptions(), -# CGI::end_div(), -# CGI::end_form() -# ); -# } +sub options { + my ($self) = @_; + #warn "doing options in Problem"; + + # don't show options if we don't have anything to show + return if $self->{invalidSet} or $self->{invalidProblem}; + return unless $self->{isOpen}; + + my $displayMode = $self->{displayMode}; + my %can = %{ $self->{can} }; + + my @options_to_show = "displayMode"; + push @options_to_show, "showOldAnswers" if $can{showOldAnswers}; + push @options_to_show, "showHints" if $can{showHints}; + push @options_to_show, "showSolutions" if $can{showSolutions}; + + return $self->optionsMacro( + options_to_show => \@options_to_show, + extra_params => ["editMode", "sourceFilePath"], + ); +} sub siblings { my ($self) = @_; Index: ProblemSet.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/ProblemSet.pm,v retrieving revision 1.64 retrieving revision 1.65 diff -Llib/WeBWorK/ContentGenerator/ProblemSet.pm -Llib/WeBWorK/ContentGenerator/ProblemSet.pm -u -r1.64 -r1.65 --- lib/WeBWorK/ContentGenerator/ProblemSet.pm +++ lib/WeBWorK/ContentGenerator/ProblemSet.pm @@ -105,11 +105,18 @@ my $problemSetsPage = $urlpath->parent; my @links = ("Homework Sets" , $r->location . $problemSetsPage->path, "navUp"); - my $tail = "&displayMode=".$self->{displayMode}."&showOldAnswers=".$self->{will}->{showOldAnswers}; + # CRAP ALERT: this line relies on the hacky options() implementation in ContentGenerator. + # we need to find a better way to do this -- long range dependencies like this are dangerous! + #my $tail = "&displayMode=".$self->{displayMode}."&showOldAnswers=".$self->{will}->{showOldAnswers}; + # here is a hack to get some functionality back, but I don't even think it's that important to + # have this, since there are SO MANY PLACES where we lose the displayMode, etc. + # (oh boy, do we need a session table in the database!) + my $displayMode = $r->param("displayMode") || ""; + my $showOldAnswers = $r->param("showOldAnswers") || ""; + my $tail = "&displayMode=$displayMode&showOldAnswers=$showOldAnswers"; return $self->navMacro($args, $tail, @links); } - sub siblings { my ($self) = @_; my $r = $self->r; @@ -195,7 +202,7 @@ my $psvn = $set->psvn(); my $screenSetHeader = $set->set_header || $ce->{webworkFiles}->{screenSnippets}->{setHeader}; - my $displayMode = $ce->{pg}->{options}->{displayMode}; + my $displayMode = $r->param("displayMode") || $ce->{pg}->{options}->{displayMode}; if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile") { $screenSetHeader = "$screenSetHeader.$userID.tmp"; @@ -250,6 +257,8 @@ return ""; } +sub options { shift->optionsMacro } + sub body { my ($self) = @_; my $r = $self->r; |