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