File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.66: download - view: text, annotated - select for diffs
Fri Sep 19 19:37:53 2003 UTC (20 years, 7 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Re-enable help links in construction space.

    1: # The LearningOnline Network with CAPA 
    2: # edit mode helpers
    3: #
    4: # $Id: edit.pm,v 1.66 2003/09/19 19:37:53 matthew Exp $
    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: #
   28: # 3/20 Guy
   29: # 01/10/02 Matthew
   30: # 03/06/02 Matthew
   31: package Apache::edit; 
   32: 
   33: use strict;
   34: use Apache::lonnet();
   35: use HTML::Entities();
   36: 
   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;
   42: @Apache::edit::inserttag=();
   43: # image-type responses: active background image and curdepth at definition
   44: $Apache::edit::bgimgsrc='';
   45: $Apache::edit::bgimgsrccurdepth='';
   46: 
   47: sub initialize_edit {
   48:     $Apache::edit::colordepth=0;
   49:     @Apache::edit::inserttag=();
   50: }
   51: 
   52: sub tag_start {
   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);
   67: #<td>". 
   68: #  &movebuttons($target,$token).
   69: #    "</tr><tr><td colspan=\"3\">\n";
   70: 	my @help = Apache::lonxml::helpinfo($token);
   71: 	if ($help[0]) {
   72: 	    $result .= '<td align="right" valign="top">' .
   73: 		Apache::loncommon::help_open_topic(@help) .
   74: 		'</td>';
   75: 	} else { $result .= "<td>&nbsp;</td>"; }
   76: 	$result .= &end_row().&start_spanning_row();
   77:     }
   78:     return $result;
   79: }
   80: 
   81: sub tag_end {
   82:     my ($target,$token,$description) = @_;
   83:     my $result='';
   84:     if ($target eq 'edit') {
   85: 	$result.="</td></tr>".&end_table()."\n";
   86:     }
   87:     return $result;
   88: }
   89: 
   90: sub start_table {
   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;
  109: }
  110: 
  111: sub end_table {
  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;
  127: }
  128: 
  129: sub start_spanning_row { return '<tr><td colspan="4" bgcolor="#DDDDDD">';}
  130: sub start_row          { return '<tr><td bgcolor="#DDDDDD">';            }
  131: sub end_row            { return '</td></tr>';          }
  132: 
  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: 
  142: sub deletelist {
  143:     my ($target,$token) = @_;
  144:     my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
  145: <option></option>
  146: <option>Yes</option>
  147: </select>";
  148:     return $result;
  149: }
  150: 
  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];
  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;
  172: }
  173: 
  174: sub get_insert_list {
  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;
  198: }
  199: 
  200: sub insertlist {
  201:     my ($target,$token) = @_;
  202:     return &innerinsertlist($target,$token->[1]);
  203: }
  204: 
  205: sub innerinsertlist {
  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="&nbsp;";
  221: 	}
  222:     }
  223:     return $result;
  224: }
  225: 
  226: sub handle_insert {
  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>";
  236:     } else {
  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: 	}
  246:     }
  247:     return $result;
  248: }
  249: 
  250: sub handle_insertafter {
  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>";
  262:     } else {
  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: 	}
  272:     }
  273:     return $result;
  274: }
  275: 
  276: sub insert_responseparam {
  277:     return '
  278:     <responseparam />';
  279: }
  280: 
  281: sub insert_formularesponse {
  282:     return '
  283: <formularesponse answer="" samples="">
  284:     <textline />
  285:     <hintgroup>
  286:     </hintgroup>
  287: </formularesponse>';
  288: }
  289: 
  290: sub insert_numericalresponse {
  291:     return '
  292: <numericalresponse answer="">
  293:     <textline />
  294:     <hintgroup>
  295:     </hintgroup>
  296: </numericalresponse>';
  297: }
  298: 
  299: sub insert_stringresponse {
  300:     return '
  301: <stringresponse answer="" type="">
  302:     <textline />
  303:     <hintgroup>
  304:     </hintgroup>
  305: </stringresponse>';
  306: }
  307: 
  308: sub insert_essayresponse {
  309:     return '
  310: <essayresponse>
  311:     <textfield></textfield>
  312: </essayresponse>';
  313: }
  314: 
  315: sub insert_imageresponse {
  316:     return '
  317: <imageresponse max="1">
  318:     <foilgroup>
  319:     </foilgroup>
  320:     <hintgroup>
  321:     </hintgroup>
  322: </imageresponse>';
  323: }
  324: 
  325: sub insert_optionresponse {
  326:     return '
  327: <optionresponse max="10">
  328:     <foilgroup options="">
  329:     </foilgroup>
  330:     <hintgroup>
  331:     </hintgroup>
  332: </optionresponse>';
  333: }
  334: 
  335: sub insert_radiobuttonresponse {
  336:     return '
  337: <radiobuttonresponse max="10">
  338:     <foilgroup>
  339:     </foilgroup>
  340:     <hintgroup>
  341:     </hintgroup>
  342: </radiobuttonresponse>';
  343: }
  344: 
  345: sub insert_rankresponse {
  346:     return '
  347: <rankresponse max="10">
  348:     <foilgroup options="">
  349:     </foilgroup>
  350:     <hintgroup>
  351:     </hintgroup>
  352: </rankresponse>';
  353: }
  354: 
  355: sub insert_matchresponse {
  356:     return '
  357: <matchresponse max="10">
  358:     <foilgroup options="">
  359:       <itemgroup>
  360:       </itemgroup>
  361:     </foilgroup>
  362:     <hintgroup>
  363:     </hintgroup>
  364: </matchresponse>';
  365: }
  366: 
  367: sub insert_displayduedate { return '<displayduedate />'; }
  368: sub insert_displaytitle   { return '<displaytitle />'; }
  369: sub insert_hintpart {
  370:     return '
  371: <hintpart on="default">
  372:     <startouttext/>
  373:     <endouttext />
  374: </hintpart>';
  375: }
  376: 
  377: sub insert_numericalhint {
  378:     return '
  379: <numericalhint>
  380: </numericalhint>';
  381: }
  382: 
  383: sub insert_stringhint {
  384:     return '
  385: <stringhint>
  386: </stringhint>';
  387: }
  388: 
  389: sub insert_formulahint {
  390:     return '
  391: <formulahint>
  392: </formulahint>';
  393: }
  394: 
  395: sub insert_radiobuttonhint {
  396:     return '
  397: <radiobuttonhint>
  398: </radiobuttonhint>';
  399: }
  400: 
  401: sub insert_optionhint {
  402:     return '
  403: <optionhint>
  404: </optionhint>';
  405: }
  406: 
  407: sub insert_startouttext {
  408:     return "<startouttext />\n<endouttext />";
  409: }
  410: 
  411: sub insert_script {
  412:     return "\n<script type=\"loncapa/perl\">\n</script>";
  413: }
  414: 
  415: sub textarea_sizes {
  416:     my ($data)=@_;
  417:     my $count=0;
  418:     my $maxlength=-1;
  419:     foreach (split ("\n", $$data)) {
  420: 	$count+=int(length($_)/79);
  421: 	$count++;
  422: 	if (length($_) > $maxlength) { $maxlength = length($_); }
  423:     }
  424:     my $rows = $count;
  425:     my $cols = $maxlength;
  426:     return ($rows,$cols);
  427: }
  428: 
  429: sub editline {
  430:     my ($tag,$data,$description,$size)=@_;
  431:     $data=&HTML::Entities::encode($data);
  432:     if ($description) { $description="<br />".$description."<br />"; }
  433:     my $result = <<"END";
  434: $description
  435: <input type="text" name="homework_edit_$Apache::lonxml::curdepth" 
  436:        value="$data" size="$size" />
  437: END
  438:     return $result;
  439: }
  440: 
  441: sub editfield {
  442:     my ($tag,$data,$description,$minwidth,$minheight)=@_;
  443: 
  444:     my ($rows,$cols)=&textarea_sizes(\$data);
  445:     if ($cols > 80) { $cols = 80; }
  446:     if ($cols < $minwidth ) { $cols = $minwidth; }
  447:     if ($rows < $minheight) { $rows = $minheight; }
  448:     if ($description) { $description="<br />".$description."<br />"; }
  449:     return $description."\n".'&nbsp;&nbsp;&nbsp;<textarea rows="'.$rows.
  450: 	'" cols="'.$cols.'" name="homework_edit_'.
  451: 	$Apache::lonxml::curdepth.'">'.
  452: 	&HTML::Entities::encode($data).'</textarea>'."\n";
  453: }
  454: 
  455: sub modifiedfield {
  456:     my ($token) = @_;
  457:     my $result;
  458: #  foreach my $envkey (sort keys %ENV) {
  459: #    &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
  460: #  }
  461: #  &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
  462: #  &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
  463:     $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
  464:     return $result;
  465: }
  466: 
  467: # Returns a 1 if the token has been modified and you should rebuild the tag
  468: # side-effects, will modify the $token if new values are found
  469: sub get_new_args {
  470:     my ($token,$parstack,$safeeval,@args)=@_;
  471:     my $rebuild=0;
  472:     foreach my $arg (@args) {
  473: 	#just want the string that it was set to
  474: 	my $value=$token->[2]->{$arg};
  475: 	my $element=&html_element_name($arg);
  476: 	my $newvalue=$ENV{"form.$element"};
  477: 	&Apache::lonxml::debug("for:$arg: cur is :$value: new is :$newvalue:");
  478: 	if (defined($newvalue) && $value ne $newvalue) {
  479: 	    if (ref($newvalue) eq 'ARRAY') {
  480: 		$token->[2]->{$arg}=join(',',@$newvalue);
  481: 	    } else {
  482: 		$token->[2]->{$arg}=$newvalue;
  483: 	    }
  484: 	    $rebuild=1;
  485: 	}
  486:     }
  487:     return $rebuild;
  488: }
  489: 
  490: # looks for /> on start tags
  491: sub rebuild_tag {
  492:     my ($token) = @_;
  493:     my $result;
  494:     if ($token->[0] eq 'S') {
  495: 	$result = '<'.$token->[1];
  496: 	while (my ($key,$val)= each(%{$token->[2]})) {
  497: 	    $val=~s:^\s+|\s+$::g;
  498: 	    $val=~s:"::g; #"
  499: 	    &Apache::lonxml::debug("setting :$key: to  :$val:");
  500: 	    $result.=' '.$key.'="'.$val.'"';
  501: 	}
  502: 	if ($token->[4] =~ m:/>$:) {
  503: 	    $result.=' />';
  504: 	} else {
  505: 	    $result.='>';
  506: 	}
  507:     } elsif ( $token->[0] eq 'E' ) {
  508: 	$result = '</'.$token->[1].'>';
  509:     }
  510:     return $result;
  511: }
  512: 
  513: sub html_element_name {
  514:     my ($name) = @_;
  515:     return $name.'_'.$Apache::lonxml::curdepth;
  516: }
  517: 
  518: sub hidden_arg {
  519:     my ($name,$token) = @_;
  520:     my $result;
  521:     my $arg=$token->[2]{$name};
  522:     $result='<input name="'.&html_element_name($name).
  523: 	'" type="hidden" value="'.$arg.'" />';
  524:     return $result;
  525: }
  526: 
  527: sub checked_arg {
  528:     my ($description,$name,$list,$token) = @_;
  529:     my $result;
  530:     my $optionlist="";
  531:     my $allselected=$token->[2]{$name};
  532:     $result=$description;
  533:     foreach my $option (@$list) {
  534: 	my ($value,$text);
  535: 	if ( ref($option) eq 'ARRAY') {
  536: 	    $value='value="'.$$option[0].'"';
  537: 	    $text=$$option[1];
  538: 	    $option=$$option[0];
  539: 	} else {
  540: 	    $text=$option;
  541: 	    $value='value="'.$option.'"';
  542: 	}
  543: 	$result.="<nobr><input type='checkbox' $value name='".
  544: 	    &html_element_name($name)."'";
  545: 	foreach my $selected (split(/,/,$allselected)) {
  546: 	    if ( $selected eq $option ) {
  547: 		$result.=" checked='on' ";
  548: 		last;
  549: 	    }
  550: 	}
  551: 	$result.=" />$text</nobr>\n";
  552:     }
  553:     return $result;
  554: }
  555: 
  556: sub text_arg {
  557:     my ($description,$name,$token,$size) = @_;
  558:     my $result;
  559:     if (!defined $size) { $size=20; }
  560:     my $arg=$token->[2]{$name};
  561:     $result=$description.'&nbsp;<input name="'.&html_element_name($name).
  562: 	'" type="text" value="'.$arg.'" size="'.$size.'" />';
  563:     return '<nobr>'.$result.'</nobr>';
  564: }
  565: 
  566: sub select_arg {
  567:     my ($description,$name,$list,$token) = @_;
  568:     my $result;
  569:     my $optionlist="";
  570:     my $selected=$token->[2]{$name};
  571:     foreach my $option (@$list) {
  572: 	my ($text,$value);
  573: 	if ( ref($option) eq 'ARRAY') {
  574: 	    $value='value="'.$$option[0].'"';
  575: 	    $text=$$option[1];
  576: 	    $option=$$option[0];
  577: 	} else {
  578: 	    $text=$option;
  579: 	    $value='value="'.$option.'"';
  580: 	}
  581: 	if ( $selected eq $option ) {
  582: 	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
  583: 	} else {
  584: 	    $optionlist.="<option $value >$text</option>\n";
  585: 	}
  586:     }
  587:     $result.='<nobr>'.$description.'&nbsp;<select name="'.
  588: 	&html_element_name($name).'">
  589:        '.$optionlist.'
  590:       </select></nobr>';
  591:     return $result;
  592: }
  593: 
  594: sub select_or_text_arg {
  595:     my ($description,$name,$list,$token,$size) = @_;
  596:     my $result;
  597:     my $optionlist="";
  598:     my $found=0;
  599:     my $selected=$token->[2]{$name};
  600:     foreach my $option (@$list) {
  601: 	my ($text,$value);
  602: 	if ( ref($option) eq 'ARRAY') {
  603: 	    $value='value="'.$$option[0].'"';
  604: 	    $text=$$option[1];
  605: 	    $option=$$option[0];
  606: 	} else {
  607: 	    $text=$option;
  608: 	    $value='value="'.$option.'"';
  609: 	}
  610: 	if ( $selected eq $option ) {
  611: 	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
  612: 	    $found=1;
  613: 	} else {
  614: 	    $optionlist.="<option $value>$text</option>\n";
  615: 	}
  616:     }
  617:     $optionlist.="<option value=\"TYPEDINVALUE\"".
  618:  	((!$found)?' selected="on"':'').
  619:  	">Type in value</option>\n";
  620: #
  621:     my $element=&html_element_name($name);
  622:     my $selectelement='select_list_'.$element;
  623:     my $typeinelement='type_in_'.$element;
  624:     my $typeinvalue=($found?'':$selected);
  625: #
  626:     my $hiddenvalue='this.form.'.$element.'.value';
  627:     my $selectedindex='this.form.'.$selectelement.'.selectedIndex';
  628:     my $selectedvalue='this.form.'.$selectelement.
  629: 	     '.options['.$selectedindex.'].value';
  630:     my $typedinvalue='this.form.'.$typeinelement.'.value';
  631:     my $selecttypeinindex='this.form.'.$selectelement.'.options.length';
  632: #
  633:     return (<<ENDSELECTORTYPE);
  634: <nobr>
  635: $description
  636: &nbsp;<select name="$selectelement"
  637: onChange="if ($selectedvalue!='TYPEDINVALUE') { $hiddenvalue=$selectedvalue; $typedinvalue=''; }"
  638: $optionlist
  639: </select>
  640: <input type="text" size="$size" name="$typeinelement"
  641:        value="$typeinvalue" 
  642: onChange="$hiddenvalue=$typedinvalue;"
  643: onFocus="$selectedindex=$selecttypeinindex-1;" />
  644: <input type="hidden" name="$element" value="$selected" />
  645: </nobr>
  646: ENDSELECTORTYPE
  647: }
  648: 
  649: #----------------------------------------------------- image coordinates
  650: # single image coordinates, x, y 
  651: sub entercoords {
  652:     my ($idx,,$idy,$mode,$width,$height) = @_;
  653:     unless ($Apache::edit::bgimgsrc) { return ''; }
  654:     if ($idx) { $idx.='_'; }
  655:     if ($idy) { $idy.='_'; }
  656:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  657:     my $form    = 'lonhomework';
  658:     my $element;
  659:     if (! defined($mode) || $mode eq 'attribute') {
  660:         $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
  661:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  662:         $element = &Apache::lonnet::escape('homework_edit_'.
  663:                                            $Apache::lonxml::curdepth);
  664:     }
  665:     my $formheight='';
  666:     if ($height) {
  667: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  668:     }
  669:     my $formwidth='';
  670:     if ($width) {
  671: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  672:     }
  673:     my $result = <<"ENDBUTTON";
  674: <a href="/cgi-bin/imagechoice.pl?formname=$form&file=$bgfile&formx=$idx$element&formy=$idy$element$formheight$formwidth"
  675: target="imagechoice">Click Coordinates</a>
  676: ENDBUTTON
  677:     return $result;
  678: }
  679: 
  680: # coordinate pair (x1,y1)-(x2,y2)
  681: sub entercoordpair {
  682:     my ($id,$mode,$width,$height) = @_;
  683:     unless ($Apache::edit::bgimgsrc) { return ''; }
  684:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  685:     my $form    = 'lonhomework';
  686:     my $element;
  687:     if (! defined($mode) || $mode eq 'attribute') {
  688:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  689:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  690:         $element = &Apache::lonnet::escape('homework_edit_'.
  691:                                            $Apache::lonxml::curdepth);
  692:     }
  693:     my $formheight='';
  694:     if ($height) {
  695: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  696:     }
  697:     my $formwidth='';
  698:     if ($width) {
  699: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  700:     }
  701:     my $result = <<"ENDBUTTON";
  702: <a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
  703: target="imagechoice">Click Coordinate Pair</a>
  704: ENDBUTTON
  705:     return $result;
  706: }
  707: #----------------------------------------------------- browse
  708: sub browse {
  709:     # insert a link to call up the filesystem browser (lonindexer)
  710:     my ($id, $mode) = @_;
  711:     my $form    = 'lonhomework';
  712:     my $element;
  713:     if (! defined($mode) || $mode eq 'attribute') {
  714:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  715:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  716:         $element = &Apache::lonnet::escape('homework_edit_'.
  717:                                            $Apache::lonxml::curdepth);
  718:     }
  719:     my $result = <<"ENDBUTTON";
  720: <a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
  721: ENDBUTTON
  722:     return $result;
  723: }
  724: 
  725: #----------------------------------------------------- browse
  726: sub search {
  727:     # insert a link to call up the filesystem browser (lonindexer)
  728:     my ($id, $mode) = @_;
  729:     my $form    = 'lonhomework';
  730:     my $element;
  731:     if (! defined($mode) || $mode eq 'attribute') {
  732:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  733:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  734:         $element = &Apache::lonnet::escape('homework_edit_'.
  735:                                            $Apache::lonxml::curdepth);
  736:     }
  737:     my $result = <<"ENDBUTTON";
  738: <a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
  739: ENDBUTTON
  740:     return $result;
  741: }
  742: 
  743: 
  744: 1;
  745: __END__
  746: 
  747: =head1 NAME
  748: 
  749: Apache::edit - edit mode helpers
  750: 
  751: =head1 SYNOPSIS
  752: 
  753: Invoked by many homework and xml related modules.
  754: 
  755:  &Apache::edit::SUBROUTINENAME(ARGUMENTS);
  756: 
  757: =head1 INTRODUCTION
  758: 
  759: This module outputs HTML syntax helpful for the rendering of edit
  760: mode interfaces.
  761: 
  762: This is part of the LearningOnline Network with CAPA project
  763: described at http://www.lon-capa.org.
  764: 
  765: =head1 HANDLER SUBROUTINE
  766: 
  767: There is no handler subroutine.
  768: 
  769: =head1 OTHER SUBROUTINES
  770: 
  771: =over 4
  772: 
  773: =item *
  774: 
  775: initialize_edit() : initialize edit (set colordepth to zero)
  776: 
  777: =item *
  778: 
  779: tag_start($target,$token,$description) : provide deletion and insertion lists
  780: for the manipulation of a start tag; return a scalar string
  781: 
  782: =item *
  783: 
  784: tag_end($target,$token,$description) : ending syntax corresponding to
  785: &tag_start. return a scalar string.
  786: 
  787: =item *
  788: 
  789: start_table($token) : start table; update colordepth; return scalar string.
  790: 
  791: =item *
  792: 
  793: end_table() : reduce color depth; end table; return scalar string
  794: 
  795: =item *
  796: 
  797: start_spanning_row() : start a new table row spanning the 'edit' environment.
  798: 
  799: =item *
  800: 
  801: start_row() : start a new table row and element. 
  802: 
  803: =item *
  804: 
  805: end_row() : end current table element and row.
  806: 
  807: =item *
  808: 
  809: movebuttons($target,$token) : move-up and move-down buttons; return scalar
  810: string
  811: 
  812: =item *
  813: 
  814: deletelist($target,$token) : provide a yes option in an HTML select element;
  815: return scalar string
  816: 
  817: =item *
  818: 
  819: handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
  820: $style) : respond to a user delete request by passing relevant stack
  821: and array information to various rendering functions; return a scalar string
  822: 
  823: =item *
  824: 
  825: get_insert_list($token) : provide an insertion list based on possibilities
  826: from lonxml; return a scalar string
  827: 
  828: =item *
  829: 
  830: insertlist($target,$token) : api that uses get_insert_list;
  831: return a scalar string
  832: 
  833: =item *
  834: 
  835: handleinsert($token) : provide an insertion list based on possibilities
  836: from lonxml; return a scalar string
  837: 
  838: =item *
  839: 
  840: get_insert_list($token) : provide an insertion list based on possibilities
  841: from lonxml; return a scalar string
  842: 
  843: =item *
  844: browse($elementname) : provide a link which will open up the filesystem
  845: browser (lonindexer) and, once a file is selected, place the result in
  846: the form element $elementname.
  847: 
  848: =item *
  849: search($elementname) : provide a link which will open up the filesystem
  850: searcher (lonsearchcat) and, once a file is selected, place the result in
  851: the form element $elementname.
  852: 
  853: =item *
  854: editline(tag,data,description,size): Provide a <input type="text" ../> for
  855: single-line text entry.  This is to be used for text enclosed by tags, not
  856: arguements/parameters associated with a tag.
  857: 
  858: =back
  859: 
  860: incomplete...
  861: 
  862: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>