Annotation of loncom/homework/edit.pm, revision 1.47

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

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