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

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.9     ! albertel   10:   my ($target,$token,$description) = @_;
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)));
1.9     ! albertel   16:     if (!$description) { $description="<$tag>"; }
        !            17:     $result.="<table bgcolor=\"$color\" width=\"100%\" border=\"2\"><tr><td>$description</td>
1.8       albertel   18: <td>Delete:".
                     19:   &deletelist($target,$token)
                     20:   ."</td>
1.4       albertel   21: <td>".
1.8       albertel   22:   &insertlist($target,$token).
1.4       albertel   23:     "</td>
1.1       albertel   24: </tr><tr><td colspan=\"3\">\n";
1.4       albertel   25:   }
1.1       albertel   26:   return $result;
                     27: }
                     28: 
                     29: sub tag_end {
1.9     ! albertel   30:   my ($target,$token,$description) = @_;
1.1       albertel   31:   my $result='';
1.4       albertel   32:   if ($target eq 'edit') {
                     33:     my $tag=$token->[1];
1.9     ! albertel   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";
1.4       albertel   40:   }
                     41:   return $result;
                     42: }
1.1       albertel   43: 
1.8       albertel   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: 
1.7       albertel   54: sub get_insert_list {
1.6       albertel   55:   my ($token) = @_;
                     56:   my $result='';
1.7       albertel   57:   my @tagnums= ();
                     58:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
1.6       albertel   59:   if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
1.7       albertel   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"} });
1.6       albertel   67:     }
                     68:   }
1.7       albertel   69:   if (@tagnums) {
                     70:     foreach my $tagnum (@tagnums) {
                     71:       $result.='<option value="'.$tagnum.'">'.$Apache::lonxml::insertlist{"$tagnum.description"}."</option>\n";
1.5       albertel   72:     }
                     73:     if ($result) { $result='<option selected="on"></option>'.$result; }
                     74:   }
                     75:   return $result;
                     76: }
                     77: 
1.4       albertel   78: sub insertlist {
1.8       albertel   79:   my ($target,$token) = @_;
1.4       albertel   80:   my $result;
                     81:   if ($target eq 'edit') {
1.5       albertel   82:     my $optionlist= &get_insert_list($token);
                     83:     if ($optionlist) {
                     84:       $result = "Insert:
1.4       albertel   85: <select name=\"insert_$Apache::lonxml::curdepth\">
1.5       albertel   86: $optionlist
1.4       albertel   87: </select>"
1.6       albertel   88:     }
                     89:   }
                     90:   return $result;
                     91: }
                     92: 
1.7       albertel   93: sub handle_insert {
1.6       albertel   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"};
1.7       albertel  100:     my $namespace;
                    101:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.6       albertel  102:     $result.="\n<$newtag>\n</$newtag>";
                    103:   } else {
                    104:     {
                    105:       no strict 'refs';
1.7       albertel  106:       $result.=&$func();
1.5       albertel  107:     }
                    108:   }
                    109:   return $result;
                    110: }
                    111: 
1.7       albertel  112: sub insert_optionresponse {
                    113:   return '
                    114: <optionresponse max="10">
                    115:     <foilgroup options="">
                    116:     </foilgroup>
                    117: </optionresponse>';
1.1       albertel  118: }
                    119: 
1.2       albertel  120: sub editfield {
1.5       albertel  121:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.2       albertel  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; }
1.5       albertel  129:   if ($maxlength < $minwidth) { $maxlength = $minwidth; }
                    130:   if ( $count < $minheight) { $count = $minheight; }
                    131:   if ($description) {
1.9     ! albertel  132:     $description="<br />".$description."<br />";
1.2       albertel  133:   }
1.9     ! albertel  134:   return "$description\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
1.2       albertel  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) = @_;
1.3       albertel  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:     }
1.2       albertel  153:   }
1.3       albertel  154:   return $result;
1.5       albertel  155: }
                    156: 
                    157: sub insert_startouttext {
                    158:   return "\n<startouttext />\n<endouttext />";
1.2       albertel  159: }
                    160: 
1.1       albertel  161: 1;
                    162: __END__

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