Annotation of loncom/homework/edit.pm, revision 1.57.2.1
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # edit mode helpers
1.25 albertel 3: #
1.57.2.1! albertel 4: # $Id: edit.pm,v 1.57 2003/06/30 20:41:35 albertel Exp $
1.25 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28: # 3/20 Guy
1.27 matthew 29: # 01/10/02 Matthew
1.29 matthew 30: # 03/06/02 Matthew
1.1 albertel 31: package Apache::edit;
32:
33: use strict;
1.32 albertel 34: use Apache::lonnet();
35: use HTML::Entities();
1.1 albertel 36:
1.10 albertel 37: # Global Vars
38: # default list of colors to use in editing
39: @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
40: # depth of nesting of edit
41: $Apache::edit::colordepth=0;
1.38 www 42: @Apache::edit::inserttag=();
1.49 www 43: # image-type responses: active background image and curdepth at definition
44: $Apache::edit::bgimgsrc='';
45: $Apache::edit::bgimgsrccurdepth='';
1.10 albertel 46:
47: sub initialize_edit {
48: $Apache::edit::colordepth=0;
1.38 www 49: @Apache::edit::inserttag=();
1.10 albertel 50: }
51:
1.1 albertel 52: sub tag_start {
1.9 albertel 53: my ($target,$token,$description) = @_;
1.1 albertel 54: my $result='';
1.5 albertel 55: if ($target eq "edit") {
1.4 albertel 56: my $tag=$token->[1];
1.22 albertel 57: if (!$description) {
58: $description=&Apache::lonxml::description($token);
59: if (!$description) { $description="<$tag>"; }
60: }
1.10 albertel 61: $result.= &start_table($token)."<tr><td>$description</td>
1.14 albertel 62: <td>Delete".
1.8 albertel 63: &deletelist($target,$token)
64: ."</td>
1.4 albertel 65: <td>".
1.27 matthew 66: &insertlist($target,$token).&end_row().&start_spanning_row();
67: #<td>".
1.22 albertel 68: # &movebuttons($target,$token).
69: # "</tr><tr><td colspan=\"3\">\n";
1.4 albertel 70: }
1.1 albertel 71: return $result;
72: }
73:
74: sub tag_end {
1.9 albertel 75: my ($target,$token,$description) = @_;
1.1 albertel 76: my $result='';
1.4 albertel 77: if ($target eq 'edit') {
1.55 albertel 78: $result.="</td></tr>".&end_table()."\n";
1.4 albertel 79: }
80: return $result;
81: }
1.1 albertel 82:
1.10 albertel 83: sub start_table {
84: my ($token)=@_;
85: my $tag = $token->[1];
86: my $tagnum;
87: foreach my $namespace (reverse @Apache::lonxml::namespace) {
1.23 albertel 88: my $testtag=$namespace.'::'.$tag;
1.10 albertel 89: $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
90: if (defined($tagnum)) { last; }
91: }
92: if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
93: my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
94: if (!defined($color)) {
95: $color = $Apache::edit::colorlist[$Apache::edit::colordepth];
96: }
97: $Apache::edit::colordepth++;
1.38 www 98: push(@Apache::edit::inserttag,$token->[1]);
1.40 albertel 99: my $result='<div align="right">';
1.41 www 100: $result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="5" cellpadding="3">';
1.10 albertel 101: return $result;
102: }
103:
104: sub end_table {
105: $Apache::edit::colordepth--;
1.40 albertel 106: my $result='</table></div>';
1.39 albertel 107: $result.="<table><tr><td>";
108:
109: my ($tagname,$closingtag);
110: if (defined($Apache::edit::inserttag[-2])) {
111: $tagname=$Apache::edit::inserttag[-2];
112: } else {$tagname='problem';}
113: if (defined($Apache::edit::inserttag[-1])) {
114: $closingtag=$Apache::edit::inserttag[-1];
115: }
116: $result.=&innerinsertlist('edit',$tagname,$closingtag).
117: "</td></tr></table>";
1.38 www 118: pop(@Apache::edit::inserttag);
1.10 albertel 119: return $result;
120: }
121:
1.41 www 122: sub start_spanning_row { return '<tr><td colspan="3" bgcolor="#DDDDDD">';}
123: sub start_row { return '<tr><td bgcolor="#DDDDDD">'; }
1.27 matthew 124: sub end_row { return '</td></tr>'; }
125:
1.22 albertel 126: sub movebuttons {
127: my ($target,$token) = @_;
128: my $result='<input type="submit" name="moveup.'.
129: $Apache::lonxml::curdepth.'" value="Move Up" />';
130: $result.='<input type="submit" name="movedown.'.
131: $Apache::lonxml::curdepth.'" value="Move Down" />';
132: return $result;
133: }
134:
1.8 albertel 135: sub deletelist {
136: my ($target,$token) = @_;
137: my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
1.14 albertel 138: <option></option>
139: <option>Yes</option>
1.8 albertel 140: </select>";
141: return $result;
142: }
143:
1.14 albertel 144: sub handle_delete {
145: if (!$ENV{"form.delete_$Apache::lonxml::curdepth"}) { return ''; }
146: my ($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
147: my $result=0;
148: if ($space) {
149: my $sub1="$space\:\:delete_$token->[1]";
150: {
151: no strict 'refs';
152: if (defined &$sub1) {
153: $result=&$sub1($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
154: }
155: }
156: }
157: if (!$result) {
158: my $endtag='/'.$token->[1];
1.45 albertel 159: my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
1.14 albertel 160: $$parser['-1']->get_token();
161: &Apache::lonxml::debug("Deleting :$bodytext: for $token->[1]");
162: &Apache::lonxml::end_tag($tagstack,$parstack,$token);
163: }
164: return 1;
165: }
166:
1.7 albertel 167: sub get_insert_list {
1.38 www 168: my ($tagname) = @_;
1.6 albertel 169: my $result='';
1.7 albertel 170: my @tagnums= ();
171: #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
1.38 www 172: if ($Apache::lonxml::insertlist{"$tagname.which"}) {
173: push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
1.7 albertel 174: }
175: foreach my $namespace (@Apache::lonxml::namespace) {
1.38 www 176: if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
177: push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
1.6 albertel 178: }
179: }
1.7 albertel 180: if (@tagnums) {
1.33 albertel 181: my %options;
1.7 albertel 182: foreach my $tagnum (@tagnums) {
1.33 albertel 183: my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
184: $options{$descrip} ="<option value=\"$tagnum\">".$descrip."</option>\n";
1.5 albertel 185: }
1.33 albertel 186: foreach my $option (sort(keys(%options))) { $result.=$options{$option}; }
1.5 albertel 187: if ($result) { $result='<option selected="on"></option>'.$result; }
188: }
189: return $result;
190: }
191:
1.4 albertel 192: sub insertlist {
1.8 albertel 193: my ($target,$token) = @_;
1.38 www 194: return &innerinsertlist($target,$token->[1]);
195: }
196:
197: sub innerinsertlist {
198: my ($target,$tagname,$closingtag) = @_;
1.4 albertel 199: my $result;
1.38 www 200: my $after='';
201: if ($closingtag) {
202: $after='_after_'.$closingtag;
203: }
1.4 albertel 204: if ($target eq 'edit') {
1.38 www 205: my $optionlist= &get_insert_list($tagname);
1.5 albertel 206: if ($optionlist) {
207: $result = "Insert:
1.38 www 208: <select name=\"insert$after\_$Apache::lonxml::curdepth\">
1.5 albertel 209: $optionlist
1.4 albertel 210: </select>"
1.11 albertel 211: } else {
212: $result=" ";
1.6 albertel 213: }
214: }
215: return $result;
216: }
217:
1.7 albertel 218: sub handle_insert {
1.15 albertel 219: if ($ENV{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
1.6 albertel 220: my $result;
221: my $tagnum = $ENV{"form.insert_$Apache::lonxml::curdepth"};
222: my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
223: if ($func eq 'default') {
224: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
1.7 albertel 225: my $namespace;
226: if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.6 albertel 227: $result.="\n<$newtag>\n</$newtag>";
228: } else {
1.15 albertel 229: if (defined(&$func)) {
230: {
231: no strict 'refs';
232: $result.=&$func();
233: }
234: } else {
235: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
236: &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined.");
1.38 www 237: }
238: }
239: return $result;
240: }
241:
242: sub handle_insertafter {
243: my $tagname=shift;
244: if ($ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
245: { return ''; }
246: my $result;
247: my $tagnum =$ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
248: my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
249: if ($func eq 'default') {
250: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
251: my $namespace;
252: if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
253: $result.="\n<$newtag>\n</$newtag>";
254: } else {
255: if (defined(&$func)) {
256: {
257: no strict 'refs';
258: $result.=&$func();
259: }
260: } else {
261: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
262: &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
1.5 albertel 263: }
264: }
265: return $result;
1.16 albertel 266: }
267:
268: sub insert_responseparam {
269: return '
270: <responseparam />';
1.5 albertel 271: }
272:
1.24 albertel 273: sub insert_formularesponse {
274: return '
275: <formularesponse answer="" samples="">
276: <textline />
277: <hintgroup>
278: </hintgroup>
279: </formularesponse>';
280: }
281:
1.15 albertel 282: sub insert_numericalresponse {
283: return '
284: <numericalresponse answer="">
285: <textline />
286: <hintgroup>
287: </hintgroup>
288: </numericalresponse>';
289: }
290:
1.18 albertel 291: sub insert_stringresponse {
292: return '
293: <stringresponse answer="" type="">
294: <textline />
295: <hintgroup>
296: </hintgroup>
297: </stringresponse>';
1.36 albertel 298: }
299:
300: sub insert_essayresponse {
301: return '
302: <essayresponse>
303: <textfield></textfield>
304: </essayresponse>';
1.54 albertel 305: }
306:
307: sub insert_imageresponse {
308: return '
309: <imageresponse max="1">
310: <foilgroup>
311: </foilgroup>
312: <hintgroup>
313: </hintgroup>
314: </imageresponse>';
1.18 albertel 315: }
316:
1.7 albertel 317: sub insert_optionresponse {
318: return '
319: <optionresponse max="10">
320: <foilgroup options="">
321: </foilgroup>
1.14 albertel 322: <hintgroup>
323: </hintgroup>
1.7 albertel 324: </optionresponse>';
1.1 albertel 325: }
326:
1.23 albertel 327: sub insert_radiobuttonresponse {
328: return '
329: <radiobuttonresponse max="10">
330: <foilgroup>
331: </foilgroup>
332: <hintgroup>
333: </hintgroup>
334: </radiobuttonresponse>';
1.43 albertel 335: }
336:
337: sub insert_rankresponse {
338: return '
339: <rankresponse max="10">
340: <foilgroup options="">
341: </foilgroup>
342: <hintgroup>
343: </hintgroup>
344: </rankresponse>';
1.23 albertel 345: }
346:
1.44 albertel 347: sub insert_matchresponse {
348: return '
349: <matchresponse max="10">
350: <foilgroup options="">
351: <itemgroup>
352: </itemgroup>
353: </foilgroup>
354: <hintgroup>
355: </hintgroup>
356: </matchresponse>';
357: }
358:
1.21 albertel 359: sub insert_displayduedate { return '<displayduedate />'; }
360: sub insert_displaytitle { return '<displaytitle />'; }
1.22 albertel 361: sub insert_hintpart {
362: return '
363: <hintpart on="default">
364: <startouttext/>
365: <endouttext />
366: </hintpart>';
367: }
368:
369: sub insert_numericalhint {
370: return '
371: <numericalhint>
372: </numericalhint>';
1.46 albertel 373: }
374:
375: sub insert_stringhint {
376: return '
377: <stringhint>
378: </stringhint>';
379: }
380:
381: sub insert_formulahint {
382: return '
383: <formulahint>
384: </formulahint>';
1.37 albertel 385: }
386:
387: sub insert_radiobuttonhint {
388: return '
389: <radiobuttonhint>
390: </radiobuttonhint>';
1.50 albertel 391: }
392:
393: sub insert_optionhint {
394: return '
395: <optionhint>
396: </optionhint>';
1.22 albertel 397: }
1.21 albertel 398:
1.23 albertel 399: sub insert_startouttext {
400: return "<startouttext />\n<endouttext />";
401: }
402:
403: sub insert_script {
404: return "\n<script type=\"loncapa/perl\">\n</script>";
405: }
406:
1.25 albertel 407: sub textarea_sizes {
408: my ($data)=@_;
409: my $count=0;
410: my $maxlength=-1;
1.53 albertel 411: foreach (split ("\n", $$data)) {
412: $count+=int(length($_)/79);
413: $count++;
414: if (length($_) > $maxlength) { $maxlength = length($_); }
415: }
1.25 albertel 416: my $rows = $count;
417: my $cols = $maxlength;
418: return ($rows,$cols);
419: }
420:
1.32 albertel 421: sub editline {
1.31 matthew 422: my ($tag,$data,$description,$size)=@_;
1.32 albertel 423: $data=&HTML::Entities::encode($data);
1.31 matthew 424: if ($description) { $description="<br />".$description."<br />"; }
425: my $result = <<"END";
426: $description
427: <input type="text" name="homework_edit_$Apache::lonxml::curdepth"
428: value="$data" size="$size" />
429: END
430: return $result;
431: }
432:
1.2 albertel 433: sub editfield {
1.5 albertel 434: my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.22 albertel 435:
1.25 albertel 436: my ($rows,$cols)=&textarea_sizes(\$data);
437: if ($cols > 80) { $cols = 80; }
438: if ($cols < $minwidth ) { $cols = $minwidth; }
439: if ($rows < $minheight) { $rows = $minheight; }
440: if ($description) { $description="<br />".$description."<br />"; }
1.32 albertel 441: return $description."\n".' <textarea rows="'.$rows.
442: '" cols="'.$cols.'" name="homework_edit_'.$Apache::lonxml::curdepth.'">'.
443: &HTML::Entities::encode($data).'</textarea>'."\n";
1.2 albertel 444: }
445:
446: sub modifiedfield {
447: my ($token) = @_;
1.3 albertel 448: my $result;
449: # foreach my $envkey (sort keys %ENV) {
450: # &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
451: # }
452: # &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
453: # &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
454: $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
455: return $result;
1.2 albertel 456: }
457:
1.15 albertel 458: # Returns a 1 if the token has been modified and you should rebuild the tag
1.12 albertel 459: # side-effects, will modify the $token if new values are found
460: sub get_new_args {
461: my ($token,$parstack,$safeeval,@args)=@_;
462: my $rebuild=0;
463: foreach my $arg (@args) {
1.20 albertel 464: #just want the string that it was set to
465: my $value=$token->[2]->{$arg};
1.48 albertel 466: my $element=&html_element_name($arg);
467: my $newvalue=$ENV{"form.$element"};
1.12 albertel 468: &Apache::lonxml::debug(" for:$arg: cur is :$value: new is :$newvalue:");
1.52 albertel 469: if (defined($newvalue) && $value ne $newvalue) {
1.12 albertel 470: $token->[2]->{$arg}=$newvalue;
471: $rebuild=1;
472: }
473: }
474: return $rebuild;
475: }
476:
1.15 albertel 477: # looks for /> on start tags
1.12 albertel 478: sub rebuild_tag {
479: my ($token) = @_;
480: my $result;
481: if ($token->[0] eq 'S') {
482: $result = '<'.$token->[1];
483: while (my ($key,$val)= each(%{$token->[2]})) {
1.20 albertel 484: $val=~s:^\s+|\s+$::g;
1.17 albertel 485: $val=~s:"::g; #"
1.12 albertel 486: &Apache::lonxml::debug("setting :$key: to :$val:");
487: $result.=' '.$key.'="'.$val.'"';
488: }
1.15 albertel 489: if ($token->[4] =~ m:/>$:) {
490: $result.=' />';
491: } else {
492: $result.='>';
493: }
1.12 albertel 494: } elsif ( $token->[0] eq 'E' ) {
495: $result = '</'.$token->[1].'>';
496: }
497: return $result;
498: }
1.13 albertel 499:
1.47 matthew 500: sub html_element_name {
501: my ($name) = @_;
1.48 albertel 502: return $name.'_'.$Apache::lonxml::curdepth;
503: }
504:
505: sub hidden_arg {
506: my ($name,$token) = @_;
507: my $result;
508: my $arg=$token->[2]{$name};
509: $result='<input name="'.&html_element_name($name).
510: '" type="hidden" value="'.$arg.'" />';
511: return $result;
1.47 matthew 512: }
513:
1.13 albertel 514: sub text_arg {
515: my ($description,$name,$token,$size) = @_;
516: my $result;
517: if (!defined $size) { $size=20; }
518: my $arg=$token->[2]{$name};
1.47 matthew 519: $result=$description.' <input name="'.&html_element_name($name).
1.13 albertel 520: '" type="text" value="'.$arg.'" size="'.$size.'" />';
1.57 albertel 521: return '<nobr>'.$result.'</nobr>';
1.13 albertel 522: }
523:
524: sub select_arg {
1.39 albertel 525: my ($description,$name,$list,$token) = @_;
526: my $result;
527: my $optionlist="";
528: my $selected=$token->[2]{$name};
1.57.2.1! albertel 529: &Apache::lonxml::error("Wha $selected");
1.39 albertel 530: foreach my $option (@$list) {
1.57.2.1! albertel 531: my ($text,$value);
1.39 albertel 532: if ( ref($option) eq 'ARRAY') {
533: $value='value="'.$$option[0].'"';
1.57.2.1! albertel 534: $text=$$option[1];
! 535: $option=$$option[0];
1.39 albertel 536: } else {
1.57.2.1! albertel 537: $text=$option;
1.39 albertel 538: $value='value="'.$option.'"';
539: }
540: if ( $selected eq $option ) {
1.57.2.1! albertel 541: $optionlist.="<option $value selected=\"on\">$text</option>\n";
1.39 albertel 542: } else {
1.57.2.1! albertel 543: $optionlist.="<option $value >$text</option>\n";
1.39 albertel 544: }
1.13 albertel 545: }
1.57 albertel 546: $result.='<nobr>'.$description.' <select name="'.
547: &html_element_name($name).'">
1.13 albertel 548: '.$optionlist.'
1.57 albertel 549: </select></nobr>';
1.39 albertel 550: return $result;
1.13 albertel 551: }
552:
1.19 albertel 553: sub select_or_text_arg {
1.39 albertel 554: my ($description,$name,$list,$token,$size) = @_;
555: my $result;
556: my $optionlist="";
557: my $found=0;
558: my $selected=$token->[2]{$name};
559: foreach my $option (@$list) {
1.57.2.1! albertel 560: my ($text,$value);
1.39 albertel 561: if ( ref($option) eq 'ARRAY') {
562: $value='value="'.$$option[0].'"';
1.57.2.1! albertel 563: $text=$$option[1];
! 564: $option=$$option[0];
1.39 albertel 565: } else {
1.57.2.1! albertel 566: $text=$option;
1.39 albertel 567: $value='value="'.$option.'"';
568: }
569: if ( $selected eq $option ) {
1.57.2.1! albertel 570: $optionlist.="<option $value selected=\"on\">$text</option>\n";
1.39 albertel 571: $found=1;
572: } else {
1.57.2.1! albertel 573: $optionlist.="<option $value>$text</option>\n";
1.39 albertel 574: }
575: }
576: $optionlist.="<option value=\"TYPEDINVALUE\">Type in value</option>\n";
577: if (($found) || (!$selected)) {
1.47 matthew 578: $result.=$description.' <select name="'.&html_element_name($name)
579: .'">
1.39 albertel 580: '.$optionlist.'
581: </select>';
1.19 albertel 582: } else {
1.39 albertel 583: $result.=&text_arg($description,$name,$token,$size);
1.19 albertel 584: }
1.57 albertel 585: return '<nobr>'.$result.'</nobr>';
1.19 albertel 586: }
1.29 matthew 587:
1.49 www 588: #----------------------------------------------------- image coordinates
589: # single image coordinates, x, y
590: sub entercoords {
591: my ($idx,,$idy,$mode,$width,$height) = @_;
592: unless ($Apache::edit::bgimgsrc) { return ''; }
593: if ($idx) { $idx.='_'; }
594: if ($idy) { $idy.='_'; }
595: my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
596: my $form = 'lonhomework';
597: my $element;
598: if (! defined($mode) || $mode eq 'attribute') {
599: $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
600: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
601: $element = &Apache::lonnet::escape('homework_edit_'.
602: $Apache::lonxml::curdepth);
603: }
604: my $formheight='';
605: if ($height) {
606: $formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
607: }
608: my $formwidth='';
609: if ($width) {
610: $formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
611: }
612: my $result = <<"ENDBUTTON";
613: <a href="/cgi-bin/imagechoice.pl?formname=$form&file=$bgfile&formx=$idx$element&formy=$idy$element$formheight$formwidth"
614: target="imagechoice">Click Coordinates</a>
615: ENDBUTTON
616: return $result;
617: }
618:
619: # coordinate pair (x1,y1)-(x2,y2)
620: sub entercoordpair {
621: my ($id,$mode,$width,$height) = @_;
622: unless ($Apache::edit::bgimgsrc) { return ''; }
623: my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
624: my $form = 'lonhomework';
625: my $element;
626: if (! defined($mode) || $mode eq 'attribute') {
627: $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
628: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
629: $element = &Apache::lonnet::escape('homework_edit_'.
630: $Apache::lonxml::curdepth);
631: }
632: my $formheight='';
633: if ($height) {
634: $formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
635: }
636: my $formwidth='';
637: if ($width) {
638: $formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
639: }
640: my $result = <<"ENDBUTTON";
1.51 www 641: <a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
1.49 www 642: target="imagechoice">Click Coordinate Pair</a>
643: ENDBUTTON
644: return $result;
645: }
1.29 matthew 646: #----------------------------------------------------- browse
647: sub browse {
648: # insert a link to call up the filesystem browser (lonindexer)
1.42 matthew 649: my ($id, $mode) = @_;
1.29 matthew 650: my $form = 'lonhomework';
1.42 matthew 651: my $element;
652: if (! defined($mode) || $mode eq 'attribute') {
1.49 www 653: $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
1.42 matthew 654: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
655: $element = &Apache::lonnet::escape('homework_edit_'.
656: $Apache::lonxml::curdepth);
657: }
1.29 matthew 658: my $result = <<"ENDBUTTON";
1.56 www 659: <a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
1.29 matthew 660: ENDBUTTON
661: return $result;
662: }
663:
1.30 matthew 664: #----------------------------------------------------- browse
665: sub search {
666: # insert a link to call up the filesystem browser (lonindexer)
1.49 www 667: my ($id, $mode) = @_;
1.30 matthew 668: my $form = 'lonhomework';
1.49 www 669: my $element;
670: if (! defined($mode) || $mode eq 'attribute') {
671: $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
672: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
673: $element = &Apache::lonnet::escape('homework_edit_'.
674: $Apache::lonxml::curdepth);
675: }
1.30 matthew 676: my $result = <<"ENDBUTTON";
677: <a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
678: ENDBUTTON
679: return $result;
680: }
681:
682:
1.1 albertel 683: 1;
684: __END__
1.26 harris41 685:
686: =head1 NAME
687:
688: Apache::edit - edit mode helpers
689:
690: =head1 SYNOPSIS
691:
692: Invoked by many homework and xml related modules.
693:
694: &Apache::edit::SUBROUTINENAME(ARGUMENTS);
695:
696: =head1 INTRODUCTION
697:
698: This module outputs HTML syntax helpful for the rendering of edit
699: mode interfaces.
700:
701: This is part of the LearningOnline Network with CAPA project
702: described at http://www.lon-capa.org.
703:
704: =head1 HANDLER SUBROUTINE
705:
706: There is no handler subroutine.
707:
708: =head1 OTHER SUBROUTINES
709:
710: =over 4
711:
712: =item *
713:
714: initialize_edit() : initialize edit (set colordepth to zero)
715:
716: =item *
717:
718: tag_start($target,$token,$description) : provide deletion and insertion lists
719: for the manipulation of a start tag; return a scalar string
720:
721: =item *
722:
723: tag_end($target,$token,$description) : ending syntax corresponding to
724: &tag_start. return a scalar string.
725:
726: =item *
727:
728: start_table($token) : start table; update colordepth; return scalar string.
729:
730: =item *
731:
732: end_table() : reduce color depth; end table; return scalar string
1.27 matthew 733:
734: =item *
735:
736: start_spanning_row() : start a new table row spanning the 'edit' environment.
737:
738: =item *
739:
740: start_row() : start a new table row and element.
741:
742: =item *
743:
744: end_row() : end current table element and row.
1.26 harris41 745:
746: =item *
747:
748: movebuttons($target,$token) : move-up and move-down buttons; return scalar
749: string
750:
751: =item *
752:
753: deletelist($target,$token) : provide a yes option in an HTML select element;
754: return scalar string
755:
756: =item *
757:
758: handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
759: $style) : respond to a user delete request by passing relevant stack
760: and array information to various rendering functions; return a scalar string
761:
762: =item *
763:
764: get_insert_list($token) : provide an insertion list based on possibilities
765: from lonxml; return a scalar string
766:
767: =item *
768:
769: insertlist($target,$token) : api that uses get_insert_list;
770: return a scalar string
771:
772: =item *
773:
774: handleinsert($token) : provide an insertion list based on possibilities
775: from lonxml; return a scalar string
776:
777: =item *
778:
779: get_insert_list($token) : provide an insertion list based on possibilities
780: from lonxml; return a scalar string
1.29 matthew 781:
782: =item *
783: browse($elementname) : provide a link which will open up the filesystem
784: browser (lonindexer) and, once a file is selected, place the result in
1.30 matthew 785: the form element $elementname.
786:
787: =item *
788: search($elementname) : provide a link which will open up the filesystem
789: searcher (lonsearchcat) and, once a file is selected, place the result in
1.29 matthew 790: the form element $elementname.
1.31 matthew 791:
1.34 harris41 792: =item *
1.32 albertel 793: editline(tag,data,description,size): Provide a <input type="text" ../> for
1.31 matthew 794: single-line text entry. This is to be used for text enclosed by tags, not
795: arguements/parameters associated with a tag.
1.26 harris41 796:
797: =back
798:
799: incomplete...
800:
801: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>