Annotation of loncom/homework/edit.pm, revision 1.8

1.1       albertel    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 {
1.5       albertel   10:   my ($target,$token) = @_;
1.1       albertel   11:   my $result='';
1.5       albertel   12:   if ($target eq "edit") {
1.4       albertel   13:     my $tag=$token->[1];
1.7       albertel   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>
1.8     ! albertel   17: <td>Delete:".
        !            18:   &deletelist($target,$token)
        !            19:   ."</td>
1.4       albertel   20: <td>".
1.8     ! albertel   21:   &insertlist($target,$token).
1.4       albertel   22:     "</td>
1.1       albertel   23: </tr><tr><td colspan=\"3\">\n";
1.4       albertel   24:   }
1.1       albertel   25:   return $result;
                     26: }
                     27: 
                     28: sub tag_end {
1.5       albertel   29:   my ($target,$token) = @_;
1.1       albertel   30:   my $result='';
1.4       albertel   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: }
1.1       albertel   37: 
1.8     ! albertel   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: 
1.7       albertel   48: sub get_insert_list {
1.6       albertel   49:   my ($token) = @_;
                     50:   my $result='';
1.7       albertel   51:   my @tagnums= ();
                     52:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
1.6       albertel   53:   if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
1.7       albertel   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"} });
1.6       albertel   61:     }
                     62:   }
1.7       albertel   63:   if (@tagnums) {
                     64:     foreach my $tagnum (@tagnums) {
                     65:       $result.='<option value="'.$tagnum.'">'.$Apache::lonxml::insertlist{"$tagnum.description"}."</option>\n";
1.5       albertel   66:     }
                     67:     if ($result) { $result='<option selected="on"></option>'.$result; }
                     68:   }
                     69:   return $result;
                     70: }
                     71: 
1.4       albertel   72: sub insertlist {
1.8     ! albertel   73:   my ($target,$token) = @_;
1.4       albertel   74:   my $result;
                     75:   if ($target eq 'edit') {
1.5       albertel   76:     my $optionlist= &get_insert_list($token);
                     77:     if ($optionlist) {
                     78:       $result = "Insert:
1.4       albertel   79: <select name=\"insert_$Apache::lonxml::curdepth\">
1.5       albertel   80: $optionlist
1.4       albertel   81: </select>"
1.6       albertel   82:     }
                     83:   }
                     84:   return $result;
                     85: }
                     86: 
1.7       albertel   87: sub handle_insert {
1.6       albertel   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"};
1.7       albertel   94:     my $namespace;
                     95:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.6       albertel   96:     $result.="\n<$newtag>\n</$newtag>";
                     97:   } else {
                     98:     {
                     99:       no strict 'refs';
1.7       albertel  100:       $result.=&$func();
1.5       albertel  101:     }
                    102:   }
                    103:   return $result;
                    104: }
                    105: 
1.7       albertel  106: sub insert_optionresponse {
                    107:   return '
                    108: <optionresponse max="10">
                    109:     <foilgroup options="">
                    110:     </foilgroup>
                    111: </optionresponse>';
1.1       albertel  112: }
                    113: 
1.2       albertel  114: sub editfield {
1.5       albertel  115:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.2       albertel  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; }
1.5       albertel  123:   if ($maxlength < $minwidth) { $maxlength = $minwidth; }
                    124:   if ( $count < $minheight) { $count = $minheight; }
                    125:   if ($description) {
                    126:     $description="<br />".$description;
1.2       albertel  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) = @_;
1.3       albertel  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:     }
1.2       albertel  147:   }
1.3       albertel  148:   return $result;
1.5       albertel  149: }
                    150: 
                    151: sub insert_startouttext {
                    152:   return "\n<startouttext />\n<endouttext />";
1.2       albertel  153: }
                    154: 
1.1       albertel  155: 1;
                    156: __END__

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