[LON-CAPA-cvs] cvs: loncom /homework edit.pm structuretags.pm /xml lonxml.pm

www lon-capa-cvs@mail.lon-capa.org
Sun, 03 Nov 2002 19:16:20 -0000


www		Sun Nov  3 14:16:20 2002 EDT

  Modified files:              
    /loncom/homework	edit.pm structuretags.pm 
    /loncom/xml	lonxml.pm 
  Log:
  In "colorful" problem editor, being able to insert tags into the middle,
  rather than only on top.
  
  Insert fields are produced by the end_table routine in Apache::edit for 
  target "edit". 
  
  They are labelled "insert_after_(current tag)_(current depth)". The 
  "(current tag)" was necessary because nested ending tags had the same value
  of Apache::lonxml::curdepth.
  
  New routine handle_insertafter is called in "modified" target.
  
  Needed a hack for <endouttext /> in structuretags.pm for target "modified".
  
  Appears to work just fine in several test situations, but needs more testing.
  
  
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.37 loncom/homework/edit.pm:1.38
--- loncom/homework/edit.pm:1.37	Fri Oct 25 15:02:38 2002
+++ loncom/homework/edit.pm	Sun Nov  3 14:16:19 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.37 2002/10/25 19:02:38 albertel Exp $
+# $Id: edit.pm,v 1.38 2002/11/03 19:16:19 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,9 +39,11 @@
 @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
 # depth of nesting of edit
 $Apache::edit::colordepth=0;
+@Apache::edit::inserttag=();
 
 sub initialize_edit {
   $Apache::edit::colordepth=0;
+  @Apache::edit::inserttag=();
 }
 
 sub tag_start {
@@ -96,13 +98,22 @@
     $color = $Apache::edit::colorlist[$Apache::edit::colordepth];
   }
   $Apache::edit::colordepth++;
-  my $result="<table bgcolor=\"$color\" width=\"100%\" border=\"5\">";
+  push(@Apache::edit::inserttag,$token->[1]);
+  my $result="<p align=\"right\"><table bgcolor=\"$color\" width=\"95%\" border=\"2\">";
   return $result;
 }
 
 sub end_table {
   $Apache::edit::colordepth--;
-  my $result="</table>";
+  my $result="</table></p>";
+  $result.=
+	"<p><table width=\"100%\"><tr><td>".
+        &innerinsertlist('edit',
+ (defined($Apache::edit::inserttag[-2])?$Apache::edit::inserttag[-2]:'problem')
+,
+ (defined($Apache::edit::inserttag[-1])?$Apache::edit::inserttag[-1]:'')).
+        "</td></tr></table></p>";
+  pop(@Apache::edit::inserttag);
   return $result;
 }
 
@@ -152,16 +163,16 @@
 }
 
 sub get_insert_list {
-  my ($token) = @_;
+  my ($tagname) = @_;
   my $result='';
   my @tagnums= ();
   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
-  if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
-    push (@tagnums, @{ $Apache::lonxml::insertlist{"$token->[1].which"} });
+  if ($Apache::lonxml::insertlist{"$tagname.which"}) {
+    push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
   }
   foreach my $namespace (@Apache::lonxml::namespace) {
-    if ($Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"}) {
-      push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"} });
+    if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
+      push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
     }
   }
   if (@tagnums) {
@@ -178,12 +189,21 @@
 
 sub insertlist {
   my ($target,$token) = @_;
+  return &innerinsertlist($target,$token->[1]);
+}
+
+sub innerinsertlist {
+  my ($target,$tagname,$closingtag) = @_;
   my $result;
+  my $after='';
+  if ($closingtag) {
+     $after='_after_'.$closingtag; 
+  }
   if ($target eq 'edit') {
-    my $optionlist= &get_insert_list($token);
+    my $optionlist= &get_insert_list($tagname);
     if ($optionlist) {
       $result = "Insert:
-<select name=\"insert_$Apache::lonxml::curdepth\">
+<select name=\"insert$after\_$Apache::lonxml::curdepth\">
 $optionlist
 </select>"
     } else {
@@ -212,6 +232,32 @@
     } else {
       my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
       &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined.");
+    }
+  }
+  return $result;
+}
+
+sub handle_insertafter {
+  my $tagname=shift;
+  if ($ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
+     { return ''; }
+  my $result;
+  my $tagnum =$ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
+  my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
+  if ($func eq 'default') {
+    my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
+    my $namespace;
+    if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
+    $result.="\n<$newtag>\n</$newtag>";
+  } else {
+    if (defined(&$func)) {
+      {
+	no strict 'refs';
+	$result.=&$func();
+      }
+    } else {
+      my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
+      &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
     }
   }
   return $result;
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.129 loncom/homework/structuretags.pm:1.130
--- loncom/homework/structuretags.pm:1.129	Mon Oct 28 09:47:22 2002
+++ loncom/homework/structuretags.pm	Sun Nov  3 14:16:19 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.129 2002/10/28 14:47:22 sakharuk Exp $
+# $Id: structuretags.pm,v 1.130 2002/11/03 19:16:19 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -141,7 +141,7 @@
        <input type="submit" name="problemmode" value="EditXML" />
        <input type="submit" name="Undo" value="undo" /> <hr />
        <input type="submit" name="submit" value="Submit Changes" />
-       <input type="submit" name="submit" value="Submit Changes and View" /><br />
+       <input type="submit" name="submit" value="Submit Changes and View" /><br /><p>&nbsp;</p>
       ';
 }
 
@@ -758,7 +758,9 @@
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   my $result='';
   if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
-  if ($target eq "modified") { $result='<endouttext />'; }
+  if ($target eq "modified") { 
+     $result='<endouttext />'.
+     &Apache::edit::handle_insertafter('startouttext'); }
   return $result;
 }
 sub end_endouttext {
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.209 loncom/xml/lonxml.pm:1.210
--- loncom/xml/lonxml.pm:1.209	Mon Oct 28 09:00:18 2002
+++ loncom/xml/lonxml.pm	Sun Nov  3 14:16:20 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.209 2002/10/28 14:00:18 www Exp $
+# $Id: lonxml.pm,v 1.210 2002/11/03 19:16:20 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -841,6 +841,9 @@
 	  if ($token->[0] eq 'S') {
 	    $currentstring = $token->[4];
 	    $currentstring.=&Apache::edit::handle_insert();
+	  } elsif ($token->[0] eq 'E') {
+	    $currentstring = $token->[2];
+            $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
 	  } else {
 	    $currentstring = $token->[2];
 	  }