[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm

raeburn raeburn at source.lon-capa.org
Sat Mar 7 18:13:09 EST 2015


raeburn		Sat Mar  7 23:13:09 2015 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - Bug 6740
    - Course/Community defaults include: (a) a domain configuration to specify 
      disabling Submit button, after student submission (can be overridden by a
      DC for a specific course via "View or modify a course or community"),
      and (b) duration for which button is disabled in client browser.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.530 loncom/homework/structuretags.pm:1.531
--- loncom/homework/structuretags.pm:1.530	Mon Feb 23 10:40:01 2015
+++ loncom/homework/structuretags.pm	Sat Mar  7 23:13:09 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.530 2015/02/23 10:40:01 droeschl Exp $
+# $Id: structuretags.pm,v 1.531 2015/03/07 23:13:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -224,10 +224,55 @@
 }
 
 sub homework_js {
+    my ($postsubmit,$timeout);
+    if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
+        my $crstype;
+        if (&Apache::loncommon::course_type() eq 'Community') {
+            $crstype = 'community';
+        } else {
+            if ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) {
+                $crstype = 'official';
+            } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
+                $crstype = 'textbook';
+            } else {
+                $crstype = 'unofficial';
+            }
+        }
+        $postsubmit = $env{'course.'.$env{'request.course.id'}.'.internal.postsubmit'};
+        if ($postsubmit eq '') {
+            my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+            $postsubmit = $domdefs{'postsubmit'};
+            unless ($postsubmit eq 'off') {
+                $timeout = $domdefs{$crstype.'postsubtimeout'};
+            }
+        } elsif ($postsubmit eq '0') {
+            $postsubmit = 'off';
+        } elsif ($postsubmit eq '1') {
+            $postsubmit = 'on';
+            $timeout = $env{'course.'.$env{'request.course.id'}.'.internal.postsubtimeout'};
+            if ($timeout eq '') {
+                my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+                $timeout = $domdefs{$crstype.'postsubtimeout'};
+            }
+        }
+        if ($timeout eq '') {
+            $timeout = 60;
+        }
+    } else {
+        my %domdefs = &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
+        $postsubmit = $domdefs{'postsubmit'};
+        unless ($postsubmit eq 'off') {
+            $timeout = 60;
+        }
+    }
+    my $jstimeout = 0;
+    if ($timeout) {
+        $jstimeout = 1000 * $timeout;
+    }
     return &Apache::loncommon::resize_textarea_js().
                 &Apache::loncommon::colorfuleditor_js().
            &setmode_javascript().
-	<<'JS';
+	<<"JS";
 <script type="text/javascript">
 // <![CDATA[
 function setSubmittedPart (part,prefix) {
@@ -258,50 +303,70 @@
 
 var submithandled = 0;
 var keypresshandled = 0;
+var postsubmit = '$postsubmit';
 
-$(document).ready(function(){
-
-    $(document).keypress(function(event){
+\$(document).ready(function(){
+  if (postsubmit != 'off') {    
+    \$(document).keypress(function(event){
         var keycode = (event.keyCode ? event.keyCode : event.which);
         if ((keycode == '13') && (keypresshandled == 0)) {
-            if ( $( document.activeElement ).hasClass("LC_textline") ) {
+            if ( \$( document.activeElement ).hasClass("LC_textline") ) {
                 keypresshandled = 1;
-                var idsArray = $( document.activeElement ).attr("id").split(/HWVAL_/);
+                var idsArray = \$( document.activeElement ).attr("id").split(/HWVAL_/);
                 if (idsArray.length) {
                     event.preventDefault();
                     var itemsArray = idsArray[1].split(/_/);
                     var buttonId = idsArray[0]+'submit_'+itemsArray[0];
-                    $("#"+buttonId).trigger("click");
+                    \$("#"+buttonId).trigger("click");
                 }
             }
         }
     });
 
-    $(document).delegate('form :submit', 'click', function( event ) {
-        if ( $( this ).hasClass( "LC_hwk_submit" ) ) {
+    \$(document).delegate('form :submit', 'click', function( event ) {
+        if ( \$( this ).hasClass( "LC_hwk_submit" ) ) {
             var buttonId = this.id;
+            var timeout = $jstimeout;
             if (submithandled == 0) {
                 submithandled = 1;
-                $( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
+                \$( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
                                            "color": "black","padding": "2px"}) ;
-                if (( $(this.form).id == "LC_page" ) && ($('input[name="all_submit"]').length )) {
+                if (( \$(this.form).id == "LC_page" ) && (\$('input[name="all_submit"]').length )) {
                     if (buttonId != "all_submit") {
-                        $( ".LC_status_"+buttonId ).hide();
+                        \$( ".LC_status_"+buttonId ).hide();
                         if (( "#"+buttonId+"_pressed" ).length) {
-                            $( "#"+buttonId+"_pressed" ).val( "1" );
+                            \$( "#"+buttonId+"_pressed" ).val( "1" );
                         }
                     }
                 } else {
-                    $( ".LC_status_"+buttonId ).hide();
+                    \$( ".LC_status_"+buttonId ).hide();
                 }
-                $(this.form).submit();
-                $( ".LC_hwk_submit" ).prop( "disabled", true);
-                $( ".LC_textline" ).prop( "readonly", "readonly");
+                \$(this.form).submit();
+                \$( ".LC_hwk_submit" ).prop( "disabled", true);
+                \$( ".LC_textline" ).prop( "readonly", "readonly");
                 event.preventDefault();
+
+                if (timeout > 0) {
+                    setTimeout(function(){
+                                       \$( "#msg_"+buttonId ).css({"display": "none"});
+                                       if (( \$(this.form).id == "LC_page" ) && (\$('input[name="all_submit"]').length )) {
+                                           if (buttonId != "all_submit") {
+                                               if (( "#"+buttonId+"_pressed" ).length) {
+                                                   \$( "#"+buttonId+"_pressed" ).val( "" );
+                                               }
+                                           }
+                                       }
+                                       \$( ".LC_hwk_submit" ).prop( "disabled", false);
+                                       \$( ".LC_textline" ).prop( "readonly", false);
+                                       submithandled = 0;
+                                       keypresshandled = 0;
+                                     }, timeout);
+                }
                 return true;
             }
         }
     });
+  }
 });
 
 // ]]>




More information about the LON-CAPA-cvs mailing list