File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.8: download - view: text, annotated - select for diffs
Thu May 31 22:37:56 2001 UTC (22 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- cleaning things up to use get_param
- modularising the delete tag code for it to be useful

    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: #    my $color = sprintf("#%06lx",(hex("ffffff")) >> scalar(split(/_/,$Apache::lonxml::curdepth)));
   15:     my $color = sprintf("#%02lxffff",33* scalar(split(/_/,$Apache::lonxml::curdepth)));
   16:     $result.="<table bgcolor=\"$color\" width=\"100%\" border=\"2\"><tr><td>&lt;$tag&gt;</td>
   17: <td>Delete:".
   18:   &deletelist($target,$token)
   19:   ."</td>
   20: <td>".
   21:   &insertlist($target,$token).
   22:     "</td>
   23: </tr><tr><td colspan=\"3\">\n";
   24:   }
   25:   return $result;
   26: }
   27: 
   28: sub tag_end {
   29:   my ($target,$token) = @_;
   30:   my $result='';
   31:   if ($target eq 'edit') {
   32:     my $tag=$token->[1];
   33:     $result.="</td></tr><tr><td>&lt;/$tag&gt;</td></tr></table>\n";
   34:   }
   35:   return $result;
   36: }
   37: 
   38: sub deletelist {
   39:   my ($target,$token) = @_;
   40:   my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
   41: <option>Nothing</option>
   42: <option>Tag</option>
   43: <option>Subtags</option>
   44: </select>";
   45:   return $result;
   46: }
   47: 
   48: sub get_insert_list {
   49:   my ($token) = @_;
   50:   my $result='';
   51:   my @tagnums= ();
   52:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
   53:   if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
   54:     &Apache::lonxml::debug("Adding1 $token->[1].which");
   55:     push (@tagnums, @{ $Apache::lonxml::insertlist{"$token->[1].which"} });
   56:   }
   57:   foreach my $namespace (@Apache::lonxml::namespace) {
   58:     if ($Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"}) {
   59:       &Apache::lonxml::debug("Adding2 $namespace".'::'."$token->[1].which");
   60:       push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"} });
   61:     }
   62:   }
   63:   if (@tagnums) {
   64:     foreach my $tagnum (@tagnums) {
   65:       $result.='<option value="'.$tagnum.'">'.$Apache::lonxml::insertlist{"$tagnum.description"}."</option>\n";
   66:     }
   67:     if ($result) { $result='<option selected="on"></option>'.$result; }
   68:   }
   69:   return $result;
   70: }
   71: 
   72: sub insertlist {
   73:   my ($target,$token) = @_;
   74:   my $result;
   75:   if ($target eq 'edit') {
   76:     my $optionlist= &get_insert_list($token);
   77:     if ($optionlist) {
   78:       $result = "Insert:
   79: <select name=\"insert_$Apache::lonxml::curdepth\">
   80: $optionlist
   81: </select>"
   82:     }
   83:   }
   84:   return $result;
   85: }
   86: 
   87: sub handle_insert {
   88:   if (!$ENV{"form.insert_$Apache::lonxml::curdepth"}) { return ''; }
   89:   my $result;
   90:   my $tagnum = $ENV{"form.insert_$Apache::lonxml::curdepth"};
   91:   my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
   92:   if ($func eq 'default') {
   93:     my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
   94:     my $namespace;
   95:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
   96:     $result.="\n<$newtag>\n</$newtag>";
   97:   } else {
   98:     {
   99:       no strict 'refs';
  100:       $result.=&$func();
  101:     }
  102:   }
  103:   return $result;
  104: }
  105: 
  106: sub insert_optionresponse {
  107:   return '
  108: <optionresponse max="10">
  109:     <foilgroup options="">
  110:     </foilgroup>
  111: </optionresponse>';
  112: }
  113: 
  114: sub editfield {
  115:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
  116:   
  117:   my $count=0;
  118:   my $maxlength=-1;
  119:   map { $count++;
  120: 	if (length($_) > $maxlength) { $maxlength = length ($_); }
  121:       } split ("\n", $data);
  122:   if ($maxlength > 80) { $maxlength = 80; }
  123:   if ($maxlength < $minwidth) { $maxlength = $minwidth; }
  124:   if ( $count < $minheight) { $count = $minheight; }
  125:   if ($description) {
  126:     $description="<br />".$description;
  127:   }
  128:   return "$description<br />\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
  129: #  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";
  130: }
  131: 
  132: sub modifiedfield {
  133:   my ($token) = @_;
  134:   my $result;
  135: #  foreach my $envkey (sort keys %ENV) {
  136: #    &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
  137: #  }
  138: #  &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
  139: #  &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
  140:   $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
  141:   if (defined $token) {
  142:     if (defined $token->[4]) {
  143:       $result=$token->[4].$result;
  144:     } else {
  145:       $result=$result.$token->[2];
  146:     }
  147:   }
  148:   return $result;
  149: }
  150: 
  151: sub insert_startouttext {
  152:   return "\n<startouttext />\n<endouttext />";
  153: }
  154: 
  155: 1;
  156: __END__

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