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

foxr foxr at source.lon-capa.org
Sun Mar 25 10:36:02 EDT 2012


foxr		Sun Mar 25 14:36:02 2012 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  BZ 5891 (and a bit more) add a due date timer at the top of the page next 
  to the breadcrumbs.   Note that under the (possibly bad assumption) of fast
  page load times, the software corrects for time differences between the
  client and server. 
  
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.500 loncom/homework/structuretags.pm:1.501
--- loncom/homework/structuretags.pm:1.500	Tue Dec 27 20:13:22 2011
+++ loncom/homework/structuretags.pm	Sun Mar 25 14:35:58 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.500 2011/12/27 20:13:22 foxr Exp $
+# $Id: structuretags.pm,v 1.501 2012/03/25 14:35:58 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1179,7 +1179,13 @@
 	    my @interval=&Apache::lonnet::EXT("resource.0.interval");
 	    &Apache::lonnet::set_first_access($interval[1]);
 	}
+	my $resource_due =  &Apache::lonhomework::due_date(0, $env{'request.symb'});
+	my $time_left = $resource_due - time();
+	if ($resource_due && ($time_left > 0)) {
+	    $result .= &Apache::lonhtmlcommon::set_due_date($resource_due);
+	}
 
+	    
         ($status,$accessmsg,my $slot_name,my $slot) =
             &Apache::lonhomework::check_slot_access('0','problem');
         push (@Apache::inputtags::status,$status);
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.303 loncom/interface/lonhtmlcommon.pm:1.304
--- loncom/interface/lonhtmlcommon.pm:1.303	Tue Mar 20 13:36:19 2012
+++ loncom/interface/lonhtmlcommon.pm	Sun Mar 25 14:36:01 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.303 2012/03/20 13:36:19 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.304 2012/03/25 14:36:01 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1111,6 +1111,7 @@
     if ($uri !~ m|/$|) { $output=~s|/$||; }
     $output.='</span>';
 
+
     return $output;
 }
 
@@ -1175,6 +1176,8 @@
 <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
 </script>
 <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
+<script type='text/javascript' src='/adm/countdown/js/jquery.countdown.js'></script>
+<link rel="stylesheet" type="text/css" src='/adm/countdown/css/jquery.countdown.css' />
 ENDJQUERY
 	return $s;
 }
@@ -1306,6 +1309,19 @@
                 $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/";
                 $(".colorchooser").jPicker();
 
+                // Only define the countdown if a dueDate variable is defined:
+
+               if (typeof(dueDate) != "undefined") {
+                  $("#duedatecountdown").countdown({until: dueDate, compact: true, 
+                                                  layout: "<b>Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn}</b>",
+                                                  onTick: function (periods) {
+                         if($.countdown.periodsToSeconds(periods) < 60) {
+                             $(this).css("color", "red");   //Highlight last minute.
+                         }
+                      }
+                  });
+               }
+
 	});
 ';
     if ($dragmath_prefix ne '') {
@@ -1383,6 +1399,39 @@
 }
 
 
+##
+#   Set the dueDate variable...note this is done in the timezone
+#   of the browser.
+#
+# @param epoch relative time at which the problem is due.
+#
+# @return the javascript fragment to set the date:
+#
+sub set_due_date {
+    my $dueStamp = shift;
+    my $duems    = $dueStamp * 1000; # Javascript Date object needs ms not seconds.
+
+    my $now = time()*1000;
+
+    # This slightly obscure bit of javascript sets the dueDate variable
+    # to the time in the browser at which the problem was due.  
+    # The code should correct for gross differences between the server
+    # and client's time setting
+
+    my $js = "
+<script type='text/javascript'>
+  //<![CDATA[
+var serverDueDate = $duems;
+var serverTime    = $now;
+var clientTime    = (new Date()).getTime();
+var dueDate       = new Date(serverDueDate + (clientTime - serverTime));
+
+  //]]>
+</script>
+";
+
+}
+
 ############################################################
 ############################################################
 
@@ -1501,9 +1550,12 @@
 
         # last breadcrumb is the first order heading of a page
         # for course breadcrumbs it's just bold
+
         $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
                 $lasttext), {title => $lasttext});
 
+	$links .=   '<li> <span id="duedatecountdown"></span></li>'; 
+
         my $icons = '';
         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
         $bug  = $last->{'bug'}  if (exists($last->{'bug'}));
@@ -1521,6 +1573,7 @@
                                                          $faq,$bug);
         }
         #
+
 		
 
         unless ($CourseBreadcrumbs) {
@@ -1529,12 +1582,14 @@
             $links = &htmltag('ul',  $links, { class => "LC_CourseBreadcrumbs" });
         }
 
+
         if ($component) {
             $links = &htmltag('span', 
                              ( $no_mt ? $component : mt($component) ).
                              ( $icons ? $icons : '' ),
                              { class => 'LC_breadcrumbs_component' } )
-                             .$links;
+                             .$links 
+;
         }
         
         &render_tools(\$links);
@@ -1545,7 +1600,12 @@
         # Return the @Crumbs stack to what we started with
         push(@Crumbs,$last);
         shift(@Crumbs);
+
+
         # Return the breadcrumb's line
+
+    
+
         return "$links";
     }
 




More information about the LON-CAPA-cvs mailing list