--- loncom/homework/chemresponse.pm 2003/10/16 21:52:27 1.17 +++ loncom/homework/chemresponse.pm 2004/02/13 15:12:57 1.29 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.17 2003/10/16 21:52:27 albertel Exp $ +# $Id: chemresponse.pm,v 1.29 2004/02/13 15:12:57 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,6 +40,7 @@ sub seperate_jme_window { my $smilesection; if (defined($smile_input)) { $smilesection=<<SMILESECTION; + smiles = document.applets.JME.smiles(); opener.document.lonhomework.$smile_input.value = smiles; SMILESECTION } @@ -58,12 +59,12 @@ JMESECTION <title>Molecule Editor</title> <script language="JavaScript"> function submitSmiles() { - smiles = document.applets.JME.smiles(); - if (smiles == "") { + jmeFile = document.applets.JME.jmeFile(); + if (jmeFile == "") { alert("Nothing to submit"); } else { - $smilesection $jmesection + $smilesection window.close(); } } @@ -74,7 +75,7 @@ function openHelpWindow() { </head> <body bgcolor="#ffffff"> <center> -<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="97%" height="78%"> +<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390"> You have to enable Java and JavaScript on your machine. $molecule <param name="options" value="$options" /> @@ -105,6 +106,7 @@ sub start_organicresponse { my $partid = $Apache::inputtags::part; my $id = &Apache::response::start_response($parstack,$safeeval); if ($target eq 'meta') { + $result=&Apache::response::meta_package_write('organicresponse'); } elsif ($target eq 'web') { my $molecule; if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) { @@ -142,13 +144,11 @@ sub start_organicresponse { $jmeanswer,$options); $result .='</nobr><br />'; $result .=&Apache::edit::checked_arg('Options:','options', - [ ['autoez','Auto E,Z sterochemistry'], - ['multipart','MultiPart Structures'], - ['hydrogens','Show Hydrogens'], + [ ['autoez','Auto E,Z stereochemistry'], + ['multipart','Multipart Structures'], ['nostereo','No stereochemistry'], ['reaction','Is a reaction'], - ['number','Able to number atoms'], - ['border','Draw a border'] ], + ['number','Able to number atoms'] ], ,$token); $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { @@ -209,8 +209,10 @@ sub start_organicstructure { my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval); my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval); my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval); - my $id=time.'_'.int(rand(1000)); - $result="<img src='/cgi-bin/convertjme.pl?$id' />"; + my $id=&Apache::loncommon::get_cgi_id(); + $result="<img src='/cgi-bin/convertjme.pl?$id'"; + if ($options =~ /border/) { $result.= ' border="1"'; } + $result.=' />'; &Apache::lonnet::appenv( 'cgi.'.$id.'.JME' => &Apache::lonnet::escape($molecule), 'cgi.'.$id.'.PNG' => 1, @@ -229,12 +231,13 @@ sub start_organicstructure { 'cgi.'.$id.'.WIDTH' => $texwidth ); $id=&Apache::lonnet::escape($id); &Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id"); - $result = '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}'; + if ($options =~ /border/) { $result.= '\fbox{'; } + $result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}'; + if ($options =~ /border/) { $result.= '} '; } } elsif ($target eq 'edit') { $result .=&Apache::edit::tag_start($target,$token); - $result .=&Apache::edit::text_arg('Width:','width',$token,5); - $result .=&Apache::edit::text_arg('Height:','height',$token,5); - $result .=&Apache::edit::text_arg('TeXwidth:','texwidth',$token,5); + $result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5); + $result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5); $result .='<nobr>'; $result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40); my $molecule=&Apache::lonxml::get_param('molecule',$parstack, @@ -250,16 +253,15 @@ sub start_organicstructure { $molecule,$options); $result.="</nobr><br />"; $result .=&Apache::edit::checked_arg('Options:','options', - [ ['hydrogens','Show Hydrogens'], - ['reaction','Is a reaction'], + [ ['reaction','Is a reaction'], ['border','Draw a border'] ], $token); - $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + $result .=&Apache::edit::end_row(); } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'molecule', - 'width','height', - 'texwidth','options'); + 'width','texwidth', + 'options'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } } return $result; @@ -297,6 +299,7 @@ sub start_reactionresponse { my $result; my $id = &Apache::response::start_response($parstack,$safeeval); if ($target eq 'meta') { + $result=&Apache::response::meta_package_write('reactionresponse'); } elsif ($target eq 'web') { my $partid = $Apache::inputtags::part; my $id = $Apache::inputtags::response['-1'];