Skip to content

Commit

Permalink
Item14084: add date2, ipv6address and natedit
Browse files Browse the repository at this point in the history
... as well as:

- removed dependency on YAML
- added a format parameter to the autofill formfield type
- added beforeSaveHandlers to network address formfield types to normalize their store format on save
  • Loading branch information
MichaelDaum committed May 31, 2016
1 parent dccf3f2 commit 56dab3d
Show file tree
Hide file tree
Showing 32 changed files with 8,408 additions and 3,771 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,5 +1,7 @@
*.gz
*.swp
*_new
*_bak
pub/System/MoreFormfieldsPlugin/git/
pub/System/MoreFormfieldsPlugin/phonenumber.js
pub/System/MoreFormfieldsPlugin/clockpicker.init.js
Expand All @@ -9,6 +11,7 @@ pub/System/MoreFormfieldsPlugin/userfield.js
pub/System/MoreFormfieldsPlugin/networkaddress.js
pub/System/MoreFormfieldsPlugin/topicfield.js
pub/System/MoreFormfieldsPlugin/iconfield.js
pub/System/MoreFormfieldsPlugin/select2.js
pub/System/MoreFormfieldsPlugin/moreformfields.css
MoreFormfieldsPlugin.md5
MoreFormfieldsPlugin.sha1
Expand Down
12 changes: 6 additions & 6 deletions data/System/MoreFormfieldsAjaxHelper.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1428580029" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1464704972" format="1.1" version="1"}%
%META:TOPICPARENT{name="MoreFormfieldsPlugin"}%
---+!! %TOPIC%

Expand All @@ -11,7 +11,7 @@
then="form=~'\b%URLPARAM{"form"}%\b' AND "
}%%IF{
"defined topicType"
then="TopicType=~'\b%URLPARAM{"topicType"}%\b' AND "
then="(TopicType=~'\b%URLPARAM{"topicType"}%\b' OR @Target.TopicType=~'\b%URLPARAM{"topicType"}%\b') AND "
}%%FORMATLIST{
"%IF{
"'%URLPARAM{"q"}%'=''"
Expand All @@ -38,19 +38,19 @@
}$percnt
}"
separator=",$n"
header="{\"results\":[{\"id\":\"\", \"text\":\"- none -\"},$n"
header="{\"results\":[$n"
footer="$n], \"total\":$count}"
}%</literal>%ENDSECTION{"select2::topic"}%
</verbatim>

---++ user field backend
<verbatim class="tml">
%STARTSECTION{"select2::user"}%<literal>%DBQUERY{
"form='\b%IF{
"form=~'^(%IF{
"defined form"
then="%URLPARAM{"form"}%"
else="UserForm"
}%\b' AND %FORMATLIST{
else=".*UserForm"
}%)$' AND %FORMATLIST{
"%IF{
"'%URLPARAM{"q"}%'=''"
then="."
Expand Down
71 changes: 50 additions & 21 deletions data/System/MoreFormfieldsPlugin.txt
@@ -1,6 +1,6 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1428580029" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1464704972" format="1.1" version="1"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%
%FORMFIELD{"Description"}%

%TOC%

Expand All @@ -11,7 +11,8 @@ This plugin implements a set of additional special purpose formfields to be used
To make use of these formfields use their type identifier in the =Type= column of a !DataForm definition, such as in

| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* |
| <nop>IpAddress | ipaddress | 15 | | network address | |
| <nop>IpV4 | ipaddress | 15 | | network address | |
| <nop>IpV6 | ipv6address | 40 | | network address | |
| Netmask | netmask | 15 | | netmask | |
| <nop>MacAddress | macaddress | 17 | | hardware-addresse | |

Expand All @@ -26,19 +27,33 @@ are extracted and concatenated using the specified =separator=. Values of an =au

*Parameters*:

Either use this approach:

* =format=: specify a format string to build up the autofill formfield; use =$&lt;field-name>= to reference a formfield (see example below)

... or do it the old way by looping over formfields:

* =header=: add an optional string prefixed to the field value, but only when the source fields are not empty
* =source=: comma-separated list of one or more formfields to fetch values from
* =fields=: comma-separated list of one or more formfields to fetch values from
* =separator=: separator used when concatenating all values into a new value for the =autofill= field
* =footer=: append an optional string to the field value, but only when the source fields are not empty

A typical use-case for an =autofill= field is the construction of a !TopicTitle based on other form properties:

| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* |
| <nop>TopicTitle | autofill | 1 | header="Project" source="Customer, ID, Year" | | |
| <nop>TopicTitle1 | autofill | 1 | header="Project" fields="Customer, ID, Year" | | |
| <nop>TopicTitle2 | autofill | 1 | format="Project-$ID ($Customer, $Year)" | | |
| Customer | text | 80 | | | |
| ID | id | 4 | | | |
| Year | text | 4 | | | |

---+++ =date2=

This is an alternative for the core =date= formfield type using the [[JQueryUI][jQuery-ui datepicker widget]] instead of using the [[%SYSTEMWEB%.JSCalendarContrib][Mishoo JSCalendar widget]].
It will launch a calendar when clicking into a =date2= formfield to select a date from, as well as restricts allowed keys to be entered into the formfield. The format of a =date2= formfield value
will always be of a =YYYY-MM-DD= pattern and thus not be depending on any locale settings. This is quite important to get consistant data rather than differences based on the user's current browser language.
While the _value_ stored into a =date2= formfield is locale-independent will it display according to the settings of =$Foswiki::cfg{DefaultDateFormat}= settings.

---+++ =icon=

A select box to chose an icon supported by Foswiki (famfamfam and fontawesome).
Expand Down Expand Up @@ -97,7 +112,13 @@ Then upon save the =id= formfield will have a value of =0001=.

---+++ =ipaddress=

A general purpose IP4 address, consisting of 4 octets, e.g. =10.0.0.1=
A general purpose IPv4 address, consisting of 4 octets, e.g. =10.0.0.1=

*Parameters*: none

---+++ =ipv6address=

A general purpose IPv6 address,e.g. =2001:db8:85a3:8d3:1319:8a2e:370:7348=

*Parameters*: none

Expand All @@ -107,6 +128,11 @@ A hardware address given in 6 hex values, e.g. =00:1a:10:6f:ba:12=

*Parameters*: none

---+++ =natedit=

This renders a textarea using the [[%SYSTEWEB%.NatEditPlugin][NatEditPlugin]]. The size of the imput fields is specified similar to the standard =textarea=
formfield type. Any additional parameters specific to =natedit= may be specified in the "Values" column.

---+++ =netmask=

A special IP address used for routing, consisting of 4 octets, e.g. =255.255.255.0=
Expand Down Expand Up @@ -172,26 +198,29 @@ A user reference using JQSelect2Contrib for autocompletion.
* =form=: !DataForm supposed to be attached to user profile pages; this form is used to search for users, default: !UserForm

---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%

---++ Info
<!--
* Set SHORTDESCRIPTION = Additional formfield types for !DataForms
-->

| Author(s): | Michael Daum|
| Copyright: | &copy; 2010-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; |
---++ Dependencies
%$DEPENDENCIES%

---++ Change History
| 31 May 2016: | added formfield types =date2=, =ipv6address= and =natedit=; removed dependency on YAML; added a =format= parameter to the =autofill= formfield type; added =beforeSaveHandlers= to network address formfield types to normalize their store format on save |
| 01 Mar 2016: | fixed select2 in jquery-ui modal [[https://github.com/select2/select2/issues/940][not allowing focus]] |
| 09 Jan 2016: | added ipv6, fixed validation of all network addresses by properly integrating it into jquery.validate |
| 09 Apr 2015: | documentation; final bugfixing before release; updated to latest clockpicker |
| 26 Mar 2015: | updated list of all fontawesom icons; fixed rendering of Topic formfields values |
| 16 Dec 2014: | fixed thumbnails in user autocompletion; don't inherit from <nop>ListFieldDefinition for performance reasons |
| 22 Aug 2014: | added smarbox formfield |
| 04 Apr 2014: | fixed compatibility with foswiki >= 1.2.0 |
| 23 Sep 2010: | initial release |
| Dependencies: | %$DEPENDENCIES% |
| Home page: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2010-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25TOPIC%25"}%
42 changes: 34 additions & 8 deletions lib/Foswiki/Form/Autofill.pm
Expand Up @@ -69,16 +69,42 @@ sub beforeSaveHandler {

my $header = $this->param("header") || '';
my $footer = $this->param("footer") || '';
my $source = $this->param("source");
my $fields = $this->param("source") || $this->param("fields");
my $format = $this->param("format");
my $sep = $this->param("separator") || '';
return unless $source;

my @result = ();
foreach my $name (split(/\s*,\s*/, $source)) {
my $field = $topicObject->get('FIELD', $name);
push @result, $field->{value} if defined $field && defined $field->{value} && $field->{value} ne '';
my @fields;
if (defined $fields) {
@fields = split(/\s*,\s*/, $fields);
} else {
@fields = map {$_->{name}} $topicObject->find("FIELD");
}

my $result;

if (defined($format)) {
$result = $format;

foreach my $name (@fields) {
my $field = $topicObject->get('FIELD', $name);
next unless defined $field;
my $value = $field->{value};
$value = '' unless defined $value;
$result =~ s/\$$name/$value/g;
}

} else {

my @result = ();
foreach my $name (@fields) {
my $field = $topicObject->get('FIELD', $name);
push @result, $field->{value} if defined $field && defined $field->{value} && $field->{value} ne '';
}

$result = join($sep, @result);
}
return unless defined $result;

my $thisField = $topicObject->get('FIELD', $this->{name});
$thisField = {
name => $this->{name},
Expand All @@ -89,7 +115,7 @@ sub beforeSaveHandler {
my $request = Foswiki::Func::getRequestObject();
$request->delete($this->{name});

$thisField->{value} = @result?$header.join($sep, @result).$footer:"";
$thisField->{value} = $header.$result.$footer;

$topicObject->putKeyed('FIELD', $thisField);
}
Expand All @@ -98,7 +124,7 @@ sub beforeSaveHandler {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2013-2015 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2013-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
84 changes: 84 additions & 0 deletions lib/Foswiki/Form/Date2.pm
@@ -0,0 +1,84 @@
# See bottom of file for license and copyright information
# See bottom of file for license and copyright details
# This packages subclasses Foswiki::Form::FieldDefinition to implement
# the =date= type

package Foswiki::Form::Date2;

use strict;
use warnings;

use Foswiki::Form::FieldDefinition ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Time ();
our @ISA = ('Foswiki::Form::FieldDefinition');

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
my $size = $this->{size} || '';
$size =~ s/[^\d]//g;
$size = 20 if ( !$size || $size < 1 ); # length(31st September 2007)=19
$this->{size} = $size;
return $this;
}

sub renderForDisplay {
my ( $this, $format, $value, $attrs ) = @_;

my $epoch = Foswiki::Time::parseTime($value);
$epoch = 0 unless defined $epoch;
$value = Foswiki::Time::formatTime($epoch, $Foswiki::cfg{DefaultDateFormat} || '$year-$mo-$day');

return $this->SUPER::renderForDisplay($format, $value, $attrs);
}

sub renderForEdit {
my ( $this, $topicObject, $value ) = @_;
my ( $web, $topic );

unless ( ref($topicObject) ) {

# Pre 1.1
( $this, $web, $topic, $value ) = @_;
undef $topicObject;
}

Foswiki::Plugins::JQueryPlugin::createPlugin("ui::datepicker");

$value = CGI::textfield(
{
name => $this->{name},
id => 'id' . $this->{name} . int(rand()*1000),
size => $this->{size},
value => $value,
"data-change-month" => "true",
"data-change-year" => "true",
class => $this->can('cssClasses')
? $this->cssClasses( 'foswikiInputField',
'jqUIDatepicker' )
: 'foswikiInputField jqUIDatepicker'
}
);

return ( '', $value );
}

1;
__DATA__
Copyright (C) 2015-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
2 changes: 1 addition & 1 deletion lib/Foswiki/Form/Icon.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2015 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-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
2 changes: 1 addition & 1 deletion lib/Foswiki/Form/Id.pm
Expand Up @@ -86,7 +86,7 @@ sub beforeSaveHandler {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2013-2015 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2013-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
24 changes: 22 additions & 2 deletions lib/Foswiki/Form/Ipaddress.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2015 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-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 @@ -24,8 +24,28 @@ our @ISA = ('Foswiki::Form::NetworkAddressField');
sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
$this->{_class} = 'foswikiIpAddress';
$this->{_class} = 'foswikiIpv4Address';
return $this;
}

sub beforeSaveHandler {
my ($this, $topicObject) = @_;

my $field = $topicObject->get('FIELD', $this->{name});

$field = {
name => $this->{name},
title => $this->{name},
} unless defined $field;

my @segments = ();
foreach my $segment (split(/\./, $field->{value})) {
push @segments, sprintf("%03d", $segment);
}
$field->{value} = join(".", @segments);

$topicObject->putKeyed('FIELD', $field);
}


1;

0 comments on commit 56dab3d

Please sign in to comment.