--- loncom/homework/edit.pm 2006/07/27 20:47:02 1.103
+++ loncom/homework/edit.pm 2008/10/24 16:22:54 1.116
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.103 2006/07/27 20:47:02 albertel Exp $
+# $Id: edit.pm,v 1.116 2008/10/24 16:22:54 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,7 +61,7 @@ sub tag_start {
if (!$description) { $description="<$tag>"; }
}
$result.= &start_table($token)."
$description |
- Delete".
+ | ".&mt('Delete?').' '.
&deletelist($target,$token)
." |
".
@@ -90,17 +90,10 @@ sub tag_end {
sub start_table {
my ($token)=@_;
- my $tag = $token->[1];
- my $tagnum;
- foreach my $namespace (reverse @Apache::lonxml::namespace) {
- my $testtag=$namespace.'::'.$tag;
- $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
- &Apache::lonxml::debug(" $testtag ");
- if (defined($tagnum)) { last; }
- }
- if (!defined ($tagnum)) {$tagnum=$Apache::lonxml::insertlist{"$tag.num"};}
- my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
- &Apache::lonxml::debug(" $tagnum -- $color");
+ my $tag = &Apache::lonxml::get_tag($token);
+
+ my $color = $Apache::lonxml::insertlist{"$tag.color"};
+ &Apache::lonxml::debug(" $tag -- $color");
if (!defined($color)) {
$color = $Apache::edit::colorlist[$Apache::edit::colordepth];
}
@@ -119,17 +112,23 @@ sub end_table {
my ($tagname,$closingtag);
if (defined($Apache::edit::inserttag[-2])) {
$tagname=$Apache::edit::inserttag[-2];
- } else {$tagname='problem';}
+ } else {
+ if ($Apache::lonhomework::parsing_a_task) {
+ $tagname='Task';
+ } else {
+ $tagname='problem';
+ }
+ }
if (defined($Apache::edit::inserttag[-1])) {
$closingtag=$Apache::edit::inserttag[-1];
}
$result.=&innerinsertlist('edit',$tagname,$closingtag).
" |
";
- pop(@Apache::edit::inserttag);
+ my $last = pop(@Apache::edit::inserttag);
return $result;
}
-sub start_spanning_row { return '';}
+sub start_spanning_row { return ' |
';}
sub start_row { return ' |
'; }
sub end_row { return ' |
'; }
@@ -146,7 +145,7 @@ sub deletelist {
my ($target,$token) = @_;
my $result = "";
return $result;
}
@@ -177,20 +176,21 @@ sub handle_delete {
sub get_insert_list {
my ($tagname) = @_;
my $result='';
- my @tagnums= ();
+ my @tags= ();
#&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
if ($Apache::lonxml::insertlist{"$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
}
foreach my $namespace (@Apache::lonxml::namespace) {
if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
}
}
- if (@tagnums) {
+ if (@tags) {
my %options;
- foreach my $tagnum (@tagnums) {
- my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
+ foreach my $tag (@tags) {
+ my $descrip=$Apache::lonxml::insertlist{"$tag.description"};
+ my $tagnum =$Apache::lonxml::insertlist{"$tag.num"};
$options{$descrip} ="\n";
}
@@ -215,7 +215,7 @@ sub innerinsertlist {
if ($target eq 'edit') {
my $optionlist= &get_insert_list($tagname);
if ($optionlist) {
- $result = "Insert:
+ $result = &mt('Insert:')."
"
@@ -228,40 +228,32 @@ sub innerinsertlist {
sub handle_insert {
if ($env{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
- my $result;
my $tagnum = $env{"form.insert_$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 tag ".$Apache::lonxml::curdepth." ($tagnum) $newtag, func was not defined.");
- }
- }
- return $result;
+ return &do_insert($tagnum);
}
sub handle_insertafter {
my $tagname=shift;
- if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
- { return ''; }
- my $result;
+ if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '') {
+ return '';
+ }
my $tagnum =$env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
- my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
+ return &do_insert($tagnum,1);
+}
+
+sub do_insert {
+ my ($tagnum,$after) = @_;
+ my $result;
+
+ my $newtag = $Apache::lonxml::insertlist{"$tagnum.tag"};
+ my $func = $Apache::lonxml::insertlist{"$newtag.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>";
+ my $depth = scalar(@Apache::lonxml::depthcounter);
+ $depth -- if ($after);
+ my $inset = "\t"x$depth;
+ $result.="\n$inset<$newtag>\n$inset$newtag>";
} else {
if (defined(&$func)) {
{
@@ -269,8 +261,7 @@ sub handle_insertafter {
$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)");
+ &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined. ($tagnum)");
}
}
return $result;
@@ -333,6 +324,56 @@ sub insert_customresponse_answer {
';
}
+sub insert_customhint {
+ return '
+
+
+
+ ';
+}
+
+sub insert_customhint_answer {
+ return '
+
+
+';
+}
+
+sub insert_mathresponse {
+ return '
+
+
+
+
+
+
+
+
+';
+}
+
+sub insert_mathresponse_answer {
+ return '
+
+
+';
+}
+
+sub insert_mathhint {
+ return '
+
+
+
+ ';
+}
+
+sub insert_mathhint_answer {
+ return '
+
+
+';
+}
+
sub insert_stringresponse {
return '
@@ -536,7 +577,8 @@ sub element_change_detection {
}
sub submit_ask_anyway {
- return ' onclick="still_ask=true;" ';
+ my ($extra_action) = @_;
+ return ' onclick="still_ask=true;'.$extra_action.'" ';
}
sub textarea_sizes {
@@ -556,7 +598,7 @@ sub textarea_sizes {
sub editline {
my ($tag,$data,$description,$size)=@_;
$data=&HTML::Entities::encode($data,'<>&"');
- if ($description) { $description="
".$description."
"; }
+ if ($description) { $description=$description."
"; }
my $change_code = &element_change_detection();
my $result = <<"END";
$description
@@ -578,11 +620,15 @@ sub editfield {
if ($cols > 80) { $cols = 80; }
if ($cols < $minwidth ) { $cols = $minwidth; }
if ($rows < $minheight) { $rows = $minheight; }
- if ($description) { $description="
".$description."
"; }
+ if ($description) { $description=$description."
"; }
if ($usehtmlarea) {
&Apache::lonhtmlcommon::add_htmlareafields('homework_edit_'.
$Apache::lonxml::curdepth);
}
+ # remove typesetting whitespace from between data and the end tag
+ # to make the edit look prettier
+ $data =~ s/\n?[ \t]*$//;
+
return $description."\n".'