[LON-CAPA-cvs] cvs: loncom(version_2_11_donebutton) /homework lonhomework.pm /interface lonmenu.pm
raeburn
raeburn at source.lon-capa.org
Tue May 26 09:25:53 EDT 2015
raeburn Tue May 26 13:25:53 2015 EDT
Modified files: (Branch: version_2_11_donebutton)
/loncom/interface lonmenu.pm
/loncom/homework lonhomework.pm
Log:
"Done" button (allows student to end his/her access to a timed (interval)
quiz.
- Name spacing
- Localization
- Support interval set either for resource or map.
- Move button to left of countdown timer to make it standout a little more.
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.431.2.2 loncom/interface/lonmenu.pm:1.431.2.3
--- loncom/interface/lonmenu.pm:1.431.2.2 Tue Apr 14 21:35:52 2015
+++ loncom/interface/lonmenu.pm Tue May 26 13:25:43 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.431.2.2 2015/04/14 21:35:52 musolffc Exp $
+# $Id: lonmenu.pm,v 1.431.2.3 2015/05/26 13:25:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1536,34 +1536,53 @@
END
}
-# This creates a "done button" for timed events. The confirmation box is a jQuerey
-# dialog widget. Clicking OK will set (done = 'true') which is checked in
+# 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 {
- return <<END;
-
-<form method="post" name="doneButton">
- <input type="hidden" name="done" value=""/>
- <button id="done-confirm-opener" type="button">Done</button>
-</form>
+ 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="done-confirm" title="WARNING!">
- <p></span>You are trying to end this timed event early. Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder. Click "OK" if you are completely finished. Click "Cancel" to continue working.</p>
+<div id="LC_done-confirm" title="$lt{'title'}">
+ <p>$confirm</p>
</div>
-<script>
-\$( "#done-confirm" ).dialog({ autoOpen: false });
-\$( "#done-confirm-opener" ).click(function() {
- \$( "#done-confirm" ).dialog( "open" );
- \$( "#done-confirm" ).dialog({
+<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:320,
+ height: $height,
modal: true,
buttons: {
"OK": function() {
\$( this ).dialog( "close" );
- \$( '[name="done"]' )[0].value = 'true';
- \$( '[name="doneButton"]' )[0].submit();
+ \$( '[name="LC_interval_done"]' )[0].value = 'true';
+ \$( '[name="LCdoneButton"]' )[0].submit();
},
Cancel: function() {
\$( this ).dialog( "close" );
@@ -1571,9 +1590,13 @@
}
})
});
+// ]]>
</script>
END
+ } else {
+ return;
+ }
}
sub utilityfunctions {
@@ -2256,9 +2279,9 @@
($type eq 'Task' && $slothastime)) {
$currdisp = 'inline';
$collapse = '► ';
- $donebutton = &done_button_js();
-
-
+ if ((@interval > 1) && ($hastimeleft)) {
+ $donebutton = &done_button_js($interval[1]);
+ }
} else {
$currdisp = 'none';
$expand = '◄ ';
@@ -2270,7 +2293,7 @@
my $desc = &mt('Countdown to due date/time');
return <<END;
-
+$donebutton
<a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
<span id="ddcountcollapse" class="LC_menubuttons_inline_text">
$collapse
@@ -2279,7 +2302,6 @@
<a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
<span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
<img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
-$donebutton
END
}
}
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.349.2.2 loncom/homework/lonhomework.pm:1.349.2.3
--- loncom/homework/lonhomework.pm:1.349.2.2 Tue Apr 14 21:35:56 2015
+++ loncom/homework/lonhomework.pm Tue May 26 13:25:52 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.349.2.2 2015/04/14 21:35:56 musolffc Exp $
+# $Id: lonhomework.pm,v 1.349.2.3 2015/05/26 13:25:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,6 +51,7 @@
use Apache::drawimage();
use Apache::Constants qw(:common);
use Apache::loncommon();
+use Apace::lonparmset();
use Apache::lonlocal;
use Time::HiRes qw( gettimeofday tv_interval );
use HTML::Entities();
@@ -1331,30 +1332,46 @@
}
}
-# Sets timer to zero for the entire folder containing the current resource for the
-# current user.
+#
+# 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 = shift;
- my $first_access = &Apache::lonnet::get_first_access("map",$symb);
- my $done_time = time() - $first_access;
- &Apache::lonparmset::storeparm_by_symb($symb,"0_interval","2",$done_time,
- "date_interval",$env{'user.name'},$env{'user.domain'},,'',);
+ 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];
- my ($symb) = &Apache::lonnet::whichuser();
-
- # 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 ($env{"form.done"} eq "true") {
- &zero_timer($symb);
- $env{"form.done"} = "";
- }
-
$Apache::lonxml::request=$request;
$Apache::lonxml::debug=$env{'user.debug'};
$env{'request.uri'}=$request->uri;
@@ -1377,8 +1394,10 @@
&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();
&Apache::lonxml::debug('symb is '.$symb);
if ($env{'request.state'} eq "construct") {
if ( -e $file ) {
@@ -1406,6 +1425,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);
More information about the LON-CAPA-cvs
mailing list