--- loncom/homework/chemresponse.pm 2006/07/27 20:34:40 1.69 +++ loncom/homework/chemresponse.pm 2007/10/15 09:47:29 1.75 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.69 2006/07/27 20:34:40 albertel Exp $ +# $Id: chemresponse.pm,v 1.75 2007/10/15 09:47:29 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -245,6 +245,7 @@ sub start_organicresponse { $result .='
'; $result .=&Apache::edit::text_arg('Correct Answer:','answer', $token,40); + $result .='
'; $result .=&Apache::edit::text_arg('JME string of the answer (automatically updated when using the Draw Molecule button):', 'jmeanswer',$token); my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, @@ -326,15 +327,31 @@ sub end_organicresponse { } $result.=&Apache::response::answer_footer('organicresponse'); } + if ($target eq 'web') { + &Apache::response::setup_prior_tries_hash(\&format_prior_answer_organic, + ['molecule']) + } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { - &Apache::lonxml::increment_counter(&Apache::response::repetition()); + &Apache::lonxml::increment_counter(&Apache::response::repetition(), + "$partid.$id"); # part.response + if ($target eq 'analyze') { + &Apache::lonhomework::set_bubble_lines(); + } } &Apache::response::end_response(); return $result; } +sub format_prior_answer_organic { + my ($mode,$answer,$other_data) = @_; + my $result=&mt('Smile representation: "[_1]"',''.$answer.''); + my $jme=$other_data->[0]; + $result.=&jme_img($jme,$answer,400); + return $result; +} + sub start_organicstructure { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; @@ -466,7 +483,7 @@ sub start_reactionresponse { &Apache::lonxml::default_homework_load($safeeval); } @Apache::scripttag::parser_env = @_; - $Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval); + $Apache::inputtags::answertxt{$id}=[&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval)]; } } elsif ($target eq "edit") { $result .=&Apache::edit::tag_start($target,$token); @@ -541,15 +558,24 @@ sub end_reactionresponse { } $result.=&Apache::response::answer_footer('reactionresponse'); } + if ($target eq 'web') { + &Apache::response::setup_prior_tries_hash(\&format_prior_response_reaction); + } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { - &Apache::lonxml::increment_counter(&Apache::response::repetition()); + &Apache::lonxml::increment_counter(&Apache::response::repetition(), "$partid.$id"); } &Apache::response::end_response(); return $result; } +sub format_prior_response_reaction { + my ($mode,$answer) =@_; + return ''. + &HTML::Entities::encode($answer,'"<>&').''; +} + sub start_chem { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $result = '';