[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm /interface lonmenu.pm

musolffc musolffc at source.lon-capa.org
Tue Jun 16 23:57:15 EDT 2015


musolffc		Wed Jun 17 03:57:15 2015 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm 
    /loncom/interface	lonmenu.pm 
  Log:
  Adding "done button" feature for timed exams from branch version_2_11_donebutton
  
  
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.353 loncom/homework/lonhomework.pm:1.354
--- loncom/homework/lonhomework.pm:1.353	Sat May 16 23:29:17 2015
+++ loncom/homework/lonhomework.pm	Wed Jun 17 03:57:01 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.353 2015/05/16 23:29:17 droeschl Exp $
+# $Id: lonhomework.pm,v 1.354 2015/06/17 03:57:01 musolffc Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,6 +51,7 @@
 use Apache::drawimage();
 use Apache::Constants qw(:common);
 use Apache::loncommon();
+use Apache::lonparmset();
 use Apache::lonlocal;
 use Time::HiRes qw( gettimeofday tv_interval );
 use HTML::Entities();
@@ -1346,10 +1347,46 @@
     }
 }
 
+#
+# Sets interval for current user so time left will be zero, either for the entire folder 
+# containing the current resource, or just the resource, depending on value of first item
+# in interval array retrieved from EXT("resource.0.interval");
+#
+sub zero_timer {
+    my ($symb) = @_;
+    my ($hastimeleft,$first_access,$now);
+    my @interval=&Apache::lonnet::EXT("resource.0.interval");
+    if (@interval > 1) {
+        if ($interval[1] eq 'course') {
+            return;
+        } else {
+            my $now = time;
+            my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
+            if ($first_access > 0) {
+                if ($first_access+$interval[0] > $now) {
+                    my $done_time = $now - $first_access;
+                    my $snum = 1;
+                    if ($interval[1] eq 'map') {
+                        $snum = 2;
+                    }
+                    my $result = 
+                        &Apache::lonparmset::storeparm_by_symb_inner($symb,'0_interval',
+                                                                     $snum,$done_time,
+                                                                     'date_interval',
+                                                                     $env{'user.name'},
+                                                                     $env{'user.domain'});
+                    return $result;
+                }
+            }
+        }
+    }
+    return;
+}
 
 sub handler {
     #my $t0 = [&gettimeofday()];
     my $request=$_[0];
+
     $Apache::lonxml::request=$request;
     $Apache::lonxml::debug=$env{'user.debug'};
     $env{'request.uri'}=$request->uri;
@@ -1372,6 +1409,7 @@
 	&unset_permissions();
 	return OK;
     }
+
     &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade");
     &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
     my ($symb) = &Apache::lonnet::whichuser();
@@ -1402,6 +1440,12 @@
 	    &newproblem($request);
 	}
     } else {
+        # Set the event timer to zero if the "done button" was clicked.  The button is
+        # part of the doneButton form created in lonmenu.pm
+        if ($symb && $env{'form.LC_interval_done'} eq 'true') {  
+            &zero_timer($symb);
+            undef($env{'form.LC_interval_done'});
+        }
 	# just render the page normally outside of construction space
 	&Apache::lonxml::debug("not construct");
 	&renderpage($request,$file);
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.434 loncom/interface/lonmenu.pm:1.435
--- loncom/interface/lonmenu.pm:1.434	Thu May 28 03:14:25 2015
+++ loncom/interface/lonmenu.pm	Wed Jun 17 03:57:15 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.434 2015/05/28 03:14:25 raeburn Exp $
+# $Id: lonmenu.pm,v 1.435 2015/06/17 03:57:15 musolffc Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1543,6 +1543,69 @@
 END
 }
 
+# This creates a "done button" for timed events.  The confirmation box is a jQuery
+# dialog widget.  Clicking OK will set (LC_interval_done = 'true') which is checked in 
+# lonhomework.pm.
+sub done_button_js {
+    my ($type,$height) = @_;
+    if ($height !~ /^\d+$/) {
+        $height = 320;
+    }
+    my %lt = &Apache::lonlocal::texthash(
+                 title    => 'WARNING!',
+                 button   => 'Done',
+                 preamble => 'You are trying to end this timed event early.',
+                 map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
+                 resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
+                 ok       => 'Click "OK" if you are completely finished.',
+                 cancel   => 'Click "Cancel" to continue working.',
+    );
+    my $confirm;
+    if (($type eq 'map') || ($type eq 'resource')) {
+        $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'};
+    }
+    if ($confirm) {
+        return <<END;
+
+<form method="post" name="LCdoneButton" action="">
+    <input type="hidden" name="LC_interval_done" value="" />
+    <button id="LC_done-confirm-opener" type="button">$lt{'button'}</button>
+</form>
+
+<div id="LC_done-confirm" title="$lt{'title'}">
+    <p>$confirm</p>
+</div>
+
+<script type="text/javascript">
+// <![CDATA[
+\$( "#LC_done-confirm" ).dialog({ autoOpen: false });
+\$( "#LC_done-confirm-opener" ).click(function() {
+    \$( "#LC_done-confirm" ).dialog( "open" );
+    \$( "#LC_done-confirm" ).dialog({
+      resizable: false,
+      height: $height,
+      modal: true,
+      buttons: {
+        "OK": function() {
+            \$( this ).dialog( "close" );
+            \$( '[name="LC_interval_done"]' )[0].value = 'true';
+            \$( '[name="LCdoneButton"]' )[0].submit();
+        },
+        Cancel: function() {
+          \$( this ).dialog( "close" );
+        }
+      }    
+    })
+});
+// ]]>
+</script>
+
+END
+    } else {
+        return;
+    }
+}
+
 sub utilityfunctions {
     my ($httphost) = @_;
     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
@@ -2217,11 +2280,14 @@
         if (($duedate && $duedate > time) ||
             (!$duedate && $hastimeleft) ||
             ($slot_name ne '' && $slothastime)) {
-            my ($collapse,$expand,$alttxt,$title,$currdisp);
+            my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
             if ((@interval > 1 && $hastimeleft) ||
                 ($type eq 'Task' && $slothastime)) {
                 $currdisp = 'inline';
                 $collapse = '► ';
+                if ((@interval > 1) && ($hastimeleft)) {
+                    $donebutton = &done_button_js($interval[1]);
+                }
             } else {
                 $currdisp = 'none';
                 $expand = '◄ ';
@@ -2231,8 +2297,9 @@
                 $title = $alttxt.' ';
             }
             my $desc = &mt('Countdown to due date/time');
-            return <<END;
 
+            return <<END;
+$donebutton
 <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 $collapse




More information about the LON-CAPA-cvs mailing list