Annotation of loncom/homework/edit.pm, revision 1.6
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.6 ! albertel 39: sub get_insert_list2 {
! 40: my ($token) = @_;
! 41: my $result='';
! 42: if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
! 43: my @tagnums= @{ $Apache::lonxml::insertlist{"$token->[1].which"} };
! 44: foreach my $tagnum (@tagnums) {
! 45: $result.='<option value="'.$tagnum.'">'.$Apache::lonxml::insertlist{"$tag.description"}."</option>\n";
! 46: }
! 47: if ($result) { $result='<option selected="on"></option>'.$result; }
! 48: }
! 49: return $result;
! 50: }
! 51:
1.5 albertel 52: sub get_insert_list {
53: my ($token) = @_;
54: my $result='';
55: if ($Apache::lonxml::insertlist{"$token->[1].which"}) {
56: my @tags= @{ $Apache::lonxml::insertlist{"$token->[1].which"} };
57: foreach my $tag (@tags) {
58: $result.='<option value="'.$tag.'">'.$Apache::lonxml::insertlist{"$tag.description"}."</option>\n";
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:
! 80: sub handle_insert2 {
! 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: $result.="\n<$newtag>\n</$newtag>";
! 88: } else {
! 89: {
! 90: no strict 'refs';
! 91: $result.=&$func;
1.5 albertel 92: }
93: }
94: return $result;
95: }
96:
97: sub handle_insert {
98: if (!$ENV{"form.insert_$Apache::lonxml::curdepth"}) { return ''; }
99: my $result;
100: my $newtag = $ENV{"form.insert_$Apache::lonxml::curdepth"};
101: my $func=$Apache::lonxml::insertlist{"$newtag.function"};
102: if ($func eq 'default') {
103: $result.="\n<$newtag>\n</$newtag>";
104: } else {
105: {
106: no strict 'refs';
107: $result.=&$func;
108: }
1.4 albertel 109: }
1.1 albertel 110: return $result;
111: }
112:
1.2 albertel 113: sub editfield {
1.5 albertel 114: my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.2 albertel 115:
116: my $count=0;
117: my $maxlength=-1;
118: map { $count++;
119: if (length($_) > $maxlength) { $maxlength = length ($_); }
120: } split ("\n", $data);
121: if ($maxlength > 80) { $maxlength = 80; }
1.5 albertel 122: if ($maxlength < $minwidth) { $maxlength = $minwidth; }
123: if ( $count < $minheight) { $count = $minheight; }
124: if ($description) {
125: $description="<br />".$description;
1.2 albertel 126: }
127: return "$description<br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
128: # return "<br />\n<$tag><br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br />\n</$tag><br />\n";
129: }
130:
131: sub modifiedfield {
132: my ($token) = @_;
1.3 albertel 133: my $result;
134: # foreach my $envkey (sort keys %ENV) {
135: # &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
136: # }
137: # &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
138: # &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
139: $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
140: if (defined $token) {
141: if (defined $token->[4]) {
142: $result=$token->[4].$result;
143: } else {
144: $result=$result.$token->[2];
145: }
1.2 albertel 146: }
1.3 albertel 147: return $result;
1.5 albertel 148: }
149:
150: sub insert_startouttext {
151: return "\n<startouttext />\n<endouttext />";
1.2 albertel 152: }
153:
1.1 albertel 154: 1;
155: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>