--- loncom/homework/chemresponse.pm 2005/01/31 22:00:40 1.45 +++ loncom/homework/chemresponse.pm 2015/03/07 23:04:08 1.95 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.45 2005/01/31 22:00:40 albertel Exp $ +# $Id: chemresponse.pm,v 1.95 2015/03/07 23:04:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,9 +30,13 @@ package Apache::chemresponse; use strict; use Apache::lonxml; use Apache::lonnet; +use Apache::lonlocal; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { - &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse')); + &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); } sub chem_standard_order { @@ -63,28 +67,153 @@ sub chem_standard_order { } sub separate_jme_window { - my ($smile_input,$jme_input,$molecule,$options)=@_; + my ($smile_input,$jme_input,$molecule,$options,$shown_text)=@_; + my $usejsme = 1; + if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) { + if (exists($env{'course.'.$env{'request.course.id'}.'.usejsme'})) { + if ($env{'course.'.$env{'request.course.id'}.'.usejsme'} eq '0') { + $usejsme = 0; + } + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + if ($domdefs{'usejsme'} eq '0') { + $usejsme = 0; + } + } + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + if ($domdefs{'usejsme'} eq '0') { + $usejsme = 0; + } + } + if ($usejsme) { + if ($env{'browser.type'} eq 'mozilla') { + if ($env{'browser.version'} < 4) { + $usejsme = 0; + } + } + } else { + if ($env{'browser.mobile'}) { + $usejsme = 1; + } + } + my $linkstyle = 'display:none'; + my $creditstyle = 'display:inline'; + if ($env{'browser.type'} eq 'explorer') { + if (($env{'browser.os'} eq 'win') && ($env{'browser.version'} < 9)) { + $linkstyle = 'display:inline'; + $creditstyle = 'display:none'; + } + } my $smilesection; if (defined($smile_input)) { + my $smiles; + if ($usejsme) { + $smiles = 'document.JME.smiles()'; + } else { + $smiles = 'document.applets.JME.smiles()'; + } $smilesection=<'; } - my $body=< - -Molecule Editor - +RESIZEJS + $resizejs = &Apache::loncommon::js_ready($resizejs); + $jsme_js = ' +'."\n"; + $js =< +function jsmeOnLoad() { + document.getElementById('JMErefresh').style.display="none"; + document.getElementById('JMEcredits').style.display="inline"; + jsmeApplet = new JSApplet.JSME("jme", "420px", "330px"); + document.JME = jsmeApplet; + $molecule; + document.getElementById('JMEbuttons').style.display="block"; + callResize(); +} + +function submitSmiles() { + jmeFile = document.JME.jmeFile(); + if (jmeFile == "") { + alert("Nothing to submit"); + } else { + $jmesection + $smilesection + window.close(); + } +} +function openHelpWindow() { + window.open("http://peter-ertl.com/jsme/2013_03/help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); +} + + + +CHEMJS + + $viewportjs = &Apache::loncommon::viewport_geometry_js(); + $viewportjs = ''; + + } else { + $buttonstyle = 'display:block'; + $js =< function submitSmiles() { jmeFile = document.applets.JME.jmeFile(); if (jmeFile == "") { @@ -98,33 +227,124 @@ function submitSmiles() { function openHelpWindow() { window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); } +function substituent(r) {document.applets.JME.setSubstituent(r);} - - +CHEMJS + } + + my $start_page = + &Apache::loncommon::start_page('Molecule Editor',$viewportjs, + {'only_body' => 1, + 'js_ready' => 1, + 'bgcolor' => '#FFFFFF',}); + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + my $java_not_enabled=&Apache::lonhtmlcommon::java_not_enabled(); + my %lt = &Apache::lonlocal::texthash( + 'seltext' => 'Select substituent...', + 'close' => 'Close', + 'help' => 'Help', + ); + my $body = " +$jsme_js +$js".' - -You have to enable Java and JavaScript on your machine. + +'; + if ($usejsme) { + $body.= <<"ENDCHEM"; + + +JSME Molecular Editor courtesy of Peter Ertl (Novartis) and Bruno Bienfait + +ENDCHEM + } else { + $body.=< + + + + $lt{'seltext'} + -C(=O)OH + -C(=O)OMe + -OC(=O)Me + -CMe3 + -CF3 + -CCl3 + -NO2 + -SO2-NH2 + -NH-SO2-Me + -NMe2 + -C#N + -C#C-Me + -C#CH + + + + +$java_not_enabled $molecule - -JME Editor courtesy of Peter Ertl, Novartis - - + - +JME Editor courtesy of Peter Ertl, Novartis +CHEMPAGE + } + $body .= < +$insert_answer + - + + + +Display Molecule Editor + - -