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