--- loncom/homework/edit.pm 2003/09/10 22:03:40 1.57.2.1
+++ loncom/homework/edit.pm 2013/07/04 16:35:07 1.147
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.57.2.1 2003/09/10 22:03:40 albertel Exp $
+# $Id: edit.pm,v 1.147 2013/07/04 16:35:07 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,14 +25,120 @@
#
# http://www.lon-capa.org/
#
-# 3/20 Guy
-# 01/10/02 Matthew
-# 03/06/02 Matthew
+
+=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 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;
use strict;
-use Apache::lonnet();
+use Apache::lonnet;
use HTML::Entities();
+use Apache::lonlocal;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
# Global Vars
# default list of colors to use in editing
@@ -45,456 +151,779 @@ $Apache::edit::bgimgsrc='';
$Apache::edit::bgimgsrccurdepth='';
sub initialize_edit {
- $Apache::edit::colordepth=0;
- @Apache::edit::inserttag=();
+ $Apache::edit::colordepth=0;
+ @Apache::edit::inserttag=();
}
sub tag_start {
- my ($target,$token,$description) = @_;
- my $result='';
- if ($target eq "edit") {
- my $tag=$token->[1];
- if (!$description) {
- $description=&Apache::lonxml::description($token);
- if (!$description) { $description="<$tag>"; }
- }
- $result.= &start_table($token)."
$description
-
Delete".
- &deletelist($target,$token)
- ."
-
".
- &insertlist($target,$token).&end_row().&start_spanning_row();
+ my ($target,$token,$description) = @_;
+ my $result='';
+ if ($target eq "edit") {
+ my $tag=$token->[1];
+ if (!$description) {
+ $description=&Apache::lonxml::description($token);
+ if (!$description) { $description="<$tag>"; }
+ }
+ $result.= &start_table($token)."
'; }
sub movebuttons {
- my ($target,$token) = @_;
- my $result='';
- $result.='';
- return $result;
+ my ($target,$token) = @_;
+ my $result='';
+ $result.='';
+ return $result;
}
sub deletelist {
- my ($target,$token) = @_;
- my $result = "';
return $result;
}
@@ -556,107 +1019,154 @@ sub select_or_text_arg {
my $optionlist="";
my $found=0;
my $selected=$token->[2]{$name};
- foreach my $option (@$list) {
- my ($text,$value);
- if ( ref($option) eq 'ARRAY') {
- $value='value="'.$$option[0].'"';
- $text=$$option[1];
- $option=$$option[0];
- } else {
- $text=$option;
- $value='value="'.$option.'"';
- }
- if ( $selected eq $option ) {
- $optionlist.="\n";
- $found=1;
- } else {
- $optionlist.="\n";
- }
- }
- $optionlist.="\n";
- if (($found) || (!$selected)) {
- $result.=$description.'
- '.$optionlist.'
- ';
- } else {
- $result.=&text_arg($description,$name,$token,$size);
- }
- return ''.$result.'';
+ if (ref($list) eq 'ARRAY') {
+ foreach my $option (@{$list}) {
+ my ($text,$value);
+ if (ref($option) eq 'ARRAY') {
+ $value='value="'.&HTML::Entities::encode($option->[0]).'"';
+ $text=$option->[1];
+ $option=$option->[0];
+ } else {
+ $text=$option;
+ $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
+ }
+ if ( $selected eq $option ) {
+ $optionlist.="\n";
+ $found=1;
+ } else {
+ $optionlist.="\n";
+ }
+ }
+ }
+ $optionlist.="\n";
+#
+ my $change_code=&element_change_detection();
+ my $element=&html_element_name($name);
+ my $selectelement='select_list_'.$element;
+ my $typeinelement='type_in_'.$element;
+ my $typeinvalue=($found?'':$selected);
+#
+ my $hiddenvalue='this.form.'.$element.'.value';
+ my $selectedindex='this.form.'.$selectelement.'.selectedIndex';
+ my $selectedvalue='this.form.'.$selectelement.
+ '.options['.$selectedindex.'].value';
+ my $typedinvalue='this.form.'.$typeinelement.'.value';
+ my $selecttypeinindex='this.form.'.$selectelement.'.options.length';
+ $description=&mt($description);
+#
+ return (<
+$description
+
+$optionlist
+
+
+
+
+ENDSELECTORTYPE
}
#----------------------------------------------------- image coordinates
# single image coordinates, x, y
sub entercoords {
- my ($idx,,$idy,$mode,$width,$height) = @_;
+ my ($idx,$idy,$mode,$width,$height) = @_;
unless ($Apache::edit::bgimgsrc) { return ''; }
if ($idx) { $idx.='_'; }
if ($idy) { $idy.='_'; }
- my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
+ my $bgfile=&escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
my $form = 'lonhomework';
my $element;
if (! defined($mode) || $mode eq 'attribute') {
- $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
+ $element = &escape("$Apache::lonxml::curdepth");
} elsif ($mode eq 'textnode') { # for data between ...
- $element = &Apache::lonnet::escape('homework_edit_'.
+ $element = &escape('homework_edit_'.
$Apache::lonxml::curdepth);
}
- my $formheight='';
+ my $id=$Apache::lonxml::curdepth;
+ my %data=("imagechoice.$id.type" =>'point',
+ "imagechoice.$id.formname" =>$form,
+ "imagechoice.$id.formx" =>"$idx$element",
+ "imagechoice.$id.formy" =>"$idy$element",
+ "imagechoice.$id.file" =>$bgfile,
+ "imagechoice.$id.formcoord" =>$element);
if ($height) {
- $formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
+ $data{"imagechoice.$id.formheight"}=$height.'_'.
+ $Apache::edit::bgimgsrccurdepth;
}
- my $formwidth='';
if ($width) {
- $formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
+ $data{"imagechoice.$id.formwidth"}=$width.'_'.
+ $Apache::edit::bgimgsrccurdepth;
}
- my $result = <<"ENDBUTTON";
-Click Coordinates
-ENDBUTTON
+ &Apache::lonnet::appenv(\%data);
+ my $text="Click Coordinates";
+ my $result=''.$text.'';
return $result;
}
-# coordinate pair (x1,y1)-(x2,y2)
-sub entercoordpair {
- my ($id,$mode,$width,$height) = @_;
+# coordinates (x1,y1)-(x2,y2)...
+# mode can be either box, or polygon
+sub entercoord {
+ my ($idx,$mode,$width,$height,$type) = @_;
unless ($Apache::edit::bgimgsrc) { return ''; }
- my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
+ my $bgfile=&escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
my $form = 'lonhomework';
my $element;
if (! defined($mode) || $mode eq 'attribute') {
- $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
+ $element = &escape("$idx\_$Apache::lonxml::curdepth");
} elsif ($mode eq 'textnode') { # for data between ...
- $element = &Apache::lonnet::escape('homework_edit_'.
+ $element = &escape('homework_edit_'.
$Apache::lonxml::curdepth);
}
- my $formheight='';
+ my $id=$Apache::lonxml::curdepth;
+ my %data=("imagechoice.$id.type" =>$type,
+ "imagechoice.$id.formname" =>$form,
+ "imagechoice.$id.file" =>$bgfile,
+ "imagechoice.$id.formcoord" =>$element);
if ($height) {
- $formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
+ $data{"imagechoice.$id.formheight"}=$height.'_'.
+ $Apache::edit::bgimgsrccurdepth;
}
- my $formwidth='';
if ($width) {
- $formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
+ $data{"imagechoice.$id.formwidth"}=$width.'_'.
+ $Apache::edit::bgimgsrccurdepth;
}
- my $result = <<"ENDBUTTON";
-Click Coordinate Pair
-ENDBUTTON
+ &Apache::lonnet::appenv(\%data);
+ my $text="Enter Coordinates";
+ if ($type eq 'polygon') { $text='Create Polygon Data'; }
+ my $result=''.$text.'';
return $result;
}
+
+sub deletecoorddata {
+ &Apache::lonnet::delenv('imagechoice.');
+}
+
#----------------------------------------------------- browse
sub browse {
# insert a link to call up the filesystem browser (lonindexer)
- my ($id, $mode) = @_;
+ my ($id, $mode, $titleid, $only) = @_;
my $form = 'lonhomework';
my $element;
if (! defined($mode) || $mode eq 'attribute') {
- $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
+ $element = &escape("$id\_$Apache::lonxml::curdepth");
} elsif ($mode eq 'textnode') { # for data between ...
- $element = &Apache::lonnet::escape('homework_edit_'.
- $Apache::lonxml::curdepth);
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ my $titleelement;
+ if ($titleid) {
+ $titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
+ } else {
+ $titleelement=",'$only'";
}
my $result = <<"ENDBUTTON";
-Select
+Select
ENDBUTTON
return $result;
}
@@ -664,17 +1174,21 @@ ENDBUTTON
#----------------------------------------------------- browse
sub search {
# insert a link to call up the filesystem browser (lonindexer)
- my ($id, $mode) = @_;
+ my ($id, $mode, $titleid) = @_;
my $form = 'lonhomework';
my $element;
if (! defined($mode) || $mode eq 'attribute') {
- $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
+ $element = &escape("$id\_$Apache::lonxml::curdepth");
} elsif ($mode eq 'textnode') { # for data between ...
- $element = &Apache::lonnet::escape('homework_edit_'.
+ $element = &escape('homework_edit_'.
$Apache::lonxml::curdepth);
}
+ my $titleelement;
+ if ($titleid) {
+ $titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
+ }
my $result = <<"ENDBUTTON";
-Search
+Search
ENDBUTTON
return $result;
}
@@ -683,119 +1197,4 @@ ENDBUTTON
1;
__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 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