';
- 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;
+ my ($description,$name,$list,$token,$size) = @_;
+ my $result;
+ my $optionlist="";
+ my $found=0;
+ my $selected=$token->[2]{$name};
+ 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
+
+
+
+
+ENDSELECTORTYPE
+}
+
+#----------------------------------------------------- image coordinates
+# single image coordinates, x, y
+sub entercoords {
+ my ($idx,$idy,$mode,$width,$height) = @_;
+ unless ($Apache::edit::bgimgsrc) { return ''; }
+ if ($idx) { $idx.='_'; }
+ if ($idy) { $idy.='_'; }
+ 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 = &escape("$Apache::lonxml::curdepth");
+ } elsif ($mode eq 'textnode') { # for data between ...
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ 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) {
+ $data{"imagechoice.$id.formheight"}=$height.'_'.
+ $Apache::edit::bgimgsrccurdepth;
+ }
+ if ($width) {
+ $data{"imagechoice.$id.formwidth"}=$width.'_'.
+ $Apache::edit::bgimgsrccurdepth;
+ }
+ &Apache::lonnet::appenv(%data);
+ my $text="Click Coordinates";
+ my $result=''.$text.'';
+ return $result;
+}
+
+# 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=&escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
+ my $form = 'lonhomework';
+ my $element;
+ if (! defined($mode) || $mode eq 'attribute') {
+ $element = &escape("$idx\_$Apache::lonxml::curdepth");
+ } elsif ($mode eq 'textnode') { # for data between ...
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ 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) {
+ $data{"imagechoice.$id.formheight"}=$height.'_'.
+ $Apache::edit::bgimgsrccurdepth;
+ }
+ if ($width) {
+ $data{"imagechoice.$id.formwidth"}=$width.'_'.
+ $Apache::edit::bgimgsrccurdepth;
+ }
+ &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, $titleid, $only) = @_;
+ my $form = 'lonhomework';
+ my $element;
+ if (! defined($mode) || $mode eq 'attribute') {
+ $element = &escape("$id\_$Apache::lonxml::curdepth");
+ } elsif ($mode eq 'textnode') { # for data between ...
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ my $titleelement;
+ if ($titleid) {
+ $titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
} else {
- $optionlist.="\n";
+ $titleelement=",'$only'";
}
- }
- $optionlist.="\n";
- if ($found) {
- $result.=$description.' |
';
- } else {
- $result.=&text_arg($description,$name,$token,$size);
- }
- return $result;
+ my $result = <<"ENDBUTTON";
+Select
+ENDBUTTON
+ return $result;
+}
+
+#----------------------------------------------------- browse
+sub search {
+ # insert a link to call up the filesystem browser (lonindexer)
+ my ($id, $mode, $titleid) = @_;
+ my $form = 'lonhomework';
+ my $element;
+ if (! defined($mode) || $mode eq 'attribute') {
+ $element = &escape("$id\_$Apache::lonxml::curdepth");
+ } elsif ($mode eq 'textnode') { # for data between ...
+ $element = &escape('homework_edit_'.
+ $Apache::lonxml::curdepth);
+ }
+ my $titleelement;
+ if ($titleid) {
+ $titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
+ }
+ my $result = <<"ENDBUTTON";
+Search
+ENDBUTTON
+ return $result;
}
+
+
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
|