Skip to content

Commit

Permalink
Item11562:
Browse files Browse the repository at this point in the history
   * added =$origvalues= to display unmapped values of +values formfields
   * added =prefix= parameter
   * protecting the editor of a formfield by surrounding it with <literal> tags



git-svn-id: http://svn.foswiki.org/trunk/FlexFormPlugin@14078 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Feb 24, 2012
1 parent 700dde3 commit e6e0f7c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 25 deletions.
9 changes: 8 additions & 1 deletion data/System/FlexFormPlugin.txt
Expand Up @@ -29,6 +29,7 @@ In addition, !FlexFormPlugin facilitates the extraction of field default values
| excludeattr="..." | regular expression field attributes must match to be excluded from the output | undefined |
| exclude="..." | regular expression fieldnames must match to be excluded from the output | undefined |
| fields="&lt;fieldname1>, &lt;fieldname2>, ..." | list of formfields to render the interface for | all known formfields |
| prefix="..." | adds a prefix string to the name while rendering the editor for a formfield |
| footer="..." | footer string to apped to the output | &lt;empty string> |
| format="..." | format string to render each formfield with, more info below | =$edit$mandatory= |
| form="..." | topic name containing the !DataForm definition | form found at the base topic |
Expand Down Expand Up @@ -101,13 +102,15 @@ The =format= parameter may contain the following pseudo-variables:
* =$value=: current value of the formfield; for =+value= formfields this is the _mapped_ value use =$origvalue= to get the original one
* =$origvalue=: current value of the formfield; for =+value= formfields this is the original _unmapped_ value of the formfield
* =$values=: list of all allowed values for the formfield as defined in the !DataForm definition
* =$origvalues=: list of all allowed values; for =+value= formfields this is the original _unmapped_ value of the formfield
* =$default=: this is the default value if no value is specified in the topic itself

---++ Examples

<verbatim>
%RENDERFOREDIT{
form="%USERSWEB%.UserForm"
topic="Sandbox.TestTopic1"
exclude="Email|Comment|State"
FirstName_value="Horst"
LastName_value="Buchholz"
Expand All @@ -117,6 +120,7 @@ The =format= parameter may contain the following pseudo-variables:

%RENDERFOREDIT{
form="%USERSWEB%.UserForm"
topic="Sandbox.TestTopic1"
exclude="Email|Comment|State"
FirstName_value="Horst"
LastName_value="Buchholz"
Expand All @@ -142,11 +146,14 @@ Many thanks to the following sponsors for supporting this work:
* Acknowledge any sponsors here

| Author(s): | Foswiki:MichaelDaum|
| Copyright: | &copy; 2009-2011 Michael Daum http://michaeldaumconsulting.com |
| Copyright: | &copy; 2009-2012 Michael Daum http://michaeldaumconsulting.com |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 24 Feb 2012: | added =$origvalues= to display unmapped values of +values formfields; \
added =prefix= parameter; \
protecting the editor of a formfield by surrounding it with &lt;literal> tags |
| 25 Aug 2011: | fixed rendering +value formields yet again; added =$origvalue= |
| 18 Mar 2011: | added autolink param; \
fixed getting default values; \
Expand Down
31 changes: 15 additions & 16 deletions lib/Foswiki/Plugins/FlexFormPlugin.pm
Expand Up @@ -29,8 +29,15 @@ our $baseTopic;
sub initPlugin {
($baseTopic, $baseWeb) = @_;

Foswiki::Func::registerTagHandler('RENDERFOREDIT', \&handleRENDERFOREDIT);
Foswiki::Func::registerTagHandler('RENDERFORDISPLAY', \&handleRENDERFORDISPLAY);
Foswiki::Func::registerTagHandler('RENDERFOREDIT', sub {
init();
return Foswiki::Plugins::FlexFormPlugin::Core::handleRENDERFOREDIT(@_);
});

Foswiki::Func::registerTagHandler('RENDERFORDISPLAY', sub {
init();
return Foswiki::Plugins::FlexFormPlugin::Core::handleRENDERFORDISPLAY(@_);
});

$doneInit = 0;
return 1;
Expand All @@ -44,24 +51,16 @@ sub init {
Foswiki::Plugins::FlexFormPlugin::Core::init($baseWeb, $baseTopic);
}

##############################################################################
sub handleRENDERFOREDIT {
init();
Foswiki::Plugins::FlexFormPlugin::Core::handleRENDERFOREDIT(@_);
}

##############################################################################
sub handleRENDERFORDISPLAY {
init();
Foswiki::Plugins::FlexFormPlugin::Core::handleRENDERFORDISPLAY(@_);
}


###############################################################################
# deprecated to be used as a finish handler
sub modifyHeaderHandler {
init();
Foswiki::Plugins::FlexFormPlugin::Core::finish(@_);
return Foswiki::Plugins::FlexFormPlugin::Core::finish(@_);
}

###############################################################################
sub completePageHandler {
$_[0] =~ s/<\/?literal>//g;
}


Expand Down
62 changes: 54 additions & 8 deletions lib/Foswiki/Plugins/FlexFormPlugin/Core.pm
Expand Up @@ -194,6 +194,23 @@ sub handleRENDERFORDISPLAY {
}
}

my $fieldOrigAllowedValues = '';
if ($field->can('getOptions')) {
#writeDebug("can getOptions");
my $options = $field->getOptions();
if ($options) {
#writeDebug("options=$options");
$fieldOrigAllowedValues = join($theValueSep, @$options);
}
} else {
#writeDebug("can't getOptions ... fallback to field->{value}");
# fallback to field->value
my $options = $field->{value};
if ($options) {
$fieldOrigAllowedValues = join($theValueSep, split(/\s*,\s*/, $options));
}
}

my $fieldDefault = '';
if ($field->can('getDefaultValue')) {
$fieldDefault = $field->getDefaultValue() || '';
Expand Down Expand Up @@ -244,7 +261,7 @@ sub handleRENDERFORDISPLAY {
$field = $fieldClone;
}

next if $theHideEmpty && !$fieldValue;
next if $theHideEmpty && (!defined($fieldValue) || $fieldValue eq '');
$fieldValue = $fieldDefault unless defined $fieldValue;

next if $theInclude && $fieldName !~ /^($theInclude)$/;
Expand All @@ -263,6 +280,7 @@ sub handleRENDERFORDISPLAY {

# some must be expanded before renderForDisplay
$line =~ s/\$values\b/$fieldAllowedValues/g;
$line =~ s/\$origvalues\b/$fieldOrigAllowedValues/g;
$line =~ s/\$title\b/$fieldTitle/g;

$line = $field->renderForDisplay($line, $fieldValue, {
Expand Down Expand Up @@ -322,6 +340,7 @@ sub handleRENDERFOREDIT {
my $theHidden = $params->{hidden};
my $theHiddenFormat = $params->{hiddenformat};
my $theSort = Foswiki::Func::isTrue($params->{sort}, 0);
my $thePrefix = $params->{prefix};

if (!defined($theFormat) && !defined($theHeader) && !defined($theFooter)) {
$theHeader = '<div class=\'foswikiFormSteps\'>';
Expand Down Expand Up @@ -393,13 +412,18 @@ sub handleRENDERFOREDIT {
#writeDebug("selectedFields=@selectedFields");

my @result = ();
foreach my $field (@selectedFields) {
foreach my $field (@selectedFields) {
next unless $field;

my $fieldExtra = '';
my $fieldEdit = '';

my $fieldName = $field->{name};
my $origFieldName = $field->{name};
if (defined $thePrefix) {
$field->{name} = $thePrefix.$fieldName;
}

my $fieldType = $field->{type};
my $fieldSize = $field->{size};
my $fieldAttrs = $field->{attributes};
Expand All @@ -411,23 +435,41 @@ sub handleRENDERFOREDIT {
my $fieldAllowedValues = '';
# CAUTION: don't use field->getOptions() on a +values field as that won't return the full valueMap...only the value part, but not the title map
if ($field->can('getOptions') && $field->{type} !~ /\+values/) {
#writeDebug("can getOptions");
#writeDebug("can getOptions for $fieldName");
my $options = $field->getOptions();
if ($options) {
#writeDebug("options=$options");
writeDebug("options=$options");
$fieldAllowedValues = join($theValueSep, @$options);
}
} else {
#writeDebug("can't getOptions ... fallback to field->{value}");
#writeDebug("can't getOptions ... fallback to field->{value} for $fieldName");
# fallback to field->value
my $options = $field->{value};
if ($options) {
$fieldAllowedValues = join($theValueSep, split(/\s*,\s*/, $options));
}
}

#writeDebug("fieldAllowedValues=$fieldAllowedValues");

# get the list of all allowed values without any +values mapping applied
my $fieldOrigAllowedValues = '';
if ($field->can('getOptions')) {
writeDebug("can getOptions for $fieldName");
my $options = $field->getOptions();
if ($options) {
#writeDebug("options=".join(";", @$options));
$fieldOrigAllowedValues = join($theValueSep, @$options);
}
} else {
writeDebug("can't getOptions ... fallback to field->{value} for $fieldName");
# fallback to field->value
my $options = $field->{value};
if ($options) {
$fieldOrigAllowedValues = join($theValueSep, split(/\s*,\s*/, $options));
}
}
writeDebug("fieldOrigAllowedValues=$fieldOrigAllowedValues");

# get the default value
my $fieldDefault = '';
if ($field->can('getDefaultValue')) {
Expand Down Expand Up @@ -500,7 +542,7 @@ sub handleRENDERFOREDIT {
next if $theIncludeAttr && $fieldAttrs !~ /^($theIncludeAttr)$/;
next if $theExcludeAttr && $fieldAttrs =~ /^($theExcludeAttr)$/;

unless ($fieldValue) {
unless (defined $fieldValue) {
$fieldValue = "\0"; # prevent dropped value attr in CGI.pm
}

Expand Down Expand Up @@ -562,6 +604,7 @@ sub handleRENDERFOREDIT {
$line =~ s/\$size\b/$fieldSize/g;
$line =~ s/\$attrs\b/$fieldAttrs/g;
$line =~ s/\$values\b/$fieldAllowedValues/g;
$line =~ s/\$origvalues\b/$fieldOrigAllowedValues/g;
$line =~ s/\$(orig)?value\b/$fieldValue/g;
$line =~ s/\$default\b/$fieldDefault/g;
$line =~ s/\$tooltip\b/$fieldDescription/g;
Expand All @@ -573,6 +616,7 @@ sub handleRENDERFOREDIT {

# cleanup
$fieldClone->finish() if defined $fieldClone;
$field->{name} = $origFieldName if defined $origFieldName;
}


Expand All @@ -582,7 +626,9 @@ sub handleRENDERFOREDIT {
$result =~ s/\$perce?nt/%/g;
$result =~ s/\$dollar/\$/g;

return '<noautolink>'.$result.'</noautolink>';
#print STDERR "result=$result\n";

return '<literal><noautolink>'.$result.'</noautolink></literal>';
}

##############################################################################
Expand Down

0 comments on commit e6e0f7c

Please sign in to comment.