--- loncom/homework/edit.pm 2002/03/22 14:45:11 1.31
+++ loncom/homework/edit.pm 2003/06/10 18:39:08 1.55
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.31 2002/03/22 14:45:11 matthew Exp $
+# $Id: edit.pm,v 1.55 2003/06/10 18:39:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,16 +31,22 @@
package Apache::edit;
use strict;
-use Apache::lonnet;
+use Apache::lonnet();
+use HTML::Entities();
# Global Vars
# default list of colors to use in editing
@Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
# depth of nesting of edit
$Apache::edit::colordepth=0;
+@Apache::edit::inserttag=();
+# image-type responses: active background image and curdepth at definition
+$Apache::edit::bgimgsrc='';
+$Apache::edit::bgimgsrccurdepth='';
sub initialize_edit {
$Apache::edit::colordepth=0;
+ @Apache::edit::inserttag=();
}
sub tag_start {
@@ -69,13 +75,7 @@ sub tag_end {
my ($target,$token,$description) = @_;
my $result='';
if ($target eq 'edit') {
- my $tag=$token->[1];
- if (!defined($description)) {
- $result.="
</$tag> | | ";
- } else {
- if ($description ne '') { $result.="
$description | | "; }
- }
- $result.="
".&end_table()."\n";
+ $result.="".&end_table()."\n";
}
return $result;
}
@@ -95,18 +95,32 @@ sub start_table {
$color = $Apache::edit::colorlist[$Apache::edit::colordepth];
}
$Apache::edit::colordepth++;
- my $result="";
+ push(@Apache::edit::inserttag,$token->[1]);
+ my $result='';
+ $result.='
';
return $result;
}
sub end_table {
$Apache::edit::colordepth--;
- my $result="
";
+ my $result='
';
+ $result.="";
+
+ my ($tagname,$closingtag);
+ if (defined($Apache::edit::inserttag[-2])) {
+ $tagname=$Apache::edit::inserttag[-2];
+ } else {$tagname='problem';}
+ if (defined($Apache::edit::inserttag[-1])) {
+ $closingtag=$Apache::edit::inserttag[-1];
+ }
+ $result.=&innerinsertlist('edit',$tagname,$closingtag).
+ " |
";
+ pop(@Apache::edit::inserttag);
return $result;
}
-sub start_spanning_row { return '';}
-sub start_row { return ' |
'; }
+sub start_spanning_row { return ' |
';}
+sub start_row { return ' |
'; }
sub end_row { return ' |
'; }
sub movebuttons {
@@ -142,7 +156,7 @@ sub handle_delete {
}
if (!$result) {
my $endtag='/'.$token->[1];
- my $bodytext=&Apache::lonxml::get_all_text($endtag,$$parser[$#$parser]);
+ my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
$$parser['-1']->get_token();
&Apache::lonxml::debug("Deleting :$bodytext: for $token->[1]");
&Apache::lonxml::end_tag($tagstack,$parstack,$token);
@@ -151,22 +165,25 @@ sub handle_delete {
}
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) {
+ my %options;
foreach my $tagnum (@tagnums) {
- $result.='\n";
+ my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
+ $options{$descrip} ="\n";
}
+ foreach my $option (sort(keys(%options))) { $result.=$options{$option}; }
if ($result) { $result=''.$result; }
}
return $result;
@@ -174,12 +191,21 @@ sub get_insert_list {
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:
-