Skip to content

Commit

Permalink
Item15258: new macro %EDITFIELD
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jan 22, 2024
1 parent 4c34c0f commit c677772
Show file tree
Hide file tree
Showing 82 changed files with 1,902 additions and 144 deletions.
38 changes: 30 additions & 8 deletions data/System/FlexFormPlugin.txt
Expand Up @@ -28,15 +28,17 @@ While %<nop>RENDERFOREDIT% and %<nop>%RENDERFORDISPLAY render forms for the net
the %<nop>RENDERFORMDEF= macro renders information about the !DataForm definition itself identpendent of
any topic actually using it. This may be used to provide more defailed insights into the !DataForm definition.

The %<nop>DISPLAYFIELD% is supposed to be a shortcut for =%<nop>RENDERFORDISPLAY% for a single formfield, similar
%<nop>DISPLAYFIELD% is supposed to be a shortcut for %<nop>RENDERFORDISPLAY% for a single formfield, similar
to %<nop>FORMFIELD%. Contrary to %<nop>FORMFIELD% it renders a proper display value based on the type of the formfield,
whereas %<nop>FORMFIELD% returns the raw data as stored in the topic.

Similarly, %<nop>EDITFIELD% is a shortcut for %<nop>%RENDERFOREDIT% rendering an editor for a single field.

---++ Usage
---+++ RENDERFOREDIT
| *Parameter* | *Description* | *Default* |
| "..." or topic="..." | name of a topic to render the edit form for | the base topic of the current url |
| revision="..." or rev="..." | topic revision which to use the data from while populating the edit form | |
| revision="..." or rev="..." | topic revision which to use the data from while populating the edit form | "rev" url parameter |
| 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> |
Expand Down Expand Up @@ -66,7 +68,9 @@ whereas %<nop>FORMFIELD% returns the raw data as stored in the topic.
&lt;fieldname>_title="..." %BR% \
&lt;fieldname>_type="..." %BR% \
&lt;fieldname>_values="..." %BR% \
| these parameters allow to override the formfield properties as specified in the !DataForm definition; for example a =Teaser_type="text"= , =Teaser_size="30"= will override a definition of a =Teaser= formfield that otherwise is a =textarea= of size =80x25=; &lt;fieldname>_values redefines the list of allowed values for that field | values as defined in the !DataForm definition and the current topic |
&lt;fieldname>_params="..." %BR% \
&lt;fieldname>_definition="..." %BR% \
| these parameters allow to override the formfield properties as specified in the !DataForm definition; for example a =Teaser_type="text"= , =Teaser_size="30"= will override a definition of a =Teaser= formfield that otherwise is a =textarea= of size =80x25=; &lt;fieldname>_values redefines the list of allowed values for that field; &lt;fieldname>_definition redefinies a value defining topic | values as defined in the !DataForm definition and the current topic |
| &lt;fieldname>_value="..." | value to be inserted into the edit interface of the named field | looks for urlparam &lt;fieldname>, defaults to stored value |
| &lt;fieldname>_sort="..." | on/off/asc/desc/rev - sort allowed values before displaying them | as defined in the !DataForm |

Expand All @@ -91,6 +95,7 @@ whereas %<nop>FORMFIELD% returns the raw data as stored in the topic.
| excludevalue="..." | regular expression field value must match to be excluded in the output | undefined |
| include="..." | regular expression fieldnames must match to be included in the output | undefined |
| exclude="..." | regular expression fieldnames must match to be excluded from the output | undefined |
| limit="..." | specifies the maximum number of formfields to be included in the output |
| labelformat="..." | format string used for labels exclusively; labels aren't real input fields; they are part of the form definition but carry read-only values only if at all | same as =format= |
| map="&lt;fieldname1>=&lt;title1>, &lt;fieldname2>=&lt;title2>, ..." | allows to map a fieldname to a different title string (*deprecated*: please use &lt;fieldname>_title to redefine the title) | original fieldnames are used as title string |
| separator="..." | string to be put between each formatted output per formfield | &lt;empty string> |
Expand All @@ -107,6 +112,7 @@ whereas %<nop>FORMFIELD% returns the raw data as stored in the topic.
&lt;fieldname>_type="..." %BR% \
&lt;fieldname>_value="..." %BR% \
&lt;fieldname>_values="..." %BR% \
&lt;fieldname>_params="..." %BR% \
| see above | defaults as defined in the !DataForm definition and the current topic |

If all three =format=, =header= and =footer= are undefined a =foswikiFormSteps= block will be rendered as illustrated in the example below.
Expand Down Expand Up @@ -135,11 +141,21 @@ The =format= parameter may contain the following variables:
| *Parameter* | *Description* | *Default* |
| "..." or field="..." | name of the field to display | |
| topic="..." | topic to display the field for | current topic |
| form="..." | topic name containing the !DataForm definition | form found at =topic= |
| default="..." | default value if the field isn't defined | _empty string_ |
| editable="on/off" | enable/disable inline editing | off |
| format="..." | format for the field (see RENDERFORDISPLAY) | =$value= |
| revision="..." or rev="..." | topic revision to display | |
| hideempty="on/off" | hide empty formfields | off |

---+++ EDITFIELD

| *Parameter* | *Description* | *Default* |
| "..." or field="..." | name of the field to render an editor for | |
| topic="..." | topic to render the editor for | current topic |
| form="..." | topic name containing the !DataForm definition | form found at =topic= |
| default="..." | default value if the field isn't defined | _empty string_ |
| format="..." | format for the field (see RENDERFOREDIT) | =$edit= |
| revision="..." or rev="..." | topic revision to display | |

---+++ RENDERFORMDEF

Expand Down Expand Up @@ -211,7 +227,7 @@ in inline editing to a custom output. The following example illustrates the requ
format="<tr>
<th>$title:</th>
<td class='inlineEditValue' data-formfield='$name'>$value $editicon</td>
</tr>
</tr>"
separator="$n"
footer="</table>"
}%
Expand All @@ -235,7 +251,7 @@ Note that multiple instances of =%RENDERFORDISPLAY= can be covered by a single i
format="<tr>
<th>$title:</th>
<td class='inlineEditValue' data-formfield='$name' data-topic='$web.$topic'>$value $editicon</td>
</tr>
</tr>"
separator="$n"
footer="</table>"
}%
Expand All @@ -248,7 +264,7 @@ Note that multiple instances of =%RENDERFORDISPLAY= can be covered by a single i
format="<tr>
<th>$title:</th>
<td class='inlineEditValue' data-formfield='$name' data-topic='$web.$topic'>$value $editicon</td>
</tr>
</tr>"
separator="$n"
footer="</table>"
}%
Expand Down Expand Up @@ -302,6 +318,12 @@ This also illustrates how to edit formfields of different topics in one inline e

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 22 Jan 2024: | added EDITFIELD; \
added =_definition= to RENDERFOREDIT; \
added =_params= as a synonym for =_values= as this column is used form formfield parameters more often than for listing allowed values;\
rationalized the way format strings are collected and defaulted; \
read =rev= url parameter by default; \
added =limit= parameter for RENDERFORDISPLAY |
| 29 Apr 2022: | added =includevalue= and =excludevalue= to RENDERFORDISPLAY |
| 22 Feb 2022: | added inline editor feature to RENDERFORDISPLAY |
| 25 Jan 2022: | fixed =$description= in RENDERFORMDEF |
Expand Down Expand Up @@ -355,7 +377,7 @@ This also illustrates how to edit formfields of different topics in one inline e

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Foswiki:MichaelDaum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2009-2022 Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2009-2024 Michael Daum"}%
%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)]]"}%
Expand Down
71 changes: 62 additions & 9 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-2022 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2024 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 @@ -20,10 +20,12 @@ use warnings;

use Foswiki::Func ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Contrib::JsonRpcContrib ();

our $VERSION = '8.10';
our $RELEASE = '29 Apr 2022';
our $VERSION = '8.31';
our $RELEASE = '%$RELEASE%';
our $SHORTDESCRIPTION = 'Flexible way to render <nop>DataForms';
our $LICENSECODE = '%$LICENSECODE%';
our $NO_PREFS_IN_TOPIC = 1;

our $renderForEditInstance;
Expand All @@ -37,6 +39,8 @@ sub initPlugin {
Foswiki::Func::registerTagHandler('RENDERFORMDEF', \&renderFormDef);
Foswiki::Func::registerTagHandler('DISPLAYFIELD', \&displayField);

Foswiki::Func::registerTagHandler('EDITFIELD', \&editField);

Foswiki::Plugins::JQueryPlugin::registerPlugin('InlineEditor', 'Foswiki::Plugins::FlexFormPlugin::InlineEditor');

Foswiki::Contrib::JsonRpcContrib::registerMethod("FlexFormPlugin", "save", sub {
Expand Down Expand Up @@ -84,19 +88,36 @@ sub displayField {

my %params = ();

$params{field} = $theParams->{_DEFAULT} // $theParams->{field};
if (defined $theParams->{type} && !defined $theParams->{topic} && ! defined $theParams->{form}) {
$params{form} = "System.MoreFormfieldsPlugin"; # SMELL: only advanced fields ... need a way to reference all available formfield types
$params{field} = ucfirst($theParams->{type});
$params{$params{field} . '_name'} = $theParams->{_DEFAULT} // $theParams->{field};
} else {
$params{form} = $theParams->{form};
$params{topic} = $theParams->{topic} // $theTopic;
$params{field} = $theParams->{_DEFAULT} // $theParams->{field};
$params{$params{field} . "_name"} = $theParams->{name};
}

return "" unless defined $params{field};

$params{topic} = $theParams->{topic} // $theTopic;
$params{$params{field} . "_default"} = $theParams->{default} // "";
$params{$params{field} . "_attributes"} = $theParams->{attributes} // "";
$params{excludeattr} = ""; # disable exclusion based on attributes, i.e. hidden fields
$params{$params{field} . "_attributes"} = $theParams->{attributes};
$params{$params{field} . "_default"} = $theParams->{default};
$params{$params{field} . "_definition"} = $theParams->{definition};
$params{$params{field} . "_size"} = $theParams->{size};
$params{$params{field} . "_type"} = $theParams->{type};
$params{$params{field} . "_value"} = $theParams->{value};
$params{$params{field} . "_values"} = $theParams->{values};

$params{rev} = $theParams->{revision} || $theParams->{rev};
$params{hideempty} = $theParams->{hideempty} // 'off';
$params{editable} = $theParams->{editable} // 'off';
$params{format} = $theParams->{format};
$params{hideempty} = $theParams->{hideempty};

unless (defined $params{format}) {
if (Foswiki::Func::isTrue($params{editable})) {
$params{format} = '<span class="inlineEditor"><span class="inlineEditValue" data-formfield="$name">$n$value $editicon</span></span>';
$params{format} = '<span class="inlineEditor" data-topic="$topic"><span class="inlineEditValue" data-formfield="$name">$n$value $editicon</span></span>';
} else {
$params{format} = '$value';
}
Expand All @@ -105,6 +126,38 @@ sub displayField {
return renderForDisplay($session, \%params, $theTopic, $theWeb);
}

sub editField {
my ($session, $theParams, $theTopic, $theWeb) = @_;

my %params = ();

if (defined $theParams->{type} && !defined $theParams->{topic} && ! defined $theParams->{form}) {
$params{form} = "System.MoreFormfieldsPlugin"; # SMELL: only advanced fields ... need a way to reference all available formfield types
$params{field} = ucfirst($theParams->{type});
$params{$params{field} . '_name'} = $theParams->{_DEFAULT} // $theParams->{field};
} else {
$params{form} = $theParams->{form};
$params{topic} = $theParams->{topic} // $theTopic;
$params{field} = $theParams->{_DEFAULT} // $theParams->{field};
$params{$params{field} . "_name"} = $theParams->{name};
}

return "" unless defined $params{field};

$params{$params{field} . "_type"} = $theParams->{type};
$params{$params{field} . "_attributes"} = $theParams->{attributes};
$params{$params{field} . "_default"} = $theParams->{default};
$params{$params{field} . "_definition"} = $theParams->{definition};
$params{$params{field} . "_size"} = $theParams->{size};
$params{$params{field} . "_value"} = $theParams->{value};
$params{$params{field} . "_values"} = $theParams->{values};

$params{rev} = $theParams->{revision} || $theParams->{rev};
$params{format} = $theParams->{format} // '$edit';

return renderForEdit($session, \%params, $theTopic, $theWeb);
}

sub renderFormDef {
my $session = shift;

Expand Down
2 changes: 1 addition & 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-2020 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2024 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
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin/InlineEditor.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2022 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2022-2024 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
24 changes: 24 additions & 0 deletions lib/Foswiki/Plugins/FlexFormPlugin/MANIFEST
Expand Up @@ -7,6 +7,30 @@ lib/Foswiki/Plugins/FlexFormPlugin.pm 0644
lib/Foswiki/Plugins/FlexFormPlugin/RenderForDisplay.pm 0644
lib/Foswiki/Plugins/FlexFormPlugin/RenderForEdit.pm 0644
lib/Foswiki/Plugins/FlexFormPlugin/RenderFormDef.pm 0644
locale/FlexFormPlugin/bg.po 0644
locale/FlexFormPlugin/cs.po 0644
locale/FlexFormPlugin/da.po 0644
locale/FlexFormPlugin/de.po 0644
locale/FlexFormPlugin/el.po 0644
locale/FlexFormPlugin/es.po 0644
locale/FlexFormPlugin/fi.po 0644
locale/FlexFormPlugin/Foswiki.pot 0644
locale/FlexFormPlugin/fr.po 0644
locale/FlexFormPlugin/it.po 0644
locale/FlexFormPlugin/ja.po 0644
locale/FlexFormPlugin/ko.po 0644
locale/FlexFormPlugin/nl.po 0644
locale/FlexFormPlugin/no.po 0644
locale/FlexFormPlugin/pl.po 0644
locale/FlexFormPlugin/pt-br.po 0644
locale/FlexFormPlugin/pt.po 0644
locale/FlexFormPlugin/ru.po 0644
locale/FlexFormPlugin/sv.po 0644
locale/FlexFormPlugin/tlh.po 0644
locale/FlexFormPlugin/tr.po 0644
locale/FlexFormPlugin/uk.po 0644
locale/FlexFormPlugin/zh-cn.po 0644
locale/FlexFormPlugin/zh-tw.po 0644
pub/System/FlexFormPlugin/inlineEditor.css 0644
pub/System/FlexFormPlugin/inlineEditor.css.gz 0644
pub/System/FlexFormPlugin/inlineEditor.js 0644
Expand Down

0 comments on commit c677772

Please sign in to comment.