Skip to content

Commit

Permalink
Item14019: clean up formfield title before ...
Browse files Browse the repository at this point in the history
... trying to translate it

also, add hideempty to RENDERFOREDIT
  • Loading branch information
MichaelDaum committed Mar 8, 2016
1 parent bd1bdbe commit e15ef2f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 40 deletions.
33 changes: 17 additions & 16 deletions data/System/FlexFormPlugin.txt
@@ -1,6 +1,6 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418733456" format="1.1" version="1"}%
---+!! %TOPIC%
%$SHORTDESCRIPTION%
%FORMFIELD{"Description"}%

%TOC%

Expand Down Expand Up @@ -40,6 +40,7 @@ any topic actually using it. This may be used to provide more defailed insights
| form="..." | topic name containing the !DataForm definition | form found at the base topic |
| header="..." | header string to be put in front of the output | <empty string> |
| hidden="..." | those fields that match this regular expression will be rendered hidden | undefined |
| hideempty="on/off" | hide empty formfields | off |
| includeattr="..." | regular expression field attributes must match to be included in the output | undefined |
| include="..." | regular expression fieldnames must match to be included in the output | undefined |
| mandatory="..." | string to be inserted when a field is mandatory | <span class='foswikiAlert'>**</span> |
Expand Down Expand Up @@ -175,18 +176,12 @@ Note that the actual results may vary depending on the formfield type of the !Da
---++ Installation Instructions
%$INSTALL_INSTRUCTIONS%

---++ Info

<!--
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
-->
---++ Dependencies
%$DEPENDENCIES%

| Author(s): | Foswiki:MichaelDaum|
| Copyright: | &copy; 2009-2015 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; |
---++ Change History
| 08 Mar 2016: | clean up formfield title before trying to translate it; \
added =hideempty= for RENDERFOREDIT |
| 17 Jul 2015: | fixed use of =param()= in list context |
| 24 Mar 2015: | working around encoding problems with CGI >= 4.11 |
| 12 Mar 2015: | restructured code to offer a proper perl api |
Expand Down Expand Up @@ -226,8 +221,14 @@ Note that the actual results may vary depending on the formfield type of the !Da
| 11 Mar 2010: | Foswiki:Main.MartinCleaver - added ability to extract allowed values of a field Foswiki:Tasks.Item8671 |
| 10 Mar 2010: | added fine-grained control over each formfield, i.e. remapping of the formfield type |
| 08 Mar 2010: | initial release |
| Dependencies: | %$DEPENDENCIES% |
| Home page: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |

<!-- Do _not_ attempt to edit this topic; it is auto-generated. -->
%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Foswiki:MichaelDaum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2009-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Release" title="Release" value="%$RELEASE%"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%TOPIC%"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%TOPIC%"}%
%META:FIELD{name="Version" title="Version" value="%$VERSION%"}%
6 changes: 3 additions & 3 deletions lib/Foswiki/Plugins/FlexFormPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2015 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2016 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -18,8 +18,8 @@ package Foswiki::Plugins::FlexFormPlugin;
use strict;
use warnings;

our $VERSION = '5.10';
our $RELEASE = '24 Mar 2015';
our $VERSION = '5.20';
our $RELEASE = '08 Mar 2016';
our $SHORTDESCRIPTION = 'Flexible way to render <nop>DataForms';
our $NO_PREFS_IN_TOPIC = 1;
our $renderForEditInstance;
Expand Down
3 changes: 2 additions & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin/Base.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2015 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2016 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -85,6 +85,7 @@ sub translate {
sub translateField {
my ($this, $field, $web, $topic) = @_;


return unless $field;
return unless $field->{type} =~ /\+values/;
return unless Foswiki::Func::getContext()->{MultiLingualPluginEnabled};
Expand Down
16 changes: 10 additions & 6 deletions lib/Foswiki/Plugins/FlexFormPlugin/RenderForDisplay.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2015 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2016 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -226,8 +226,8 @@ sub handle {
$field = $fieldClone;
}

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

next if $theInclude && $fieldName !~ /$theInclude/;
next if $theExclude && $fieldName =~ /$theExclude/;
Expand All @@ -242,12 +242,16 @@ sub handle {
$line = '<noautolink>' . $line . '</noautolink>' unless $fieldAutolink;

$fieldTitle = $fieldTitles->{$fieldName} if $fieldTitles && $fieldTitles->{$fieldName};

# clean up
$fieldTitle =~ s/^\[\[([^]]+)\]\]$/$1/g;

$fieldTitle = $this->translate($fieldTitle, $theFormWeb, $theForm);

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

# For Foswiki > 1.2, treat $value ourselves to get a consistent
# behavior across all releases:
Expand Down Expand Up @@ -276,12 +280,12 @@ sub handle {
$line =~ s/\$type\b/$fieldType/g;
$line =~ s/\$size\b/$fieldSize/g;
$line =~ s/\$attrs\b/$fieldAttrs/g;
$line =~ s/\$value(\(display\))?\b/$fieldValue/g;
$line =~ s/\$origvalue\b/$origValue/g;
$line =~ s/\$default\b/$fieldDefault/g;
$line =~ s/\$(tooltip|description)\b/$fieldDescription/g;
$line =~ s/\$title\b/$fieldTitle/g;
$line =~ s/\$form\b/$formTitle/g;
$line =~ s/\$default\b/$fieldDefault/g;
$line =~ s/\$value(\(display\))?\b/$fieldValue/g;
$line =~ s/\$origvalue\b/$origValue/g;

push @result, $line;

Expand Down
38 changes: 25 additions & 13 deletions lib/Foswiki/Plugins/FlexFormPlugin/RenderForEdit.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2015 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2016 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -51,8 +51,7 @@ sub handle {
my $theHiddenFormat = $params->{hiddenformat};
my $theSort = Foswiki::Func::isTrue($params->{sort}, 0);
my $thePrefix = $params->{prefix};

my $useMultiLingual = Foswiki::Func::getContext()->{MultiLingualPluginEnabled};
my $theHideEmpty = Foswiki::Func::isTrue($params->{hideempty}, 0);

if (!defined($theFormat) && !defined($theHeader) && !defined($theFooter)) {
$theHeader = '<div class=\'foswikiFormSteps\'>';
Expand All @@ -68,7 +67,7 @@ sub handle {
$theHeader = '' unless defined $theHeader;
$theFooter = '' unless defined $theFooter;
}
$theMandatory = " <span class='foswikiAlert'>**</span> " unless defined $theMandatory;
$theMandatory = " <span class='foswikiAlert'>*</span> " unless defined $theMandatory;
$theHiddenFormat = '$edit' unless defined $theHiddenFormat;

my $thisWeb = $theWeb;
Expand Down Expand Up @@ -217,7 +216,7 @@ sub handle {
);
$field = $fieldClone;
}
$this->translateField($field, $theForm, $theWeb);
$this->translateField($field, $theWeb, $theForm);

#$this->writeDebug("reading fieldName=$fieldName");

Expand Down Expand Up @@ -246,7 +245,7 @@ sub handle {
$fieldValue = $metaField->{value} if $metaField;
}

$fieldValue = $fieldDefault unless defined $fieldValue && $fieldValue ne '';
$fieldValue = $fieldDefault unless defined $fieldValue;

next if $theInclude && $fieldName !~ /$theInclude/;
next if $theExclude && $fieldName =~ /$theExclude/;
Expand All @@ -257,6 +256,14 @@ sub handle {
$fieldValue = "\0"; # prevent dropped value attr in CGI.pm
}

my $fieldMandatory = '';
my $origFieldAttributes;
if (!$field->isMandatory() && Foswiki::Func::isTrue($params->{$fieldName . '_mandatory'}, 0)) {
$origFieldAttributes = $field->{attributes};
$field->{attributes} .= 'M';
}
$fieldMandatory = $theMandatory if $field->isMandatory();

$fieldEdit = $this->{session}{plugins}->dispatch('renderFormFieldForEditHandler', $fieldName, $fieldType, $fieldSize, $fieldValue, $fieldAttrs, $fieldAllowedValues);

my $isHidden = ($fieldAttrs=~ /h/i || $theHidden && $fieldName =~ /^($theHidden)$/) ? 1 : 0;
Expand Down Expand Up @@ -309,33 +316,38 @@ sub handle {

my $line = $isHidden ? $theHiddenFormat : $fieldFormat;
$fieldTitle = $fieldTitles->{$fieldName} if $fieldTitles && $fieldTitles->{$fieldName};
my $fieldMandatory = '';
$fieldMandatory = $theMandatory if $field->isMandatory();

# clean up
$fieldTitle =~ s/^\[\[([^]]+)\]\]$/$1/g;

$fieldTitle = $this->translate($fieldTitle, $theFormWeb, $theForm);
$fieldDescription = $this->translate($fieldDescription, $theFormWeb, $theForm);

$line =~ s/\$mandatory/$fieldMandatory/g;
$line =~ s/\$edit\b/$fieldEdit/g;
$line =~ s/\$name\b/$fieldName/g;
$line =~ s/\$type\b/$fieldType/g;
$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;
$line =~ s/\$description\b/$fieldDescription/g;
$line =~ s/\$title\b/$fieldTitle/g;
$line =~ s/\$extra\b/$fieldExtra/g;
$line =~ s/\$default\b/$fieldDefault/g;
$line =~ s/\$values\b/$fieldAllowedValues/g;
$line =~ s/\$origvalues\b/$fieldOrigAllowedValues/g;
$line =~ s/\$(orig)?value\b/$fieldValue/g;
$line =~ s/\$edit\b/$fieldEdit/g;

push @result, $line;

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

return '' if $theHideEmpty && !@result;

my $result = $theHeader . join($theSep, @result) . $theFooter;
$result =~ s/\$nop//g;
$result =~ s/\$n/\n/g;
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin/RenderFormDef.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2015 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2016 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down

0 comments on commit e15ef2f

Please sign in to comment.