version 1.112, 2007/10/03 00:24:48
|
version 1.157, 2023/03/27 18:41:06
|
Line 26
|
Line 26
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
|
|
|
=pod |
|
|
|
=head1 NAME |
|
|
|
Apache::edit - edit mode helpers |
|
|
|
=head1 SYNOPSIS |
|
|
|
Invoked by many homework and xml related modules. |
|
|
|
&Apache::edit::SUBROUTINENAME(ARGUMENTS); |
|
|
|
=head1 INTRODUCTION |
|
|
|
This module outputs HTML syntax helpful for the rendering of edit |
|
mode interfaces. |
|
|
|
This is part of the LearningOnline Network with CAPA project |
|
described at http://www.lon-capa.org. |
|
|
|
=head1 SUBROUTINES |
|
|
|
=over 4 |
|
|
|
=item initialize_edit() |
|
|
|
initialize edit (set colordepth to zero) |
|
|
|
=item tag_start($target,$token,$description) |
|
|
|
provide deletion and insertion lists |
|
for the manipulation of a start tag; return a scalar string |
|
|
|
=item tag_end($target,$token,$description) |
|
|
|
ending syntax corresponding to |
|
&tag_start. return a scalar string. |
|
|
|
=item start_table($token) |
|
|
|
start table; update colordepth; return scalar string. |
|
|
|
=item end_table() |
|
|
|
reduce color depth; end table; return scalar string |
|
|
|
=item start_spanning_row() |
|
|
|
start a new table row spanning the 'edit' environment. |
|
|
|
=item start_row() |
|
|
|
start a new table row and element. |
|
|
|
=item end_row() |
|
|
|
end current table element and row. |
|
|
|
=item movebuttons($target,$token) |
|
|
|
move-up and move-down buttons; return scalar string |
|
|
|
=item deletelist($target,$token) |
|
|
|
provide a yes option in an HTML select element; return scalar string |
|
|
|
=item handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval, |
|
$style) |
|
|
|
respond to a user delete request by passing relevant stack |
|
and array information to various rendering functions; return a scalar string |
|
|
|
=item get_insert_list($token) |
|
|
|
provide an insertion list based on possibilities from lonxml; return a scalar string |
|
|
|
=item insertlist($target,$token) |
|
|
|
api that uses get_insert_list; return a scalar string |
|
|
|
=item handleinsert($token) |
|
|
|
provide an insertion list based on possibilities from lonxml; return a scalar string |
|
|
|
=item get_insert_list($token) |
|
|
|
provide an insertion list based on possibilities from lonxml; return a scalar string |
|
|
|
=item browse($elementname) |
|
|
|
provide a link which will open up the filesystem browser (lonindexer) and, once a file is selected, place the result in the form element $elementname. |
|
|
|
=item search($elementname) |
|
|
|
provide a link which will open up the filesystem searcher (lonsearchcat) and, once a file is selected, place the result in the form element $elementname. |
|
|
|
=item editline(tag,data,description,size) |
|
|
|
Provide a <input type="text" ../> for single-line text entry. This is to be used for text enclosed by tags, not arguements/parameters associated with a tag. |
|
|
|
=back |
|
|
|
=cut |
|
|
package Apache::edit; |
package Apache::edit; |
|
|
use strict; |
use strict; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::loncommon; |
use HTML::Entities(); |
use HTML::Entities(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use LONCAPA; |
use LONCAPA qw(:DEFAULT :match); |
|
|
|
|
# Global Vars |
# Global Vars |
Line 57 sub tag_start {
|
Line 162 sub tag_start {
|
if ($target eq "edit") { |
if ($target eq "edit") { |
my $tag=$token->[1]; |
my $tag=$token->[1]; |
if (!$description) { |
if (!$description) { |
$description=&Apache::lonxml::description($token); |
$description=&mt(&Apache::lonxml::description($token)); |
if (!$description) { $description="<$tag>"; } |
if (!$description) { $description="<$tag>"; } |
} |
} |
$result.= &start_table($token)."<tr><td>$description</td> |
$result.= &start_table($token)."<tr><td>".&Apache::loncommon::insert_folding_button(). |
<td>Delete". |
" $description</td><td>".&mt('Delete?')." ".&deletelist($target,$token). |
&deletelist($target,$token) |
"</td><td>".&insertlist($target,$token); |
."</td> |
|
<td>". |
|
&insertlist($target,$token); |
|
#<td>". |
#<td>". |
# &movebuttons($target,$token). |
# &movebuttons($target,$token). |
# "</tr><tr><td colspan=\"3\">\n"; |
# "</tr><tr><td colspan=\"3\">\n"; |
my @help = Apache::lonxml::helpinfo($token); |
my @help = Apache::lonxml::helpinfo($token); |
if ($help[0]) { |
if ($help[0]) { |
$result .= '</td><td align="right" valign="top">' . |
$result .= '</td><td class="LC_edit_problem_latexhelper">'. |
Apache::loncommon::help_open_topic(@help); |
Apache::loncommon::help_open_topic(@help); |
} else { $result .= "</td><td> "; } |
} else { $result .= "</td><td> "; } |
$result .= &end_row().&start_spanning_row(); |
$result .= &end_row().&start_spanning_row(); |
Line 99 sub start_table {
|
Line 201 sub start_table {
|
} |
} |
$Apache::edit::colordepth++; |
$Apache::edit::colordepth++; |
push(@Apache::edit::inserttag,$token->[1]); |
push(@Apache::edit::inserttag,$token->[1]); |
my $result='<div align="right">'; |
my $result='<div>'; |
$result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="5" cellpadding="3">'; |
$result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="3" cellpadding="2">'; |
return $result; |
return $result; |
} |
} |
|
|
sub end_table { |
sub end_table { |
$Apache::edit::colordepth--; |
$Apache::edit::colordepth--; |
my $result='</table></div>'; |
my $result='</table></div>'; |
$result.='<div align="left"><table><tr><td>'; |
$result.='<div><table><tr><td>'; |
|
|
my ($tagname,$closingtag); |
my ($tagname,$closingtag); |
if (defined($Apache::edit::inserttag[-2])) { |
if (defined($Apache::edit::inserttag[-2])) { |
Line 128 sub end_table {
|
Line 230 sub end_table {
|
return $result; |
return $result; |
} |
} |
|
|
sub start_spanning_row { return '<tr><td colspan="4" bgcolor="#DDDDDD">';} |
sub start_spanning_row { |
|
return '<tr name="foldblock_'.$Apache::lonxml::curdepth. |
|
'" style="visibility: \'\'"><td colspan="5" bgcolor="#F0F0F0">'; |
|
} |
sub start_row { return '<tr><td bgcolor="#DDDDDD">'; } |
sub start_row { return '<tr><td bgcolor="#DDDDDD">'; } |
sub end_row { return '</td></tr>'; } |
sub end_row { return '</td></tr>'; } |
|
|
Line 145 sub deletelist {
|
Line 250 sub deletelist {
|
my ($target,$token) = @_; |
my ($target,$token) = @_; |
my $result = "<select name=\"delete_$Apache::lonxml::curdepth\"> |
my $result = "<select name=\"delete_$Apache::lonxml::curdepth\"> |
<option></option> |
<option></option> |
<option>Yes</option> |
<option>".&mt('yes')."</option> |
</select>"; |
</select>"; |
return $result; |
return $result; |
} |
} |
Line 192 sub get_insert_list {
|
Line 297 sub get_insert_list {
|
my $descrip=$Apache::lonxml::insertlist{"$tag.description"}; |
my $descrip=$Apache::lonxml::insertlist{"$tag.description"}; |
my $tagnum =$Apache::lonxml::insertlist{"$tag.num"}; |
my $tagnum =$Apache::lonxml::insertlist{"$tag.num"}; |
$options{$descrip} ="<option value=\"$tagnum\">". |
$options{$descrip} ="<option value=\"$tagnum\">". |
$descrip."</option>\n"; |
&mt($descrip)."</option>\n"; |
} |
} |
foreach my $option (sort(keys(%options))) {$result.=$options{$option};} |
foreach my $option (sort(keys(%options))) {$result.=$options{$option};} |
if ($result) { $result='<option selected="selected"></option>'.$result; } |
if ($result) { $result='<option selected="selected"></option>'.$result; } |
Line 215 sub innerinsertlist {
|
Line 320 sub innerinsertlist {
|
if ($target eq 'edit') { |
if ($target eq 'edit') { |
my $optionlist= &get_insert_list($tagname); |
my $optionlist= &get_insert_list($tagname); |
if ($optionlist) { |
if ($optionlist) { |
$result = "Insert: |
$result = &mt('Insert:')." |
<select name=\"insert$after\_$Apache::lonxml::curdepth\"> |
<select name=\"insert$after\_$Apache::lonxml::curdepth\"> |
$optionlist |
$optionlist |
</select>" |
</select>" |
Line 253 sub do_insert {
|
Line 358 sub do_insert {
|
my $depth = scalar(@Apache::lonxml::depthcounter); |
my $depth = scalar(@Apache::lonxml::depthcounter); |
$depth -- if ($after); |
$depth -- if ($after); |
my $inset = "\t"x$depth; |
my $inset = "\t"x$depth; |
$result.="\n$inset<$newtag>\n$inset</$newtag>"; |
$result.="\n$inset<$newtag></$newtag>"; |
} else { |
} else { |
if (defined(&$func)) { |
if (defined(&$func)) { |
{ |
{ |
Line 293 sub insert_formularesponse {
|
Line 398 sub insert_formularesponse {
|
</formularesponse>'; |
</formularesponse>'; |
} |
} |
|
|
|
sub insert_functionplotresponse { |
|
return ' |
|
<functionplotresponse> |
|
<functionplotelements> |
|
</functionplotelements> |
|
<functionplotruleset> |
|
</functionplotruleset> |
|
</functionplotresponse>'; |
|
} |
|
|
|
sub insert_spline { |
|
return ' |
|
<spline />'; |
|
} |
|
|
|
sub insert_backgroundplot { |
|
return ' |
|
<backgroundplot />'; |
|
} |
|
|
|
sub insert_plotobject { |
|
return ' |
|
<plotobject />'; |
|
} |
|
|
|
sub insert_plotvector { |
|
return ' |
|
<plotvector />'; |
|
} |
|
|
|
sub insert_drawvectorsum { |
|
return ' |
|
<drawvectorsum />'; |
|
} |
|
|
|
|
|
sub insert_functionplotrule { |
|
return ' |
|
<functionplotrule />'; |
|
} |
|
|
|
sub insert_functionplotvectorrule { |
|
return ' |
|
<functionplotvectorrule />'; |
|
} |
|
|
|
sub insert_functionplotvectorsumrule { |
|
return ' |
|
<functionplotvectorsumrule />'; |
|
} |
|
|
|
sub insert_functionplotcustomrule { |
|
return ' |
|
<functionplotcustomrule> |
|
<answer type="loncapa/perl"> |
|
# &fpr_val("label"), &fpr_f($x), &fpr_dfdx($x), &fpr_d2fdx2($x) |
|
# ($xs,$xe,$ys,$ye)=&fpr_vectorcoords("Name"), ($x,$y)=&fpr_objectcoords("Name") |
|
# &fpr_vectorlength("Name"), &fpr_vectorangle("Name") |
|
|
|
# Return 0 or 1 |
|
return 1; |
|
</answer> |
|
</functionplotcustomrule>'; |
|
} |
|
|
|
sub insert_functionplotruleset { |
|
return ' |
|
<functionplotruleset> |
|
<functionplotrule /> |
|
</functionplotruleset>'; |
|
} |
|
|
|
sub insert_functionplotelements { |
|
return ' |
|
<functionplotelements> |
|
<spline /> |
|
</functionplotelements>'; |
|
} |
|
|
sub insert_numericalresponse { |
sub insert_numericalresponse { |
return ' |
return ' |
<numericalresponse answer=""> |
<numericalresponse answer=""> |
Line 305 sub insert_numericalresponse {
|
Line 489 sub insert_numericalresponse {
|
</numericalresponse>'; |
</numericalresponse>'; |
} |
} |
|
|
|
sub insert_externalresponse { |
|
return ' |
|
<externalresponse url="" answer="" answerdisplay="" form=""> |
|
<textfield spellcheck="none" /> |
|
</externalresponse>'; |
|
} |
|
|
sub insert_customresponse { |
sub insert_customresponse { |
return ' |
return ' |
<customresponse> |
<customresponse> |
Line 477 sub insert_matchresponse {
|
Line 668 sub insert_matchresponse {
|
<matchresponse max="10"> |
<matchresponse max="10"> |
<foilgroup options=""> |
<foilgroup options=""> |
<itemgroup> |
<itemgroup> |
|
<item> |
|
<startouttext /><endouttext /> |
|
</item> |
</itemgroup> |
</itemgroup> |
<foil> |
<foil> |
<startouttext /><endouttext /> |
<startouttext /><endouttext /> |
Line 488 sub insert_matchresponse {
|
Line 682 sub insert_matchresponse {
|
</matchresponse>'; |
</matchresponse>'; |
} |
} |
|
|
|
sub insert_startpartmarker { return '<startpartmarker />'; } |
|
sub insert_endpartmarker { return '<endpartmarker />'; } |
|
|
sub insert_displayduedate { return '<displayduedate />'; } |
sub insert_displayduedate { return '<displayduedate />'; } |
sub insert_displaytitle { return '<displaytitle />'; } |
sub insert_displaytitle { return '<displaytitle />'; } |
sub insert_hintpart { |
sub insert_hintpart { |
Line 510 sub insert_numericalhint {
|
Line 707 sub insert_numericalhint {
|
</numericalhint>'; |
</numericalhint>'; |
} |
} |
|
|
|
sub insert_reactionhint { |
|
return ' |
|
<reactionhint> |
|
</reactionhint>'; |
|
} |
|
|
|
sub insert_organichint { |
|
return ' |
|
<organichint> |
|
</organichint>'; |
|
} |
|
|
sub insert_stringhint { |
sub insert_stringhint { |
return ' |
return ' |
<stringhint> |
<stringhint> |
Line 546 sub js_change_detection {
|
Line 755 sub js_change_detection {
|
my $unsaved=&mt("There are unsaved changes"); |
my $unsaved=&mt("There are unsaved changes"); |
return (<<SCRIPT); |
return (<<SCRIPT); |
<script type="text/javascript"> |
<script type="text/javascript"> |
|
// <![CDATA[ |
var clean = true; |
var clean = true; |
var is_submit = false; |
var is_submit = false; |
var still_ask = false; |
var still_ask = false; |
Line 564 function unClean() {
|
Line 774 function unClean() {
|
clean=false; |
clean=false; |
} |
} |
window.onbeforeunload = compareForm; |
window.onbeforeunload = compareForm; |
|
// ]]> |
</script> |
</script> |
SCRIPT |
SCRIPT |
} |
} |
Line 577 sub element_change_detection {
|
Line 788 sub element_change_detection {
|
} |
} |
|
|
sub submit_ask_anyway { |
sub submit_ask_anyway { |
return ' onclick="still_ask=true;" '; |
my ($extra_action) = @_; |
|
my $resource = &Apache::loncommon::escape_single($env{'request.ambiguous'}); |
|
return ' onclick="saveScrollPosition(\''.$resource.'\');still_ask=true;'.$extra_action.';" '; |
|
} |
|
|
|
sub submit_dont_ask { |
|
my ($extra_action) = @_; |
|
my $resource = &Apache::loncommon::escape_single($env{'request.ambiguous'}); |
|
return ' onclick="saveScrollPosition(\''.$resource.'\');is_submit=true;'.$extra_action.';" '; |
|
} |
|
|
|
sub js_update_linknum { |
|
return (<<SCRIPT); |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
function updateNumber(name,index,caller,textprompt) { |
|
var pickitem = document.getElementById(name+'_'+index); |
|
var picknumtext = document.getElementById(name+'_numtext_'+index); |
|
if (pickitem.checked) { |
|
var showval = ''; |
|
if (pickitem.value != 'nochoice') { |
|
showval = pickitem.value; |
|
} |
|
var picknum=prompt(textprompt,showval); |
|
if (picknum == '' || picknum == null) { |
|
if (caller == 'check') { |
|
pickitem.checked=false; |
|
pickitem.value='nochoice'; |
|
} |
|
} else { |
|
picknum.toString(); |
|
var regexdigit=/^\\d+\$/; |
|
if (regexdigit.test(picknum)) { |
|
pickitem.value = picknum; |
|
picknumtext.innerHTML = ' <a href="javascript:updateNumber(\\''+name+'\\',\\''+index+'\\',\\'link\\',\\''+textprompt+'\\');">'+picknum+'</a>'; |
|
} else { |
|
if (caller == 'check') { |
|
pickitem.checked=false; |
|
pickitem.value='nochoice'; |
|
} |
|
return; |
|
} |
|
} |
|
} else { |
|
pickitem.value = ''; |
|
picknumtext.innerHTML = ''; |
|
} |
|
} |
|
|
|
// ]]> |
|
</script> |
|
SCRIPT |
|
|
} |
} |
|
|
sub textarea_sizes { |
sub textarea_sizes { |
Line 611 sub editfield {
|
Line 874 sub editfield {
|
my ($tag,$data,$description,$minwidth,$minheight,$usehtmlarea)=@_; |
my ($tag,$data,$description,$minwidth,$minheight,$usehtmlarea)=@_; |
|
|
my ($rows,$cols)=&textarea_sizes(\$data); |
my ($rows,$cols)=&textarea_sizes(\$data); |
if (&Apache::lonhtmlcommon::htmlareabrowser() && |
my $textareaclass; |
!&Apache::lonhtmlcommon::htmlareablocked()) { |
|
|
if (&Apache::lonhtmlcommon::htmlareabrowser() && $usehtmlarea) { |
$rows+=7; # make room for HTMLarea |
$rows+=7; # make room for HTMLarea |
$minheight+=7; # make room for HTMLarea |
$minheight+=7; # make room for HTMLarea |
|
$textareaclass = ' class="LC_richDefaultOff"'; |
} |
} |
if ($cols > 80) { $cols = 80; } |
if ($cols > 80) { $cols = 80; } |
if ($cols < $minwidth ) { $cols = $minwidth; } |
if ($cols < $minwidth ) { $cols = $minwidth; } |
if ($rows < $minheight) { $rows = $minheight; } |
if ($rows < $minheight) { $rows = $minheight; } |
if ($description) { $description=$description."<br />"; } |
if ($description) { $description='<br />'.&mt($description).'<br />'; } |
if ($usehtmlarea) { |
|
&Apache::lonhtmlcommon::add_htmlareafields('homework_edit_'. |
|
$Apache::lonxml::curdepth); |
|
} |
|
# remove typesetting whitespace from between data and the end tag |
# remove typesetting whitespace from between data and the end tag |
# to make the edit look prettier |
# to make the edit look prettier |
$data =~ s/\n?[ \t]*$//; |
$data =~ s/\n?[ \t]*$//; |
|
|
return $description."\n".'<textarea style="width:100%" rows="'.$rows. |
return $description."\n".'<textarea style="width:99%" rows="'.$rows. |
'" cols="'.$cols.'" name="homework_edit_'. |
'" cols="'.$cols.'" name="homework_edit_'. |
$Apache::lonxml::curdepth.'" id="homework_edit_'. |
$Apache::lonxml::curdepth.'" id="homework_edit_'. |
$Apache::lonxml::curdepth.'" '.&element_change_detection().'>'. |
$Apache::lonxml::curdepth.'" '.&element_change_detection(). |
|
$textareaclass.'>'. |
&HTML::Entities::encode($data,'<>&"').'</textarea>'. |
&HTML::Entities::encode($data,'<>&"').'</textarea>'. |
($usehtmlarea?&Apache::lonhtmlcommon::spelllink('lonhomework', |
($usehtmlarea?'<br />'.&Apache::lonhtmlcommon::spelllink('lonhomework', |
'homework_edit_'.$Apache::lonxml::curdepth):'')."\n"; |
'homework_edit_'.$Apache::lonxml::curdepth):'')."\n"; |
} |
} |
|
|
sub modifiedfield { |
sub modifiedfield { |
Line 724 sub hidden_arg {
|
Line 987 sub hidden_arg {
|
} |
} |
|
|
sub checked_arg { |
sub checked_arg { |
my ($description,$name,$list,$token) = @_; |
my ($description,$name,$list,$token,$onclick,$useid) = @_; |
my $result; |
my $result; |
my $optionlist=""; |
my $optionlist=""; |
my $allselected=$token->[2]{$name}; |
my $allselected=$token->[2]{$name}; |
Line 733 sub checked_arg {
|
Line 996 sub checked_arg {
|
my ($value,$text); |
my ($value,$text); |
if ( ref($option) eq 'ARRAY') { |
if ( ref($option) eq 'ARRAY') { |
$value='value="'.$$option[0].'"'; |
$value='value="'.$$option[0].'"'; |
$text=$$option[1]; |
$text=&mt($$option[1]); |
$option=$$option[0]; |
$option=$$option[0]; |
} else { |
} else { |
$text=$option; |
$text=&mt($option); |
$value='value="'.$option.'"'; |
$value='value="'.$option.'"'; |
} |
} |
$result.="<nobr><label><input type='checkbox' $value name='". |
$result.=' <span class="LC_edit_opt"><label><input type="checkbox" '.$value.' name="'. |
&html_element_name($name)."'"; |
&html_element_name($name).'"'; |
foreach my $selected (split(/,/,$allselected)) { |
foreach my $selected (split(/,/,$allselected)) { |
if ( $selected eq $option ) { |
if ( $selected eq $option ) { |
$result.=" checked='checked' "; |
$result.=' checked="checked" '; |
last; |
last; |
} |
} |
} |
} |
$result.=&element_change_detection()." />$text</label></nobr>\n"; |
if ($useid) { |
|
$result .= ' id="'.&html_element_name($name).'" '; |
|
} |
|
$result.=&element_change_detection().$onclick.' />'.$text.'</label></span>'."\n"; |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
sub text_arg { |
sub text_arg { |
my ($description,$name,$token,$size) = @_; |
my ($description,$name,$token,$size, $class) = @_; |
my $result; |
my $result; |
if (!defined $size) { $size=20; } |
if (!defined $size) { $size=20; } |
my $arg=$token->[2]{$name}; |
my $arg=$token->[2]{$name}; |
$result=&mt($description).' <input name="'.&html_element_name($name). |
$result=&mt($description).' <input name="'.&html_element_name($name). |
'" type="text" value="'.$arg.'" size="'.$size.'" '. |
'" type="text" value="'.$arg.'" size="'.$size.'" '; |
&element_change_detection().'/>'; |
if (defined $class) { |
return '<nobr>'.$result.'</nobr>'; |
$result .= 'class="' . $class . '" '; |
|
} |
|
$result .= &element_change_detection().'/>'; |
|
return ' <span class="LC_edit_opt">'.$result.'</span>'; |
} |
} |
|
|
sub select_arg { |
sub select_arg { |
Line 768 sub select_arg {
|
Line 1037 sub select_arg {
|
my $result; |
my $result; |
my $optionlist=""; |
my $optionlist=""; |
my $selected=$token->[2]{$name}; |
my $selected=$token->[2]{$name}; |
foreach my $option (@$list) { |
if (ref($list) eq 'ARRAY') { |
my ($text,$value); |
foreach my $option (@{$list}) { |
if ( ref($option) eq 'ARRAY') { |
my ($text,$value); |
$value='value="'.&HTML::Entities::encode($$option[0]).'"'; |
if (ref($option) eq 'ARRAY') { |
$text=$$option[1]; |
$value='value="'.&HTML::Entities::encode($option->[0]).'"'; |
$option=$$option[0]; |
$text=$option->[1]; |
} else { |
$option=$option->[0]; |
$text=$option; |
} else { |
$value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"'; |
$text=$option; |
} |
$value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"'; |
if ( $selected eq $option ) { |
} |
$optionlist.="<option $value selected=\"selected\">$text</option>\n"; |
if ( $selected eq $option ) { |
} else { |
$optionlist.="<option $value selected=\"selected\">".&mt($text)."</option>\n"; |
$optionlist.="<option $value >$text</option>\n"; |
} else { |
} |
$optionlist.="<option $value >".&mt($text)."</option>\n"; |
|
} |
|
} |
} |
} |
$result.='<nobr>'.$description.' <select name="'. |
$result.=' <span class="LC_edit_opt">'.&mt($description).' <select name="'. |
&html_element_name($name).'" '.&element_change_detection().' > |
&html_element_name($name).'" '.&element_change_detection().' > |
'.$optionlist.' |
'.$optionlist.' |
</select></nobr>'; |
</select></span>'; |
return $result; |
return $result; |
} |
} |
|
|
Line 797 sub select_or_text_arg {
|
Line 1068 sub select_or_text_arg {
|
my $optionlist=""; |
my $optionlist=""; |
my $found=0; |
my $found=0; |
my $selected=$token->[2]{$name}; |
my $selected=$token->[2]{$name}; |
foreach my $option (@$list) { |
if (ref($list) eq 'ARRAY') { |
my ($text,$value); |
foreach my $option (@{$list}) { |
if ( ref($option) eq 'ARRAY') { |
my ($text,$value); |
$value='value="'.&HTML::Entities::encode($$option[0]).'"'; |
if (ref($option) eq 'ARRAY') { |
$text=$$option[1]; |
$value='value="'.&HTML::Entities::encode($option->[0]).'"'; |
$option=$$option[0]; |
$text=$option->[1]; |
} else { |
$option=$option->[0]; |
$text=$option; |
} else { |
$value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"'; |
$text=$option; |
} |
$value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"'; |
if ( $selected eq $option ) { |
} |
$optionlist.="<option $value selected=\"selected\">$text</option>\n"; |
if ( $selected eq $option ) { |
$found=1; |
$optionlist.="<option $value selected=\"selected\">$text</option>\n"; |
} else { |
$found=1; |
$optionlist.="<option $value>$text</option>\n"; |
} else { |
} |
$optionlist.="<option $value>$text</option>\n"; |
|
} |
|
} |
} |
} |
$optionlist.="<option value=\"TYPEDINVALUE\"". |
$optionlist.="<option value=\"TYPEDINVALUE\"". |
((!$found)?' selected="selected"':''). |
((!$found)?' selected="selected"':''). |
Line 833 sub select_or_text_arg {
|
Line 1106 sub select_or_text_arg {
|
$description=&mt($description); |
$description=&mt($description); |
# |
# |
return (<<ENDSELECTORTYPE); |
return (<<ENDSELECTORTYPE); |
<nobr> |
<span class="LC_edit_opt"> |
$description |
$description |
<select name="$selectelement" |
<select name="$selectelement" |
onChange="if ($selectedvalue!='TYPEDINVALUE') { $hiddenvalue=$selectedvalue; $typedinvalue=''; }" > |
onchange="if ($selectedvalue!='TYPEDINVALUE') { $hiddenvalue=$selectedvalue; $typedinvalue=''; }" > |
$optionlist |
$optionlist |
</select> |
</select> |
<input type="text" size="$size" name="$typeinelement" |
<input type="text" size="$size" name="$typeinelement" |
value="$typeinvalue" |
value="$typeinvalue" |
onChange="$hiddenvalue=$typedinvalue;" |
onchange="$hiddenvalue=$typedinvalue;" |
onFocus="$selectedindex=$selecttypeinindex-1;" /> |
onfocus="$selectedindex=$selecttypeinindex-1;" /> |
<input type="hidden" name="$element" value="$selected" $change_code /> |
<input type="hidden" name="$element" value="$selected" $change_code /> |
</nobr> |
</span> |
ENDSELECTORTYPE |
ENDSELECTORTYPE |
} |
} |
|
|
Line 879 sub entercoords {
|
Line 1152 sub entercoords {
|
$data{"imagechoice.$id.formwidth"}=$width.'_'. |
$data{"imagechoice.$id.formwidth"}=$width.'_'. |
$Apache::edit::bgimgsrccurdepth; |
$Apache::edit::bgimgsrccurdepth; |
} |
} |
&Apache::lonnet::appenv(%data); |
&Apache::lonnet::appenv(\%data); |
my $text="Click Coordinates"; |
my $text="Click Coordinates"; |
my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>'; |
my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>'; |
return $result; |
return $result; |
Line 912 sub entercoord {
|
Line 1185 sub entercoord {
|
$data{"imagechoice.$id.formwidth"}=$width.'_'. |
$data{"imagechoice.$id.formwidth"}=$width.'_'. |
$Apache::edit::bgimgsrccurdepth; |
$Apache::edit::bgimgsrccurdepth; |
} |
} |
&Apache::lonnet::appenv(%data); |
&Apache::lonnet::appenv(\%data); |
my $text="Enter Coordinates"; |
my $text="Enter Coordinates"; |
if ($type eq 'polygon') { $text='Create Polygon Data'; } |
if ($type eq 'polygon') { $text='Create Polygon Data'; } |
my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>'; |
my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>'; |
Line 920 sub entercoord {
|
Line 1193 sub entercoord {
|
} |
} |
|
|
sub deletecoorddata { |
sub deletecoorddata { |
&Apache::lonnet::delenv("imagechoice\\."); |
&Apache::lonnet::delenv('imagechoice.'); |
|
} |
|
|
|
#----------------------------------------------------- browse and search links |
|
sub browse_or_search { |
|
my ($id,$mode,$titleid,$only,$crsonly,$usesearch) = @_; |
|
my $output; |
|
my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url(); |
|
if ($cnum) { |
|
my $form = 'lonhomework'; |
|
my ($element,$bretitleelement,$srchtitleelement); |
|
$element = &get_element($id,$mode); |
|
my %lt = &Apache::lonlocal::texthash ( |
|
uacf => 'Use a course file', |
|
uanf => 'Use a new file', |
|
impo => 'Import', |
|
sear => 'Search', |
|
sefi => 'Select File', |
|
upfi => 'Upload File', |
|
dire => 'Directory', |
|
news => 'New sub-directory', |
|
empd => 'No suitable resources found', |
|
); |
|
my ($importcrsres,$uploadfile,$allonly); |
|
if ($only) { |
|
$allonly = $only; |
|
if ($crsonly) { |
|
$allonly .= ','.$crsonly; |
|
} |
|
} elsif ($crsonly) { |
|
$allonly = $crsonly; |
|
} |
|
my ($numdirs,$pickfile) = |
|
&Apache::loncommon::import_crsauthor_form('coursepath_'.$element,'coursefile_'.$element,undef,$allonly,$element); |
|
$importcrsres=(<<CRSRES); |
|
<fieldset id="importcrsresform_$element" style="display:inline;"> |
|
<legend>$lt{'uacf'}</legend> |
|
<div id="hascrsres_$element" style="padding:0;clear:both;margin:0;border:0;display:none;"> |
|
<p> |
|
$pickfile |
|
</p><p> |
|
<input type="button" name="crsres_$element" value="$lt{'sefi'}" onclick="updateCrsFile(this.form,'$element');" /> |
|
</p> |
|
</div> |
|
<div id="nocrsres_$element" style="padding:0;clear:both;margin:0;border:0display:none;"> |
|
<p> |
|
$lt{'empd'} |
|
</p> |
|
</div> |
|
</fieldset> |
|
CRSRES |
|
my %subdirs; |
|
my $toppath="/priv/$cdom/$cnum"; |
|
my $exclude = &Apache::lonnet::priv_exclude(); |
|
&Apache::lonnet::recursedirs(1,1,'',$exclude,'',0,$toppath,'',\%subdirs); |
|
my $numcrsdirs = keys(%subdirs); |
|
my $pickdir = $lt{'dire'}.'<select name="crsauthorpath_'.$element.'">'."\n". |
|
'<option value="/">/</option>'."\n"; |
|
if ($numcrsdirs) { |
|
foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { |
|
$pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n"; |
|
} |
|
} |
|
$pickdir .= '</select><br />'; |
|
my $uploadfile =(<<CRSUPL); |
|
<fieldset id="uploadcrsresform_$element" style="display:inline;"> |
|
<legend>$lt{'uanf'}</legend> |
|
<p> |
|
$pickdir |
|
<span class="LC_nobreak">$lt{'news'}? |
|
<label><input type="radio" name="newsubdir_$element" value="0" onclick="toggleNewsubdir(this.form,'$element');" checked="checked" />No</label> |
|
|
|
<label><input type="radio" name="newsubdir_$element" value="1" onclick="toggleNewsubdir(this.form,'$element');" />Yes</label> |
|
</span><span id="newsubdir_$element"></span> |
|
<input type="hidden" name="newsubdirname_$element" id="newsubdirname_$element" value="" autocomplete="off" /> |
|
</p> |
|
<input type="file" id="uploadcrsres_$element" name="uploadcrsres_$element" size="40" /> |
|
<input type="hidden" id="crsuploadto_$element" name="filename_$element" value="$ENV{'REQUEST_URI'}" /> |
|
<input type="submit" id="crsupload_$element" class="LC_uploadcrsres" value="$lt{'upfi'}" /> |
|
<iframe id="crsupload_target_$element" name="crsupload_target_$element" src="" style="width:0px;height:0px;border:0px"></iframe> |
|
</fieldset> |
|
CRSUPL |
|
if ($titleid) { |
|
$bretitleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
|
$srchtitleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
|
} else { |
|
$bretitleelement=",'$only'"; |
|
} |
|
$output = '<a href="javascript:toggleChooser(document.'.$form.",'$element'".');">'. |
|
&mt('Choose File').'</a>'. |
|
'<div id="chooser_'.$element.'" style="display:none" class="LC_left_float">'. |
|
'<fieldset><legend>'.&mt('Choose File').'</legend>'. |
|
'<label><input type="radio" name="chooser_'.$element.'" value="crsres" onclick="toggleCrsFile(this.form,'."'$element'".')" />'.$lt{'uacf'}.'</label> '. |
|
'<label><input type="radio" name="chooser_'.$element.'" value="upload" onclick="toggleCrsUpload(this.form,'."'$element'".')" />'.$lt{'uanf'}.'</label> '. |
|
'<label><input type="radio" name="chooser_'.$element.'" value="import" onclick="toggleResImport(this.form,'."'$element'".');openbrowser('."'$form','$element'$bretitleelement)".'" />'.$lt{'impo'}.'</label>'; |
|
if ($usesearch) { |
|
$output .= ' <label><input type="radio" name="chooser_'.$element.'" value="search" onclick="opensearcher('."'$form','$element'$srchtitleelement".')" />'.$lt{'sear'}.'</label>'; |
|
} |
|
$output .= '<div id="chooser_'.$element.'_crsres" style="display:none">'. |
|
$importcrsres. |
|
'</div>'. |
|
'<div id="chooser_'.$element.'_upload" style="display:none">'. |
|
$uploadfile. |
|
'</div>'. |
|
'</fieldset></div>'; |
|
|
|
} else { |
|
$output = &browse($id, $mode, $titleid, $only); |
|
if ($usesearch) { |
|
$output .= ' '.&search($id, $mode, $titleid); |
|
} |
|
} |
|
return $output; |
} |
} |
|
|
#----------------------------------------------------- browse |
#----------------------------------------------------- browse |
sub browse { |
sub browse { |
# insert a link to call up the filesystem browser (lonindexer) |
# insert a link to call up the filesystem browser (lonindexer) |
my ($id, $mode, $titleid, $only) = @_; |
my ($id, $mode, $titleid, $only) = @_; |
|
my %lt = &Apache::lonlocal::texthash ( |
|
se => 'Select', |
|
); |
my $form = 'lonhomework'; |
my $form = 'lonhomework'; |
my $element; |
my $element = &get_element($id,$mode); |
if (! defined($mode) || $mode eq 'attribute') { |
|
$element = &escape("$id\_$Apache::lonxml::curdepth"); |
|
} elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> |
|
$element = &escape('homework_edit_'. |
|
$Apache::lonxml::curdepth); |
|
} |
|
my $titleelement; |
my $titleelement; |
if ($titleid) { |
if ($titleid) { |
$titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
$titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
} else { |
} else { |
$titleelement=",'$only'"; |
$titleelement=",'$only'"; |
} |
} |
my $result = <<"ENDBUTTON"; |
return <<"ENDBUTTON"; |
<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a> |
<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>$lt{'se'}</a> |
ENDBUTTON |
ENDBUTTON |
return $result; |
|
} |
} |
|
|
#----------------------------------------------------- browse |
#----------------------------------------------------- search |
sub search { |
sub search { |
# insert a link to call up the filesystem browser (lonindexer) |
# insert a link to call up the filesystem browser (lonindexer) |
my ($id, $mode, $titleid) = @_; |
my ($id, $mode, $titleid) = @_; |
my $form = 'lonhomework'; |
my $form = 'lonhomework'; |
my $element; |
my $element = &get_element($id,$mode); |
if (! defined($mode) || $mode eq 'attribute') { |
|
$element = &escape("$id\_$Apache::lonxml::curdepth"); |
|
} elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> |
|
$element = &escape('homework_edit_'. |
|
$Apache::lonxml::curdepth); |
|
} |
|
my $titleelement; |
my $titleelement; |
if ($titleid) { |
if ($titleid) { |
$titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
$titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; |
} |
} |
|
my $linktext = &mt('Search'); |
my $result = <<"ENDBUTTON"; |
my $result = <<"ENDBUTTON"; |
<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a> |
<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>$linktext</a> |
ENDBUTTON |
ENDBUTTON |
return $result; |
return $result; |
} |
} |
|
|
|
sub get_element { |
|
my ($id,$mode) = @_; |
|
my $element; |
|
if (! defined($mode) || $mode eq 'attribute') { |
|
$element = &escape("$id\_$Apache::lonxml::curdepth"); |
|
} elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> |
|
$element = &escape('homework_edit_'. |
|
$Apache::lonxml::curdepth); |
|
} |
|
return $element; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |
|
|
=head1 NAME |
|
|
|
Apache::edit - edit mode helpers |
|
|
|
=head1 SYNOPSIS |
|
|
|
Invoked by many homework and xml related modules. |
|
|
|
&Apache::edit::SUBROUTINENAME(ARGUMENTS); |
|
|
|
=head1 INTRODUCTION |
|
|
|
This module outputs HTML syntax helpful for the rendering of edit |
|
mode interfaces. |
|
|
|
This is part of the LearningOnline Network with CAPA project |
|
described at http://www.lon-capa.org. |
|
|
|
=head1 HANDLER SUBROUTINE |
|
|
|
There is no handler subroutine. |
|
|
|
=head1 OTHER SUBROUTINES |
|
|
|
=over 4 |
|
|
|
=item * |
|
|
|
initialize_edit() : initialize edit (set colordepth to zero) |
|
|
|
=item * |
|
|
|
tag_start($target,$token,$description) : provide deletion and insertion lists |
|
for the manipulation of a start tag; return a scalar string |
|
|
|
=item * |
|
|
|
tag_end($target,$token,$description) : ending syntax corresponding to |
|
&tag_start. return a scalar string. |
|
|
|
=item * |
|
|
|
start_table($token) : start table; update colordepth; return scalar string. |
|
|
|
=item * |
|
|
|
end_table() : reduce color depth; end table; return scalar string |
|
|
|
=item * |
|
|
|
start_spanning_row() : start a new table row spanning the 'edit' environment. |
|
|
|
=item * |
|
|
|
start_row() : start a new table row and element. |
|
|
|
=item * |
|
|
|
end_row() : end current table element and row. |
|
|
|
=item * |
|
|
|
movebuttons($target,$token) : move-up and move-down buttons; return scalar |
|
string |
|
|
|
=item * |
|
|
|
deletelist($target,$token) : provide a yes option in an HTML select element; |
|
return scalar string |
|
|
|
=item * |
|
|
|
handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval, |
|
$style) : respond to a user delete request by passing relevant stack |
|
and array information to various rendering functions; return a scalar string |
|
|
|
=item * |
|
|
|
get_insert_list($token) : provide an insertion list based on possibilities |
|
from lonxml; return a scalar string |
|
|
|
=item * |
|
|
|
insertlist($target,$token) : api that uses get_insert_list; |
|
return a scalar string |
|
|
|
=item * |
|
|
|
handleinsert($token) : provide an insertion list based on possibilities |
|
from lonxml; return a scalar string |
|
|
|
=item * |
|
|
|
get_insert_list($token) : provide an insertion list based on possibilities |
|
from lonxml; return a scalar string |
|
|
|
=item * |
|
browse($elementname) : provide a link which will open up the filesystem |
|
browser (lonindexer) and, once a file is selected, place the result in |
|
the form element $elementname. |
|
|
|
=item * |
|
search($elementname) : provide a link which will open up the filesystem |
|
searcher (lonsearchcat) and, once a file is selected, place the result in |
|
the form element $elementname. |
|
|
|
=item * |
|
editline(tag,data,description,size): Provide a <input type="text" ../> for |
|
single-line text entry. This is to be used for text enclosed by tags, not |
|
arguements/parameters associated with a tag. |
|
|
|
=back |
|
|
|
incomplete... |
|
|
|
=cut |
|