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 {
10: my ($token,$target) = @_;
11: my $result='';
12: if ($target eq "web") {
13: my $tag=$token->[1];
14: $result.="<table width=\"100%\" border=\"2\"><tr><td><$tag></td>
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>
21: <td>".
22: &insertlist($token,$target).
23: "</td>
24: </tr><tr><td colspan=\"3\">\n";
25: }
26: return $result;
27: }
28:
29: sub tag_end {
30: my ($token,$target) = @_;
31: my $result='';
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: }
38:
39: sub insertlist {
40: my ($token,$target) = @_;
41: my $result;
42: if ($target eq 'edit') {
43: $result = "Insert:
44: <select name=\"insert_$Apache::lonxml::curdepth\">
45: <option>Nothing</option>
46: <option>Text Block</option>
47: <option>Script Block</option>
48: </select>"
49: }
50: return $result;
51: }
52:
53: sub editfield {
54: my ($tag,$data,$description)=@_;
55:
56: my $count=0;
57: my $maxlength=-1;
58: map { $count++;
59: if (length($_) > $maxlength) { $maxlength = length ($_); }
60: } split ("\n", $data);
61: if ($maxlength > 80) { $maxlength = 80; }
62: if ($description) {
63: $description="<br />".$description;
64: }
65: return "$description<br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea>\n";
66: # return "<br />\n<$tag><br />\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br />\n</$tag><br />\n";
67: }
68:
69: sub modifiedfield {
70: my ($token) = @_;
71: my $result;
72: # foreach my $envkey (sort keys %ENV) {
73: # &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
74: # }
75: # &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
76: # &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
77: $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
78: if (defined $token) {
79: if (defined $token->[4]) {
80: $result=$token->[4].$result;
81: } else {
82: $result=$result.$token->[2];
83: }
84: }
85: return $result;
86: }
87:
88: 1;
89: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>