--- loncom/homework/edit.pm 2002/04/26 13:30:08 1.34 +++ loncom/homework/edit.pm 2002/11/07 19:45:16 1.39 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # edit mode helpers # -# $Id: edit.pm,v 1.34 2002/04/26 13:30:08 harris41 Exp $ +# $Id: edit.pm,v 1.39 2002/11/07 19:45:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,9 +39,11 @@ use HTML::Entities(); @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f'); # depth of nesting of edit $Apache::edit::colordepth=0; +@Apache::edit::inserttag=(); sub initialize_edit { $Apache::edit::colordepth=0; + @Apache::edit::inserttag=(); } sub tag_start { @@ -96,13 +98,27 @@ sub start_table { $color = $Apache::edit::colorlist[$Apache::edit::colordepth]; } $Apache::edit::colordepth++; - my $result=""; + push(@Apache::edit::inserttag,$token->[1]); + my $result='

'; + $result.='

'; return $result; } sub end_table { $Apache::edit::colordepth--; - my $result="
"; + my $result='

'; + $result.="
"; + + my ($tagname,$closingtag); + if (defined($Apache::edit::inserttag[-2])) { + $tagname=$Apache::edit::inserttag[-2]; + } else {$tagname='problem';} + if (defined($Apache::edit::inserttag[-1])) { + $closingtag=$Apache::edit::inserttag[-1]; + } + $result.=&innerinsertlist('edit',$tagname,$closingtag). + "
"; + pop(@Apache::edit::inserttag); return $result; } @@ -152,16 +168,16 @@ sub handle_delete { } sub get_insert_list { - my ($token) = @_; + my ($tagname) = @_; my $result=''; my @tagnums= (); #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist)))); - if ($Apache::lonxml::insertlist{"$token->[1].which"}) { - push (@tagnums, @{ $Apache::lonxml::insertlist{"$token->[1].which"} }); + if ($Apache::lonxml::insertlist{"$tagname.which"}) { + push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} }); } foreach my $namespace (@Apache::lonxml::namespace) { - if ($Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"}) { - push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$token->[1].which"} }); + if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) { + push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} }); } } if (@tagnums) { @@ -178,12 +194,21 @@ sub get_insert_list { sub insertlist { my ($target,$token) = @_; + return &innerinsertlist($target,$token->[1]); +} + +sub innerinsertlist { + my ($target,$tagname,$closingtag) = @_; my $result; + my $after=''; + if ($closingtag) { + $after='_after_'.$closingtag; + } if ($target eq 'edit') { - my $optionlist= &get_insert_list($token); + my $optionlist= &get_insert_list($tagname); if ($optionlist) { $result = "Insert: - $optionlist " } else { @@ -217,6 +242,32 @@ sub handle_insert { return $result; } +sub handle_insertafter { + my $tagname=shift; + if ($ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '') + { return ''; } + my $result; + my $tagnum =$ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"}; + my $func=$Apache::lonxml::insertlist{"$tagnum.function"}; + if ($func eq 'default') { + my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"}; + my $namespace; + if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); } + $result.="\n<$newtag>\n"; + } else { + if (defined(&$func)) { + { + no strict 'refs'; + $result.=&$func(); + } + } else { + my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"}; + &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)"); + } + } + return $result; +} + sub insert_responseparam { return ' '; @@ -249,6 +300,13 @@ sub insert_stringresponse { '; } +sub insert_essayresponse { + return ' + + +'; +} + sub insert_optionresponse { return ' @@ -285,6 +343,12 @@ sub insert_numericalhint { '; } +sub insert_radiobuttonhint { + return ' + +'; +} + sub insert_startouttext { return "\n"; } @@ -394,46 +458,61 @@ sub text_arg { } sub select_arg { - my ($description,$name,$list,$token) = @_; - my $result; - my $optionlist=""; - my $selected=$token->[2]{$name}; - foreach my $option (@$list) { - if ( $selected eq $option ) { - $optionlist.="\n"; - } else { - $optionlist.="\n"; + my ($description,$name,$list,$token) = @_; + my $result; + my $optionlist=""; + my $selected=$token->[2]{$name}; + foreach my $option (@$list) { + my $value; + if ( ref($option) eq 'ARRAY') { + $value='value="'.$$option[0].'"'; + $option=$$option[1]; + } else { + $value='value="'.$option.'"'; + } + if ( $selected eq $option ) { + $optionlist.="\n"; + } else { + $optionlist.="\n"; + } } - } - $result.=$description.' '.$optionlist.' '; - return $result; + return $result; } sub select_or_text_arg { - my ($description,$name,$list,$token,$size) = @_; - my $result; - my $optionlist=""; - my $found=0; - my $selected=$token->[2]{$name}; - foreach my $option (@$list) { - if ( $selected eq $option ) { - $optionlist.="\n"; - $found=1; - } else { - $optionlist.="\n"; - } - } - $optionlist.="\n"; - if ($found) { - $result.=$description.' '.$optionlist.' '; - } else { - $result.=&text_arg($description,$name,$token,$size); - } - return $result; + } else { + $result.=&text_arg($description,$name,$token,$size); + } + return $result; } #----------------------------------------------------- browse