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 ($target,$token) = @_;
11: my $result='';
12: if ($target eq "edit") {
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 ($target,$token) = @_;
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 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:
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:
65: sub insertlist {
66: my ($token,$target) = @_;
67: my $result;
68: if ($target eq 'edit') {
69: my $optionlist= &get_insert_list($token);
70: if ($optionlist) {
71: $result = "Insert:
72: <select name=\"insert_$Apache::lonxml::curdepth\">
73: $optionlist
74: </select>"
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;
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: }
109: }
110: return $result;
111: }
112:
113: sub editfield {
114: my ($tag,$data,$description,$minwidth,$minheight)=@_;
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; }
122: if ($maxlength < $minwidth) { $maxlength = $minwidth; }
123: if ( $count < $minheight) { $count = $minheight; }
124: if ($description) {
125: $description="<br />".$description;
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) = @_;
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: }
146: }
147: return $result;
148: }
149:
150: sub insert_startouttext {
151: return "\n<startouttext />\n<endouttext />";
152: }
153:
154: 1;
155: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>