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

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 18 Feb 2007 02:03:19 -0000


albertel		Sat Feb 17 21:03:19 2007 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - make the answergroup edit mode work.
  - (Need to still do somethign about old mode and new mode...)
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.207 loncom/homework/caparesponse/caparesponse.pm:1.208
--- loncom/homework/caparesponse/caparesponse.pm:1.207	Thu Jan 25 16:02:25 2007
+++ loncom/homework/caparesponse/caparesponse.pm	Sat Feb 17 21:03:18 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.207 2007/01/25 21:02:25 albertel Exp $
+# $Id: caparesponse.pm,v 1.208 2007/02/18 02:03:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,19 +61,63 @@
     if (!defined($type)) { $type = 'ordered' };
     $answer{$cur_name}= { 'type' => $type,
 			  'answers' => [] };
+    if ($target eq 'edit') {
+  	$result.=&Apache::edit::tag_start($target,$token);
+	$result.=&Apache::edit::text_arg('Name:','name',$token);
+	$result.=&Apache::edit::select_arg('Type:','type',
+					   [['ordered',  'Ordered'  ],
+					    ['unordered','Unordered'],],
+					   $token);
+	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+	my $constructtag = &Apache::edit::get_new_args($token,$parstack,
+						       $safeeval,'name',
+						       'type');
+	if ($constructtag) {
+	    $result = &Apache::edit::rebuild_tag($token);
+	    $result.= &Apache::edit::handle_insert();
+	}
+    }
     return $result;
 }
 
 sub end_answer {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
+    if ($target eq 'edit') {
+	$result .= &Apache::edit::tag_end();
+    }
+
     undef($cur_name);
     return $result;
 }
 
+sub insert_answer {
+    return '
+        <answer>
+            <value></value>
+        </answer>';
+}
+
 sub start_answergroup {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
+    if ($target eq 'edit') {
+  	$result.=&Apache::edit::tag_start($target,$token);
+	$result.=&Apache::edit::select_arg('Type:','type',
+					   [['ordered',  'Ordered'  ],
+					    ['unordered','Unordered'],],
+					   $token);
+	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+	my $constructtag = &Apache::edit::get_new_args($token,$parstack,
+						       $safeeval,'name',
+						       'type');
+	if ($constructtag) {
+	    $result = &Apache::edit::rebuild_tag($token);
+	    $result.= &Apache::edit::handle_insert();
+	}
+    }
     return $result;
 }
 
@@ -88,10 +132,21 @@
 			    $target,$token,$tagstack,$parstack,$parser,
 			    $safeeval,-2);
 	}
+    } elsif ($target eq 'edit') {
+	$result .= &Apache::edit::tag_end();
     }
     return $result;
 }
 
+sub insert_answergroup {
+    return '
+    <answergroup>
+        <answer>
+            <value></value>
+        </answer>
+    </answergroup>';
+}
+
 sub start_value {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
@@ -104,6 +159,13 @@
 	
 	push(@{ $answer{$cur_name}{'answers'} },[$bodytext]);
 	
+    } elsif ($target eq 'edit') {
+  	$result.=&Apache::edit::tag_start($target,$token);
+	my $bodytext = &Apache::lonxml::get_all_text("/value",$parser,$style);
+	$result.=&Apache::edit::editline($token->[1],$bodytext,undef,40).
+	    &Apache::edit::end_row();
+    } elsif ($target eq 'modified') {
+	$result=$token->[4].&Apache::edit::modifiedfield('/value',$parser);
     }
     return $result;
 }
@@ -111,9 +173,17 @@
 sub end_value {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
+    if ($target eq 'edit') {
+	$result = &Apache::edit::end_table();
+    }
     return $result;
 }
 
+sub insert_value {
+    return '
+            <value></value>';
+}
+
 sub start_vector {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
@@ -126,6 +196,13 @@
 	    @values = split(',',$values[0]);
 	}
 	push(@{ $answer{$cur_name}{'answers'} },\@values);
+    } elsif ($target eq 'edit') {
+  	$result.=&Apache::edit::tag_start($target,$token);
+	my $bodytext = &Apache::lonxml::get_all_text("/vector",$parser,$style);
+	$result.=&Apache::edit::editline($token->[1],$bodytext,undef,40).
+	    &Apache::edit::end_row();
+    } elsif ($target eq 'modified') {
+	$result=$token->[4].&Apache::edit::modifiedfield('/vector',$parser);
     }
     return $result;
 }
@@ -133,9 +210,17 @@
 sub end_vector {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
+    if ($target eq 'edit') {
+	$result = &Apache::edit::end_table();
+    }
     return $result;
 }
 
+sub insert_vector {
+    return '
+            <value></value>';
+}
+
 sub start_array {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
@@ -173,6 +258,7 @@
     &Apache::lonxml::register('Apache::caparesponse',
 			      ('answer','answergroup','value','array','unit',
 			       'vector'));
+    push(@Apache::lonxml::namespace,'caparesponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);
     my $result;
     undef(%answer);
@@ -392,6 +478,12 @@
 
 sub end_numericalresponse {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    &Apache::lonxml::deregister('Apache::caparesponse',
+			      ('answer','answergroup','value','array','unit',
+			       'vector'));
+    pop(@Apache::lonxml::namespace);
+
     my $increment=1;
     my $result = '';
     if (!$Apache::lonxml::default_homework_loaded) {