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

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 24 Feb 2007 01:44:14 -0000


albertel		Fri Feb 23 20:44:14 2007 EDT

  Modified files:              
    /loncom/homework	inputtags.pm lonhomework.pm response.pm 
                    	structuretags.pm 
  Log:
  - BUG#5203, trying to be smarter about when the user presses enter (should now correctly submit the correct field)
  
  
  
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.213 loncom/homework/inputtags.pm:1.214
--- loncom/homework/inputtags.pm:1.213	Wed Feb 21 19:21:47 2007
+++ loncom/homework/inputtags.pm	Fri Feb 23 20:44:14 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.213 2007/02/22 00:21:47 banghart Exp $
+# $Id: inputtags.pm,v 1.214 2007/02/24 01:44:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -292,7 +292,9 @@
 	    my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
 	    my $maxlength;
 	    if ($size eq '') { $size=20; } else {
-		if ($size < 20) { $maxlength=$size; }
+		if ($size < 20) {
+		    $maxlength = ' maxlength="'.$size.'"';
+		}
 	    }
 	    my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
 	    &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse));
@@ -320,8 +322,8 @@
 		if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
 		    $name = "none";
 		}
-		$result.= '<input type="text" '.$readonly.' name="'.$name.'" value="'.
-		    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
+		$result.= '<input onkeydown="javascript:setSubmittedPart(\''.$partid.'\');" type="text" '.$readonly.' name="'.$name.'" value="'.
+		    $oldresponse.'" size="'.$size.'"'.$maxlength.' />';
 	    }
 	    if ($Apache::lonhomework::type eq 'exam'
 		&& &needs_exam_box($tagstack)) {
@@ -1065,7 +1067,7 @@
 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
 	if ( $showbutton ) { 
 	    if ($target ne 'tex') {
-		$button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
+		$button = '<input onsubmit="javascript:setSubmittedPart(\''.$id.'\')" type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
 	    }
 	}
 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.263 loncom/homework/lonhomework.pm:1.264
--- loncom/homework/lonhomework.pm:1.263	Wed Dec 13 17:48:07 2006
+++ loncom/homework/lonhomework.pm	Fri Feb 23 20:44:14 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.263 2006/12/13 22:48:07 albertel Exp $
+# $Id: lonhomework.pm,v 1.264 2007/02/24 01:44:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -96,7 +96,6 @@
 	    return ('grade','webgrade');
 	}
 	if ( defined($env{'form.submitted'}) &&
-	     ( !defined($env{'form.resetdata'})) &&
 	     ( !defined($env{'form.newrandomization'}))) {
 	    return ('grade', 'web');
 	} else {
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.158 loncom/homework/response.pm:1.159
--- loncom/homework/response.pm:1.158	Mon Dec 18 16:37:47 2006
+++ loncom/homework/response.pm	Fri Feb 23 20:44:14 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.158 2006/12/18 21:37:47 www Exp $
+# $Id: response.pm,v 1.159 2007/02/24 01:44:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1026,7 +1026,13 @@
     if ($who eq 'scantron') { return 0; }
     # if the Submit Answer button for this particular part was pressed
     my $partid=$Apache::inputtags::part;
-    if (defined($env{'form.submit_'.$partid})) { return 1; }
+    if ($env{'form.submitted'} eq "part_$partid") {
+	return 1;
+    }
+    if ($env{'form.submitted'} eq "yes"
+	&& defined($env{'form.submit_'.$partid})) {
+	return 1;
+    }
     # Submit All button on a .page was pressed
     if (defined($env{'form.all_submit'})) { return 1; }
     # otherwise no submission occured
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.373 loncom/homework/structuretags.pm:1.374
--- loncom/homework/structuretags.pm:1.373	Thu Feb 22 20:04:05 2007
+++ loncom/homework/structuretags.pm	Fri Feb 23 20:44:14 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.373 2007/02/23 01:04:05 albertel Exp $
+# $Id: structuretags.pm,v 1.374 2007/02/24 01:44:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -88,6 +88,14 @@
 					   $parstack,$parser,$safeeval);
     }
 
+    $extra_head.= '
+<script type="text/javascript">
+function setSubmittedPart (part) {
+   this.document.lonhomework.submitted.value="part_"+part;
+}
+</script>
+';
+
     my %body_args;
     if (defined($found{'html'})) {
 	$body_args{'skip_phases'}{'head'}=1;
@@ -213,7 +221,8 @@
 	    }
 	    $env{'form.rndseed'}=$rndseed;
 	}
-	if ($env{'form.resetdata'} eq &mt('New Problem Variation') ||
+	if ( ($env{'form.resetdata'} eq &mt('New Problem Variation')
+	      && $env{'form.submitted'} eq 'yes')  ||
 	    $env{'form.newrandomization'} eq &mt('New Randomization')) {
 	    srand(time);
 	    $rndseed=int(rand(2100000000));
@@ -358,7 +367,8 @@
 	
 	my $namespace = $symb || $env{'request.uri'};
 	if ($env{'form.resetdata'} eq &mt('Reset Submissions') ||
-	    $env{'form.resetdata'} eq &mt('New Problem Variation') ||
+	    ($env{'form.resetdata'} eq &mt('New Problem Variation')
+	     && $env{'form.submitted'} eq 'yes') ||
 	    $env{'form.newrandomization'} eq &mt('New Randomization')) {
 	    &Apache::lonnet::tmpreset($namespace,'',$domain,$name);
 	    &Apache::lonxml::debug("Attempt reset");