Skip to content

Commit

Permalink
Item9370:
Browse files Browse the repository at this point in the history
   * fixed not try to load a non-existing form definition
   * providing fallback method for retrieving default values from form definition for those formfield types that can't do that by themselves
   * fixed expanding field title before the formfield does
   * fixed expanding standard escapes at the very end of the rendering process
   * added better default format for RENDERFOREDIT




git-svn-id: http://svn.foswiki.org/trunk/FlexFormPlugin@8274 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jul 22, 2010
1 parent a0f9f77 commit 8f8ad08
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
5 changes: 5 additions & 0 deletions data/System/FlexFormPlugin.txt
Expand Up @@ -138,6 +138,11 @@ Many thanks to the following sponsors for supporting this work:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 22 Jul 2010: | fixed not try to load a non-existing form definition; \
providing fallback method for retrieving default values from form definition for those formfield types that can't do that by themselves; \
fixed expanding field title before the formfield does; \
fixed expanding standard escapes at the very end of the rendering process; \
added better default format for RENDERFOREDIT |
| 07 Jun 2010: | added =includeattr=, =excludeattr= to filter formfields by their attributes |
| 24 Mar 2010: | fixed error where topic values were not inserted into the edit form properly |
| 12 Mar 2010: | cleaned up =$value= and =$values= variable in both RENDERFOREDIT and RENDERFORIDPLSAY;\
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin.pm
Expand Up @@ -18,7 +18,7 @@ package Foswiki::Plugins::FlexFormPlugin;
use strict;

our $VERSION = '$Rev: 1340 $';
our $RELEASE = 'v2.2';
our $RELEASE = 'v2.3';
our $SHORTDESCRIPTION = 'Flexible way to render %SYSTEMWEB%.DataForms';
our $NO_PREFS_IN_TOPIC = 1;
our $doneInit;
Expand Down
62 changes: 47 additions & 15 deletions lib/Foswiki/Plugins/FlexFormPlugin/Core.pm
Expand Up @@ -111,11 +111,19 @@ sub handleRENDERFORDISPLAY {
$theForm = $topicObj->getFormName unless defined $theForm;
return '' unless $theForm;

#writeDebug("theForm=$theForm");

my $theFormWeb = $thisWeb;
($theFormWeb, $theForm) = Foswiki::Func::normalizeWebTopicName($theFormWeb, $theForm);

if (!Foswiki::Func::topicExists($theFormWeb, $theForm)) {
return '';
}
#writeDebug("theFormWeb=$theFormWeb");

my $form = new Foswiki::Form($session, $theFormWeb, $theForm);
return '' unless $form;

my $formTitle;
if ($form->can('getPath')) {
$formTitle = $form->getPath;
Expand Down Expand Up @@ -157,14 +165,24 @@ sub handleRENDERFORDISPLAY {
my $fieldTitle = $field->{title};
my $fieldDefiningTopic = $field->{definingTopic};

writeDebug("fieldName=$fieldName, fieldType=$fieldType");

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

writeDebug("fieldAllowedValues=$fieldAllowedValues");

my $fieldDefault = '';
if ($field->can('getDefault')) {
$fieldDefault = $field->getDefault() || '';
Expand Down Expand Up @@ -197,8 +215,6 @@ sub handleRENDERFORDISPLAY {
$field = $fieldClone;
}

#writeDebug("reading fieldName=$fieldName");

my $metaField = $topicObj->get('FIELD', $fieldName);
unless ($metaField) {
# Not a valid field name, maybe it's a title.
Expand All @@ -218,17 +234,18 @@ sub handleRENDERFORDISPLAY {
$line = $theLabelFormat;
}

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

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

$line = $field->renderForDisplay($line, $fieldValue, {
bar=>'|', # SMELL: keep bars
newline=>'$n', # SMELL: keep newlines
}); # SMELL what about the attrs param in Foswiki::Form
# SMELL wtf is this attr anyway

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

$line =~ s/\$name\b/$fieldName/g;
$line =~ s/\$type\b/$fieldType/g;
$line =~ s/\$size\b/$fieldSize/g;
Expand All @@ -239,18 +256,20 @@ sub handleRENDERFORDISPLAY {
$line =~ s/\$description\b/$fieldDescription/g;
$line =~ s/\$title\b/$fieldTitle/g;
$line =~ s/\$form\b/$formTitle/g;
$line =~ s/\$nop//g;
$line =~ s/\$n/\n/g;
$line =~ s/\$percnt/%/g;
$line =~ s/\$dollar/\$/g;

push @result, $line;

# cleanup
$fieldClone->finish() if defined $fieldClone;
}

return $theHeader.join($theSep, @result).$theFooter;
my $result = $theHeader.join($theSep, @result).$theFooter;
$result =~ s/\$nop//g;
$result =~ s/\$n/\n/g;
$result =~ s/\$percnt/%/g;
$result =~ s/\$dollar/\$/g;

return $result;
}

##############################################################################
Expand Down Expand Up @@ -279,7 +298,7 @@ sub handleRENDERFOREDIT {

if (!defined($theFormat) && !defined($theHeader) && !defined($theFooter)) {
$theHeader = '<div class=\'foswikiFormSteps\'>';
$theFormat = '<div class=\'foswikiFormStep\'><h3>$title:$mandatory</h3>$edit</div>';
$theFormat = '<div class=\'foswikiFormStep\'><h3>$title:$mandatory</h3>$edit<div class=\'foswikiFormDescription\'>$description</div></div>';
$theFooter ='</div>';
} else {
$theFormat = '$edit$mandatory' unless defined $theFormat;
Expand Down Expand Up @@ -309,6 +328,10 @@ sub handleRENDERFOREDIT {

writeDebug("theForm=$theForm");

if (!Foswiki::Func::topicExists($theFormWeb, $theForm)) {
return '';
}

my $form = new Foswiki::Form($session, $theFormWeb, $theForm);
return '' unless $form;

Expand Down Expand Up @@ -355,6 +378,12 @@ sub handleRENDERFOREDIT {
if ($options) {
$fieldAllowedValues = join($theValueSep, @$options);
}
} else {
# fallback to field->value
my $options = $field->{value};
if ($options) {
$fieldAllowedValues = join($theValueSep, split(/\s*,\s*/, $options));
}
}

# get the default value
Expand Down Expand Up @@ -469,18 +498,21 @@ sub handleRENDERFOREDIT {
$line =~ s/\$description\b/$fieldDescription/g;
$line =~ s/\$title\b/$fieldTitle/g;
$line =~ s/\$extra\b/$fieldExtra/g;
$line =~ s/\$nop//g;
$line =~ s/\$n/\n/g;
$line =~ s/\$percnt/%/g;
$line =~ s/\$dollar/\$/g;

push @result, $line;

# cleanup
$fieldClone->finish() if defined $fieldClone;
}

return '<noautolink>'.$theHeader.join($theSep, @result).$theFooter.'</noautolink>';

my $result = $theHeader.join($theSep, @result).$theFooter;
$result =~ s/\$nop//g;
$result =~ s/\$n/\n/g;
$result =~ s/\$percnt/%/g;
$result =~ s/\$dollar/\$/g;

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


Expand Down

0 comments on commit 8f8ad08

Please sign in to comment.