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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 09 Jun 2006 22:31:37 -0000


albertel		Fri Jun  9 18:31:37 2006 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - addign a 'Cancel' to regrading screens that leaves the resource unchanged
  
  
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.162 loncom/homework/bridgetask.pm:1.163
--- loncom/homework/bridgetask.pm:1.162	Tue Jun  6 17:05:56 2006
+++ loncom/homework/bridgetask.pm	Fri Jun  9 18:31:36 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.162 2006/06/06 21:05:56 albertel Exp $
+# $Id: bridgetask.pm,v 1.163 2006/06/09 22:31:36 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -373,18 +373,36 @@
     return $file_list;
 }
 
+sub grade_mode {
+    if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
+	return 'regrade';
+    }
+    return 'queue_grade';
+}
+
 sub webgrade_standard_info {
     my ($version)=&get_version();
 
     my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
 
-    my %lt=&Apache::lonlocal::texthash('done' => 'Next Item',
-				       'stop' => 'Quit Grading',
-				       'fail' => 'Fail Rest',
-				       );
-				       
+    my %lt=('done'   => 'Next Item',
+	    'stop'   => 'Quit Grading',
+	    'fail'   => 'Fail Rest',
+	    'cancel' => 'Cancel',
+	    );
+    my %lt=&Apache::lonlocal::texthash(%lt);
+
     my $result=<<INFO;
   <div class="LC_GRADING_maincontrols">
+INFO
+
+    if (&grade_mode() eq 'regrade') {
+	$result.=<<INFO;
+    <input type="submit" name="cancel" value="$lt{'cancel'}" />
+INFO
+    }
+
+    $result.=<<INFO;
     <input type="submit" name="next" value="$lt{'done'}" />
     <input type="submit" name="stop" value="$lt{'stop'}" />
     <input type="button" name="fail" value="$lt{'fail'}" 
@@ -455,8 +473,10 @@
     if ($target eq 'web' && $env{'request.state'} eq 'construct') {
 	$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
     }
-    if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
-	$target eq 'tex') {
+    if ($target eq 'web' 
+	|| ($target eq 'grade' && !$env{'form.webgrade'}) 
+	|| $target eq 'answer' 
+	|| $target eq 'tex') {
 	my ($version,$previous)=&get_version();
 	($status,$accessmsg,my $slot_name,$slot) = 
 	    &Apache::lonhomework::check_slot_access('0','Task');
@@ -592,6 +612,8 @@
 		    &mt('Return to resource').'</a></p>';
 		if      ($status_code eq 'stop') {
 		    $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
+		} elsif ($status_code eq 'cancel') {
+		    $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
 		} elsif ($status_code eq 'lock_failed') {
 		    $result.='<b>'.&mt("Failed to lock the requested record.")
 			.'</b>'.$back;
@@ -612,6 +634,8 @@
 		}
 	    }
 	    $webgrade='no';
+	}
+	if (!$todo || $env{'form.cancel'}) {
 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
 	}
 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
@@ -702,6 +726,8 @@
 	if (!$queue) {
 	    $env{'form.queue'} = $queue = 'none';
 	    #not queued so doing either a re or pre grade
+	    #FIXME don't allow pregrade
+	    &Apache::lonxml::debug("not in queue no lock");
 	    return ($gradingkey);
 	}
 
@@ -709,11 +735,13 @@
 	if ($who eq $me) {
 	    #already have the lock
 	    $env{'form.gradingkey'}=&escape($gradingkey);
+	    &Apache::lonxml::debug("already locked");
 	    return ($gradingkey);
 	}
 	
 	if (!defined($who)) {
 	    if (&lock_key($queue,$gradingkey)) {
+		&Apache::lonxml::debug("newly locked");
 		return ($gradingkey);
 	    } else {
 		return (undef,'lock_failed');
@@ -740,6 +768,8 @@
 	    if ($target eq 'webgrade') {
 		if ($env{'form.stop'}) {
 		    return (undef,'stop');
+		} elsif ($env{'form.cancel'}) {
+		    return (undef,'cancel');
 		} elsif ($env{'form.next'}) {
 		    return (undef,'select_user');
 		}
@@ -785,7 +815,8 @@
 
     if ($env{'form.queuemode'} ne 'selected') {
 	# don't get something new from the queue if they hit the stop button
-    	if (!($env{'form.stop'} && $target eq 'webgrade') 
+    	if (!(($env{'form.cancel'} || $env{'form.stop'}) 
+	      && $target eq 'webgrade') 
 	    && !$env{'form.gradingaction'}) {
 	    &Apache::lonxml::debug("Getting anew $queue");
 	    return (&get_from_queue($queue));
@@ -937,7 +968,12 @@
 	} elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
 	    &Apache::structuretags::finalize_storage();
 	}
-	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
+	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
+	    && exists($env{'form.cancel'})) {
+	    &check_queue_unlock($env{'form.queue'});
+	    &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
+	} elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
+		 && !exists($env{'form.cancel'})) {
 	    my $optional_required=
 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
 					   $safeeval);
@@ -1091,6 +1127,7 @@
     my $me=$env{'user.name'}.':'.$env{'user.domain'};
     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
     if  ($who eq $me) {
+	&Apache::lonxml::debug("unlocking my own $who");
 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
     } elsif ($allow_not_me) {
 	&Apache::lonxml::debug("unlocking $who by $me");