--- loncom/interface/lonhelper.pm 2009/06/12 15:31:30 1.174
+++ loncom/interface/lonhelper.pm 2010/11/09 18:22:56 1.180.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.174 2009/06/12 15:31:30 bisitz Exp $
+# $Id: lonhelper.pm,v 1.180.2.3 2010/11/09 18:22:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -571,7 +571,7 @@ sub process {
# 4: Render the current state to the screen as an HTML page.
sub display {
my $self = shift;
-
+ my $footer = shift;
my $state = $self->{STATES}{$self->{STATE}};
my $result = "";
@@ -606,74 +606,62 @@ sub display {
# FIXME: This should be parameterized, not concatenated - Jeremy
- if (!$state->overrideForm()) { $result.='
FOOTER
- $result .= &Apache::loncommon::end_page();
+ $result .= $footer.&Apache::loncommon::end_page();
# Handle writing out the vars to the file
my $file = Apache::File->new('>'.$self->{FILENAME});
print $file $self->_varsInFile();
@@ -1488,9 +1476,9 @@ BUTTONS
HTML::Entities::encode($choice->[1],"<>&\"'")
. "'";
if ($checkedChoices{$choice->[1]}) {
- $result .= " checked='checked' ";
+ $result .= " checked='checked'";
}
- $result .= qq{id="id$id"};
+ $result .= qq{ id="id$id"};
my $choiceLabel = $choice->[0];
if ($choice->[3]) { # if we need to evaluate this choice
$choiceLabel = "sub { my $helper = shift; my $state = shift;" .
@@ -1498,7 +1486,7 @@ BUTTONS
$choiceLabel = eval($choiceLabel);
$choiceLabel = &$choiceLabel($helper, $self);
}
- $result .= "/>
".qq{
".qq{
";
if ($choice->[4]) {
$result .='
: Allows you to add optional elements to the
+ resource chooser currently these can be a checkbox, or a text entry
+ or hidden (see the 'type' attribute below).
+ the following attributes are supported by this tag:
+
+=over 4
+
+=item * type=control-type : determines the type of control displayed.
+ This can be one of the following types: 'checkbox' provides a true/false
+ checkbox. 'text' provides a text entry control. 'hidden' provides a
+ hidden form element that returns the name of the resource for each
+ element of the text box.
+
+=item * text=header-text : provides column header text for the option.
+
+=item * variable=helpervar : provides a helper variable to contain the
+ value of the input control for each resource. In general, the result
+ will be a set of values separated by ||| for the checkbox the value between
+ the |||'s will either be empty, if the box is not checked, or the resource
+ name if checked. For the text entry, the values will be the text in the
+ text box. This could be empty. Hidden elements unconditionally provide
+ the resource name for each row of the chooser and allow you to therefore
+ correlate text entries to their resources.
+ The helper variable can be initialized by the user code to pre-load values
+ into the controls:
+
+=over 4
+
+
+=item * Preloading checkboxes : Set the helper variable to the value you
+ would have gotten from the control if it had been manually set as desired.
+
+=item * Preloading text entries : Set the helper variable to triple pipe
+ separated values where each value is of the form resource-name=value
+
+=item * Preloading hidden fields : These cannot be pre-loaded and will always
+ be pipe separated resource names.
+
+=back
+
+
+=back
+
=back
=cut
@@ -2207,20 +2238,42 @@ sub start_option {
if (!defined($paramHash->{OPTION_TEXTS})) {
$paramHash->{OPTION_TEXTS} = [ ];
$paramHash->{OPTION_VARS} = [ ];
+ $paramHash->{OPTION_TYPES} = [ ];
}
+ # We can have an attribute: type which can have the
+ # values: "checkbox" or "text" which defaults to
+ # checkbox allowing us to change the type of input
+ # for the option:
+ #
+ my $input_widget_type = 'checkbox';
+ if(defined($token->[2]{'type'})) {
+ my $widget_type = $token->[2]{'type'};
+ if ($widget_type eq 'text') { # only accept legal alternatives
+ $input_widget_type = $widget_type; # Illegals are checks.
+ } elsif ($widget_type eq 'hidden') {
+ $input_widget_type = $widget_type;
+ }
+ }
+
# OPTION_TEXTS is a list of the text attribute
# values used to create column headings.
# OPTION_VARS is a list of the variable names, used to create the checkbox
# inputs.
+ # OPTION_TYPES is a list of the option types:
+ #
# We're ok with empty elements. as place holders
# Although the 'variable' element should really exist.
#
+
my $option_texts = $paramHash->{OPTION_TEXTS};
my $option_vars = $paramHash->{OPTION_VARS};
+ my $option_types = $paramHash->{OPTION_TYPES};
push(@$option_texts, $token->[2]{'text'});
push(@$option_vars, $token->[2]{'variable'});
+ push(@$option_types, $input_widget_type);
+
# Need to create and declare the option variables as well to make them
# persistent.
@@ -2296,6 +2349,7 @@ BUTTONS
my $multichoice = $self->{'multichoice'};
my $option_vars = $self->{OPTION_VARS};
my $option_texts = $self->{OPTION_TEXTS};
+ my $option_types = $self->{OPTION_TYPES};
my $addparts = $self->{'addparts'};
my $headings_done = 0;
@@ -2354,17 +2408,52 @@ BUTTONS
my $resource_name =
HTML::Entities::encode($raw_name,"<>&\"'");
if($option_vars) {
+ my $option_num = 0;
foreach my $option_var (@$option_vars) {
+ my $option_type = $option_types->[$option_num];
+ $option_num++;
my $var_value = "\|\|\|" . $helper->{VARS}->{$option_var} .
"\|\|\|";
my $checked ="";
if($var_value =~ /\Q|||$raw_name|||\E/) {
$checked = "checked='checked'";
}
- $col .=
- "
";
+ if ($option_type eq 'text') {
+ #
+ # For text's the variable value is a ||| separated set of
+ # resource_name=value
+ #
+ my @values = split(/\|\|\|/, $helper->{VARS}->{$option_var});
+
+ # Normal practice would be to toss this in a hash but
+ # the only thing that saves is the compare in the loop
+ # below and for all but one case we'll break out of the loop
+ # before it completes.
+
+ my $text_value = ''; # In case there's no match.
+ foreach my $value (@values) {
+ my ($res, $skip) = split(/=/, $value);
+ if($res eq $resource_name) {
+ $text_value = $skip;
+ last;
+ }
+ }
+ # TODO: add an attribute to