[LON-CAPA-cvs] cvs: loncom(BZ4492) /homework radiobuttonresponse.pm

foxr foxr at source.lon-capa.org
Sat Jan 21 15:54:58 EST 2012


foxr		Sat Jan 21 20:54:58 2012 EDT

  Modified files:              (Branch: BZ4492)
    /loncom/homework	radiobuttonresponse.pm 
  Log:
  BZ4492 Complete refactoring of html rendition of radiobuttonresponses.
  
  
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.153.6.1 loncom/homework/radiobuttonresponse.pm:1.153.6.2
--- loncom/homework/radiobuttonresponse.pm:1.153.6.1	Fri Jan 20 11:41:31 2012
+++ loncom/homework/radiobuttonresponse.pm	Sat Jan 21 20:54:57 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.153.6.1 2012/01/20 11:41:31 foxr Exp $
+# $Id: radiobuttonresponse.pm,v 1.153.6.2 2012/01/21 20:54:57 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -769,6 +769,39 @@
     return ( $answer, @whichfalse );
 }
 ##
+# Generate the HTML for a single html foil.
+# @param $part           - The part for which the response is being generated.
+# @param $fieldname      - The basename of the radiobutton field
+# @param $name           - The foilname.
+# @param $last_responses - Reference to a hash that holds the most recent
+#                          responses.
+# @param $value          - radiobutton value.
+# 
+# @return text
+# @retval The generated html.
+#
+sub html_radiobutton {
+    my ($part, $fieldname, $name, $last_responses, $value) = @_;
+
+    my $result='<label>';
+    
+    $result .= '<input type="radio"
+                onchange="javascript:setSubmittedPart(' . "'$part');\""
+		. 'name="HWVAL_' . $fieldname . '"'
+		. "value='$value'";
+
+    if (defined($last_responses->{$name})) {
+	$result .= '  checked="checked" ';
+    }
+    $result .= ' />';
+    $result .= $Apache::response::foilgroup{$name . '.text'};
+    $result .= '</label>';
+
+    return $result;
+
+}
+
+##
 # Display foils in html rendition:
 #
 # @param $whichfoils - Set of foils to display.
@@ -863,48 +896,6 @@
 	$result = &display_foils_html(
 	    $whichfoils, $target, $direction, $part, $solved, 1);
 
-#        if ( $direction eq 'horizontal' ) {
-#            if ( $target ne 'tex' ) {
-#                $result .= '<table><tr>';
-#            }
-#        }
-#        foreach my $name ( @{$whichfoils} ) {
-#            if ( $direction eq 'horizontal' ) {
-#                if ( $target ne 'tex' ) { $result .= '<td>'; }
-#            }
-#            if ( $target ne 'tex' ) {
-#                $result .= "<br />";
-#            }
-#            else {
-#                $result .= '\item \vskip -2 mm  ';
-#            }
-#            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
-#                if ( $target ne 'tex' ) {
-#                    $result .= &mt('Correct:') . '<b>';
-#                }
-#                else {
-#                    $result .= &mt('Correct:') . ' \textbf{';
-#                }
-#            }
-#            else {
-#                $result .= &mt('Incorrect:');
-#            }
-#            if ( $target eq 'web' ) { $result .= "<label>"; }
-#            $result .= $Apache::response::foilgroup{ $name . '.text' };
-#            if ( $target eq 'web' ) { $result .= "</label>"; }
-#            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
-#                if   ( $target ne 'tex' ) { $result .= '</b>'; }
-#                else                      { $result .= '}'; }
-#            }
-#            if ( $direction eq 'horizontal' ) {
-#                if ( $target ne 'tex' ) { $result .= '</td>'; }
-#            }
-#        }
-#        if ( $direction eq 'horizontal' ) {
-#            if ( $target ne 'tex' ) {
-#                $result .= '</tr></table>';
-#            }
-#        }
     }
     else {
         my @alphabet      = ( 'A' .. 'Z' );
@@ -970,27 +961,26 @@
                 $result .= '\item[\textbf{' . $Apache::lonxml::counter . '}.]';
             }
         }
+	my $item_pretext;
+	my $item_posttext;
+	if ( $target ne 'tex' ) {
+	    if ( $direction eq 'horizontal' ) {
+		$item_pretext  = '<td>';
+		$item_posttext = '</td>';
+	    }
+	    else {
+		$item_pretext = '<br/>';
+	    }
+	}
         foreach my $name ( @{$whichfoils} ) {
+
             if ( $target ne 'tex' ) {
-                if ( $direction eq 'horizontal' ) {
-                    $result .= "<td>";
-                }
-                else {
-                    $result .= "<br />";
-                }
-            }
-            if ( $target ne 'tex' ) {
-                $result .= '<label>';
-                $result .= "<input type=\"radio\"
-                            onchange=\"javascript:setSubmittedPart('$part');\"
-                            name=\"HWVAL_$Apache::inputtags::response['-1']\"
-                            value=\"$temp\"";
-                if ( defined( $lastresponse{$name} ) ) {
-                    $result .= ' checked="checked"';
-                }
-                $result .= ' />'
-                  . $Apache::response::foilgroup{ $name . '.text' }
-                  . "</label>";
+		$result .= $item_pretext;
+		$result .= &html_radiobutton(
+		    $part, $Apache::inputtags::response[-1],
+		    $name, $lastresponse, $temp
+		    );
+		$result .= $item_posttext;
             }
             else {
                 if ( $Apache::lonhomework::type eq 'exam' ) {
@@ -1037,19 +1027,21 @@
                     }
                 }
             }
-            if ( $target ne 'tex' && $direction eq 'horizontal' ) {
-                $result .= "</td>";
-            }
+
             $temp++;
         }
         if ( $target ne 'tex' && $direction eq 'horizontal' ) {
             $result .= "</tr></table>";
         }
     }
-    if ( $target ne 'tex' ) {
-        if ( $direction ne 'horizontal' ) { $result .= "<br />"; }
+    if ( $target ne 'tex'
+	 && ( $direction ne 'horizontal' ) 
+	) { 
+	     $result .= "<br />"; 
+    }
+    if ($target eq 'tex') {
+	$result .= '\vskip 0 mm '; 
     }
-    else { $result .= '\vskip 0 mm '; }
     return $result;
 }
 




More information about the LON-CAPA-cvs mailing list