File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.9: download - view: text, annotated - select for diffs
Mon Jun 11 16:15:37 2001 UTC (22 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- can control the description using the standard tag start and end interfaces

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

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