File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.7: download - view: text, annotated - select for diffs
Tue May 15 20:48:43 2001 UTC (22 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- changes to allow tag namespaces

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

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