File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.5: download - view: text, annotated - select for diffs
Sun May 13 20:01:34 2001 UTC (23 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- able to insert tags now

    1: # The LearningOnline Network with CAPA 
    2: # edit mode helpers
    3: # 3/20 Guy
    4: package Apache::edit; 
    5: 
    6: use strict;
    7: use Apache::lonnet;
    8: 
    9: sub tag_start {
   10:   my ($target,$token) = @_;
   11:   my $result='';
   12:   if ($target eq "edit") {
   13:     my $tag=$token->[1];
   14:     $result.="<table width=\"100%\" border=\"2\"><tr><td>&lt;$tag&gt;</td>
   15: <td>Delete:
   16: <select name=\"delete_$Apache::lonxml::curdepth\">
   17: <option>Nothing</option>
   18: <option>Tag</option>
   19: <option>Subtags</option>
   20: </select></td>
   21: <td>".
   22:   &insertlist($token,$target).
   23:     "</td>
   24: </tr><tr><td colspan=\"3\">\n";
   25:   }
   26:   return $result;
   27: }
   28: 
   29: sub tag_end {
   30:   my ($target,$token) = @_;
   31:   my $result='';
   32:   if ($target eq 'edit') {
   33:     my $tag=$token->[1];
   34:     $result.="</td></tr><tr><td>&lt;/$tag&gt;</td></tr></table>\n";
   35:   }
   36:   return $result;
   37: }
   38: 
   39: sub get_insert_list {
   40:   my ($token) = @_;
   41:   my $result='';
   42:   if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
   43:     my @tags= @{ $Apache::lonxml::insertlist{"$token->[1].which"} };
   44:     foreach my $tag (@tags) {
   45:       $result.='<option value="'.$tag.'">'.$Apache::lonxml::insertlist{"$tag.description"}."</option>\n";
   46:     }
   47:     if ($result) { $result='<option selected="on"></option>'.$result; }
   48:   }
   49:   return $result;
   50: }
   51: 
   52: sub insertlist {
   53:   my ($token,$target) = @_;
   54:   my $result;
   55:   if ($target eq 'edit') {
   56:     my $optionlist= &get_insert_list($token);
   57:     if ($optionlist) {
   58:       $result = "Insert:
   59: <select name=\"insert_$Apache::lonxml::curdepth\">
   60: $optionlist
   61: </select>"
   62:     }
   63:   }
   64:   return $result;
   65: }
   66: 
   67: sub handle_insert {
   68:   if (!$ENV{"form.insert_$Apache::lonxml::curdepth"}) { return ''; }
   69:   my $result;
   70:   my $newtag = $ENV{"form.insert_$Apache::lonxml::curdepth"};
   71:   my $func=$Apache::lonxml::insertlist{"$newtag.function"};
   72:   if ($func eq 'default') {
   73:     $result.="\n<$newtag>\n</$newtag>";
   74:   } else {
   75:     {
   76:       no strict 'refs';
   77:       $result.=&$func;
   78:     }
   79:   }
   80:   return $result;
   81: }
   82: 
   83: sub editfield {
   84:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
   85:   
   86:   my $count=0;
   87:   my $maxlength=-1;
   88:   map { $count++;
   89: 	if (length($_) > $maxlength) { $maxlength = length ($_); }
   90:       } split ("\n", $data);
   91:   if ($maxlength > 80) { $maxlength = 80; }
   92:   if ($maxlength < $minwidth) { $maxlength = $minwidth; }
   93:   if ( $count < $minheight) { $count = $minheight; }
   94:   if ($description) {
   95:     $description="<br />".$description;
   96:   }
   97:   return "$description<br />\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
   98: #  return "<br />\n&lt;$tag&gt;<br />\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br />\n&lt;/$tag&gt;<br />\n";
   99: }
  100: 
  101: sub modifiedfield {
  102:   my ($token) = @_;
  103:   my $result;
  104: #  foreach my $envkey (sort keys %ENV) {
  105: #    &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
  106: #  }
  107: #  &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
  108: #  &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
  109:   $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
  110:   if (defined $token) {
  111:     if (defined $token->[4]) {
  112:       $result=$token->[4].$result;
  113:     } else {
  114:       $result=$result.$token->[2];
  115:     }
  116:   }
  117:   return $result;
  118: }
  119: 
  120: sub insert_startouttext {
  121:   return "\n<startouttext />\n<endouttext />";
  122: }
  123: 
  124: 1;
  125: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>