--- loncom/homework/chemresponse.pm 2006/05/30 12:45:36 1.66 +++ loncom/homework/chemresponse.pm 2007/04/18 00:48:06 1.73 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.66 2006/05/30 12:45:36 www Exp $ +# $Id: chemresponse.pm,v 1.73 2007/04/18 00:48:06 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -110,14 +110,15 @@ function substituent(r) {document.applet CHEMJS my $start_page = - &Apache::loncommon::start_page('Molecule Editor',$js, + &Apache::loncommon::start_page('Molecule Editor',undef, {'only_body' => 1, + 'js_ready' => 1, 'bgcolor' => '#FFFFFF',}); - my $end_page = - &Apache::loncommon::end_page(); - + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + my $body=<
@@ -155,17 +156,26 @@ $insert_answer -$end_page CHEMPAGE - $body=&HTML::Entities::encode($body,'<>&"'); - $body=~s/\n/ /g; + $body=&Apache::loncommon::js_ready($body); my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); my $display=&mt('Draw Molecule'); if (defined($shown_text)) { $display=&mt($shown_text); } + my $function = + 'LONCAPA_draw_molecule_'.&Apache::lonhtmlcommon::get_uniq_name(); my $result=< + + CHEMINPUT return $result; } @@ -235,7 +245,9 @@ sub start_organicresponse { $result .='
'; $result .=&Apache::edit::text_arg('Correct Answer:','answer', $token,40); - $result .=&Apache::edit::hidden_arg('jmeanswer',$token); + $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, $safeeval); $result .=&separate_jme_window( @@ -315,6 +327,10 @@ 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') { @@ -324,6 +340,14 @@ sub end_organicresponse { 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; @@ -413,7 +437,7 @@ sub edit_reaction_button { {'frameset' => 1, 'js_ready' => 1, 'add_entries' => { - 'rows' => "30%", + 'rows' => "30%,*", 'border' => "0",}},); my $end_page = &Apache::loncommon::end_page({'frameset' => 1, @@ -425,6 +449,7 @@ sub edit_reaction_button { editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes'); editor.$docopen; editor.document.writeln('$start_page $end_page'); + editor.document.close(); } // --> @@ -454,7 +479,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); @@ -529,6 +554,9 @@ 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') { @@ -538,6 +566,12 @@ sub end_reactionresponse { 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 = '';