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

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.3       albertel   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>
1.4       albertel   23: <td>".
                     24:   &insertlist($token,$target).
                     25:     "</td>
1.1       albertel   26: </tr><tr><td colspan=\"3\">\n";
1.4       albertel   27:   }
1.1       albertel   28:   return $result;
                     29: }
                     30: 
                     31: sub tag_end {
1.5       albertel   32:   my ($target,$token) = @_;
1.1       albertel   33:   my $result='';
1.4       albertel   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: }
1.1       albertel   40: 
1.7     ! albertel   41: sub get_insert_list {
1.6       albertel   42:   my ($token) = @_;
                     43:   my $result='';
1.7     ! albertel   44:   my @tagnums= ();
        !            45:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
1.6       albertel   46:   if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
1.7     ! albertel   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"} });
1.6       albertel   54:     }
                     55:   }
1.7     ! albertel   56:   if (@tagnums) {
        !            57:     foreach my $tagnum (@tagnums) {
        !            58:       $result.='<option value="'.$tagnum.'">'.$Apache::lonxml::insertlist{"$tagnum.description"}."</option>\n";
1.5       albertel   59:     }
                     60:     if ($result) { $result='<option selected="on"></option>'.$result; }
                     61:   }
                     62:   return $result;
                     63: }
                     64: 
1.4       albertel   65: sub insertlist {
                     66:   my ($token,$target) = @_;
                     67:   my $result;
                     68:   if ($target eq 'edit') {
1.5       albertel   69:     my $optionlist= &get_insert_list($token);
                     70:     if ($optionlist) {
                     71:       $result = "Insert:
1.4       albertel   72: <select name=\"insert_$Apache::lonxml::curdepth\">
1.5       albertel   73: $optionlist
1.4       albertel   74: </select>"
1.6       albertel   75:     }
                     76:   }
                     77:   return $result;
                     78: }
                     79: 
1.7     ! albertel   80: sub handle_insert {
1.6       albertel   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"};
1.7     ! albertel   87:     my $namespace;
        !            88:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.6       albertel   89:     $result.="\n<$newtag>\n</$newtag>";
                     90:   } else {
                     91:     {
                     92:       no strict 'refs';
1.7     ! albertel   93:       $result.=&$func();
1.5       albertel   94:     }
                     95:   }
                     96:   return $result;
                     97: }
                     98: 
1.7     ! albertel   99: sub insert_optionresponse {
        !           100:   return '
        !           101: <optionresponse max="10">
        !           102:     <foilgroup options="">
        !           103:     </foilgroup>
        !           104: </optionresponse>';
1.1       albertel  105: }
                    106: 
1.2       albertel  107: sub editfield {
1.5       albertel  108:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.2       albertel  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; }
1.5       albertel  116:   if ($maxlength < $minwidth) { $maxlength = $minwidth; }
                    117:   if ( $count < $minheight) { $count = $minheight; }
                    118:   if ($description) {
                    119:     $description="<br />".$description;
1.2       albertel  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) = @_;
1.3       albertel  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:     }
1.2       albertel  140:   }
1.3       albertel  141:   return $result;
1.5       albertel  142: }
                    143: 
                    144: sub insert_startouttext {
                    145:   return "\n<startouttext />\n<endouttext />";
1.2       albertel  146: }
                    147: 
1.1       albertel  148: 1;
                    149: __END__

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