[LON-CAPA-cvs] cvs: loncom /homework chemresponse.pm /interface courseprefs.pm domainprefs.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Fri Dec 24 06:07:43 EST 2021


raeburn		Fri Dec 24 11:07:43 2021 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm courseprefs.pm 
    /loncom/homework	chemresponse.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Add option to choose inline preview (new) or pop-up (old) for Chemical 
    Reaction response items.  Default is inline preview. Domain setting can
    be overridden in a course.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.397 loncom/interface/domainprefs.pm:1.398
--- loncom/interface/domainprefs.pm:1.397	Fri Dec 24 00:48:30 2021
+++ loncom/interface/domainprefs.pm	Fri Dec 24 11:07:42 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.397 2021/12/24 00:48:30 raeburn Exp $
+# $Id: domainprefs.pm,v 1.398 2021/12/24 11:07:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6775,6 +6775,7 @@
         coursecredits        => 'Credits can be specified for courses',
         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
+        inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
         texengine            => 'Default method to display mathematics',
         postsubmit           => 'Disable submit button/keypress following student submission',
         canclone             => "People who may clone a course (besides course's owner and coordinators)",
@@ -6791,9 +6792,10 @@
                             'canuse_pdfforms' => 'off',
                             'uselcmath'       => 'on',
                             'usejsme'         => 'on',
+                            'inline_chem'     => 'on',
                             'canclone'        => 'none',
                           );
-        @toggles = ('canuse_pdfforms','uselcmath','usejsme');
+        @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
         my $deftex = $Apache::lonnet::deftex;
         if (ref($settings) eq 'HASH') {
             if ($settings->{'texengine'}) {
@@ -20307,9 +20309,10 @@
     my %defaultchecked = (
                            'canuse_pdfforms' => 'off',
                            'uselcmath'       => 'on',
-                           'usejsme'         => 'on'
+                           'usejsme'         => 'on',
+                           'inline_chem'     => 'on',
                          );
-    my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
+    my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
@@ -20519,8 +20522,9 @@
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
-                ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
-                foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
+                ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
+                ($changes{'inline_chem'})) {
+                foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine') {
                     if ($changes{$item}) {
                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                     }
@@ -20589,6 +20593,12 @@
                     } else {
                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
                     }
+                } elsif ($item eq 'inline_chem') {
+                    if ($env{'form.'.$item} eq '1') {
+                        $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
+                    }
                 } elsif ($item eq 'texengine') {
                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.94 loncom/interface/courseprefs.pm:1.95
--- loncom/interface/courseprefs.pm:1.94	Mon Oct 18 22:29:20 2021
+++ loncom/interface/courseprefs.pm	Fri Dec 24 11:07:42 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.94 2021/10/18 22:29:20 raeburn Exp $
+# $Id: courseprefs.pm,v 1.95 2021/12/24 11:07:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -473,7 +473,7 @@
                      help => 'Course_Prefs_Display',
                      ordered => ['default_xml_style','pageseparators',
                                  'disable_receipt_display','texengine',
-                                 'tthoptions','uselcmath','usejsme'],
+                                 'tthoptions','uselcmath','usejsme','inline_chem'],
                       itemtext => {
                           default_xml_style       => 'Default XML style file',
                           pageseparators          => 'Visibly Separate Items on Pages',
@@ -482,6 +482,7 @@
                           tthoptions              => 'Default set of options to pass to tth/m when converting TeX',
                           uselcmath               => 'Student formula entry uses inline preview, not DragMath pop-up',
                           usejsme                 => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
+                          inline_chem             => 'Chemical reaction response uses inline preview, not pop-up',
                                   },
                   },
         'grading' =>
@@ -1852,7 +1853,8 @@
                                         $displayval = &Apache::lonlocal::locallocaltime($displayval);
                                     } elsif ($key eq 'categories') {
                                         $displayval = $env{'form.categories_display'};
-                                    } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') || ($key eq 'uselcmath')) {
+                                    } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
+                                             ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
                                         if ($changes->{$item}{$key} eq '1') {
                                             $displayval = &mt('Yes');
                                         } elsif ($changes->{$item}{$key} eq '0') {
@@ -4671,6 +4673,10 @@
                    text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
                    input => 'radio',
                  },
+         'inline_chem' => {
+                   text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
+                   input => 'radio',
+                 },
     );
     return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
 }
@@ -5551,7 +5557,7 @@
                                                        $settings->{$item},$disabled);
             } elsif ($items->{$item}{input} eq 'radio') {
                 my ($unsetdefault,$valueyes,$valueno);
-                if (($item eq 'usejsme') || ($item eq 'uselcmath')) {
+                if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
                      my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
                      unless ($domdefs{$item} eq '0') {
                          $unsetdefault = 1;
Index: loncom/homework/chemresponse.pm
diff -u loncom/homework/chemresponse.pm:1.100 loncom/homework/chemresponse.pm:1.101
--- loncom/homework/chemresponse.pm:1.100	Wed Apr  7 22:16:03 2021
+++ loncom/homework/chemresponse.pm	Fri Dec 24 11:07:42 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # chemical equation style response
 #
-# $Id: chemresponse.pm,v 1.100 2021/04/07 22:16:03 raeburn Exp $
+# $Id: chemresponse.pm,v 1.101 2021/12/24 11:07:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -630,6 +630,40 @@
     return $result;
 }
 
+sub edit_reaction_button {
+    my ($id,$field,$reaction)=@_;
+    my $id_es=&escape($id);
+    my $field_es=&escape($field);
+    my $reaction_es=&escape($reaction);
+    my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
+    my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
+    my $display=&mt('Edit Answer');
+    my $start_page =
+        &Apache::loncommon::start_page('LON-CAPA Reaction Editor',undef,
+                                       {'frameset'    => 1,
+                                        'js_ready'    => 1,
+                                        'add_entries' => {
+                                            'rows'   => "30%,*",
+                                            'border' => "0",}},);
+    my $end_page =
+        &Apache::loncommon::end_page({'frameset' => 1,
+                                      'js_ready' => 1});
+    my $result=<<EDITREACTION;
+<script type="text/javascript">
+// <!--
+    function create_reaction_window_${id}_${field} () {
+        editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes');
+        editor.$docopen;
+        editor.document.writeln('$start_page <frame src="/adm/reactionresponse/reaction_viewer.html?inhibitmenu=yes" name="viewer" scrolling="no" />  <frame src="/adm/reactionresponse/reaction_editor.html?inhibitmenu=yes&reaction=$reaction_es&id=$id_es&field=$field_es" name="editor" scrolling="no" /> $end_page');
+        editor.document.close();
+    }
+// -->
+</script>
+<a href="javascript:create_reaction_window_${id}_${field}();void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$display' title='$display' /></a>
+EDITREACTION
+    return $result;
+}
+
 sub reaction_preview {
     my ($field, $reaction) = @_;
     
@@ -682,11 +716,20 @@
 						$safeeval);
 	$result .='<span class="LC_nobreak">'.
 	    &Apache::edit::text_arg('Answer:','answer',$token,40);
-	$result .= &reaction_preview(&Apache::edit::html_element_name('answer'), $answer).'</span>';
+        my $inline_chem = &use_inline_chem();
+        if ($inline_chem) {
+	    $result .= &reaction_preview(&Apache::edit::html_element_name('answer'), $answer).'</span>';
+        } else {
+            $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('answer'),$answer).'</span>';
+        }
 	my $initial=&Apache::lonxml::get_param('initial',$parstack,$safeeval);
 	$result.='<span class="LC_nobreak">'.
 	    &Apache::edit::text_arg('Initial Reaction:','initial',$token,40);
-        $result .= &reaction_preview(&Apache::edit::html_element_name('initial'), $initial).'</span>';
+        if ($inline_chem) { 
+            $result .= &reaction_preview(&Apache::edit::html_element_name('initial'), $initial).'</span>';
+        } else {
+            $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('initial'),$initial).'</span>';
+        }
 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
     }  elsif ($target eq 'modified') {
 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -774,12 +817,38 @@
     if  (($target eq 'web') && ($Apache::lonhomework::type ne 'exam') && ($status eq 'CAN_ANSWER')) {
         my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
         if ($reaction eq '') {  $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
-        $result .= &reaction_preview("HWVAL_$id", $reaction);
+        if (&use_inline_chem()) {
+            $result .= &reaction_preview("HWVAL_$id", $reaction);
+        } else {
+            $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
+        }
     }
     &Apache::response::end_response();
     return $result;
 }
 
+sub use_inline_chem {
+    my $inline_chem = 1;
+    if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
+        if (exists($env{'course.'.$env{'request.course.id'}.'.inline_chem'})) {
+            if ($env{'course.'.$env{'request.course.id'}.'.inline_chem'} eq '0') {
+                $inline_chem = 0;
+            }
+        } else {
+            my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+            if ($domdefs{'inline_chem'} eq '0') {
+                $inline_chem = 0;
+            }
+        }
+    } else {
+        my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+        if ($domdefs{'inline_chem'} eq '0') {
+            $inline_chem = 0;
+        }
+    }
+    return $inline_chem;
+}
+
 sub format_prior_response_reaction {
     my ($mode,$answer) =@_;
     return '<span class="LC_prior_reaction">'.
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1475 loncom/lonnet/perl/lonnet.pm:1.1476
--- loncom/lonnet/perl/lonnet.pm:1.1475	Sun Dec 19 02:45:48 2021
+++ loncom/lonnet/perl/lonnet.pm	Fri Dec 24 11:07:43 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1475 2021/12/19 02:45:48 raeburn Exp $
+# $Id: lonnet.pm,v 1.1476 2021/12/24 11:07:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2666,6 +2666,7 @@
     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
         $domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'};
         $domdefaults{'usejsme'} = $domconfig{'coursedefaults'}{'usejsme'};
+        $domdefaults{'inline_chem'} = $domconfig{'coursedefaults'}{'inline_chem'};
         $domdefaults{'uselcmath'} = $domconfig{'coursedefaults'}{'uselcmath'};
         if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
             $domdefaults{'postsubmit'} = $domconfig{'coursedefaults'}{'postsubmit'}{'client'};


More information about the LON-CAPA-cvs mailing list