Annotation of loncom/homework/edit.pm, revision 1.5
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];
14: $result.="<table width=\"100%\" border=\"2\"><tr><td><$tag></td>
1.3 albertel 15: <td>Delete:
16: <select name=\"delete_$Apache::lonxml::curdepth\">
17: <option>Nothing</option>
18: <option>Tag</option>
19: <option>Subtags</option>
20: </select></td>
1.4 albertel 21: <td>".
22: &insertlist($token,$target).
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.5 ! albertel 30: my ($target,$token) = @_;
1.1 albertel 31: my $result='';
1.4 albertel 32: if ($target eq 'edit') {
33: my $tag=$token->[1];
34: $result.="</td></tr><tr><td></$tag></td></tr></table>\n";
35: }
36: return $result;
37: }
1.1 albertel 38:
1.5 ! albertel 39: sub get_insert_list {
! 40: my ($token) = @_;
! 41: my $result='';
! 42: if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
! 43: my @tags= @{ $Apache::lonxml::insertlist{"$token->[1].which"} };
! 44: foreach my $tag (@tags) {
! 45: $result.='<option value="'.$tag.'">'.$Apache::lonxml::insertlist{"$tag.description"}."</option>\n";
! 46: }
! 47: if ($result) { $result='<option selected="on"></option>'.$result; }
! 48: }
! 49: return $result;
! 50: }
! 51:
1.4 albertel 52: sub insertlist {
53: my ($token,$target) = @_;
54: my $result;
55: if ($target eq 'edit') {
1.5 ! albertel 56: my $optionlist= &get_insert_list($token);
! 57: if ($optionlist) {
! 58: $result = "Insert:
1.4 albertel 59: <select name=\"insert_$Apache::lonxml::curdepth\">
1.5 ! albertel 60: $optionlist
1.4 albertel 61: </select>"
1.5 ! albertel 62: }
! 63: }
! 64: return $result;
! 65: }
! 66:
! 67: sub handle_insert {
! 68: if (!$ENV{"form.insert_$Apache::lonxml::curdepth"}) { return ''; }
! 69: my $result;
! 70: my $newtag = $ENV{"form.insert_$Apache::lonxml::curdepth"};
! 71: my $func=$Apache::lonxml::insertlist{"$newtag.function"};
! 72: if ($func eq 'default') {
! 73: $result.="\n<$newtag>\n</$newtag>";
! 74: } else {
! 75: {
! 76: no strict 'refs';
! 77: $result.=&$func;
! 78: }
1.4 albertel 79: }
1.1 albertel 80: return $result;
81: }
82:
1.2 albertel 83: sub editfield {
1.5 ! albertel 84: my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.2 albertel 85:
86: my $count=0;
87: my $maxlength=-1;
88: map { $count++;
89: if (length($_) > $maxlength) { $maxlength = length ($_); }
90: } split ("\n", $data);
91: if ($maxlength > 80) { $maxlength = 80; }
1.5 ! albertel 92: if ($maxlength < $minwidth) { $maxlength = $minwidth; }
! 93: if ( $count < $minheight) { $count = $minheight; }
! 94: if ($description) {
! 95: $description="<br />".$description;
1.2 albertel 96: }
97: return "$description<br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
98: # return "<br />\n<$tag><br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br />\n</$tag><br />\n";
99: }
100:
101: sub modifiedfield {
102: my ($token) = @_;
1.3 albertel 103: my $result;
104: # foreach my $envkey (sort keys %ENV) {
105: # &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
106: # }
107: # &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
108: # &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
109: $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
110: if (defined $token) {
111: if (defined $token->[4]) {
112: $result=$token->[4].$result;
113: } else {
114: $result=$result.$token->[2];
115: }
1.2 albertel 116: }
1.3 albertel 117: return $result;
1.5 ! albertel 118: }
! 119:
! 120: sub insert_startouttext {
! 121: return "\n<startouttext />\n<endouttext />";
1.2 albertel 122: }
123:
1.1 albertel 124: 1;
125: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>