Skip to content

Commit

Permalink
Item14273:
Browse files Browse the repository at this point in the history
   * replace MoreFormfieldsAjaxHelper with a template solution to be able to override it when required
   * fixes in id and autofill formfields
   * defaulting to YYYY/MM/DD in date2 formfield now to prevent browsers from interpreting date formfields using their own idea of locales
   * added an afterSaveHandler for formfield classes
   * add register of latest fontawesome icons for the icon formfield
  • Loading branch information
MichaelDaum committed Jan 16, 2017
1 parent 56dab3d commit 6133cf1
Show file tree
Hide file tree
Showing 26 changed files with 3,195 additions and 2,657 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Expand Up @@ -13,10 +13,10 @@ pub/System/MoreFormfieldsPlugin/topicfield.js
pub/System/MoreFormfieldsPlugin/iconfield.js
pub/System/MoreFormfieldsPlugin/select2.js
pub/System/MoreFormfieldsPlugin/moreformfields.css
MoreFormfieldsPlugin.md5
MoreFormfieldsPlugin.sha1
MoreFormfieldsPlugin.tgz
MoreFormfieldsPlugin.txt
MoreFormfieldsPlugin.zip
MoreFormfieldsPlugin_installer
MoreFormfieldsPlugin_installer.pl
/MoreFormfieldsPlugin.md5
/MoreFormfieldsPlugin.sha1
/MoreFormfieldsPlugin.tgz
/MoreFormfieldsPlugin.txt
/MoreFormfieldsPlugin.zip
/MoreFormfieldsPlugin_installer
/MoreFormfieldsPlugin_installer.pl
82 changes: 0 additions & 82 deletions data/System/MoreFormfieldsAjaxHelper.txt

This file was deleted.

17 changes: 12 additions & 5 deletions data/System/MoreFormfieldsPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1464704972" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1467204325" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -130,7 +130,7 @@ A hardware address given in 6 hex values, e.g. =00:1a:10:6f:ba:12=

---+++ =natedit=

This renders a textarea using the [[%SYSTEWEB%.NatEditPlugin][NatEditPlugin]]. The size of the imput fields is specified similar to the standard =textarea=
This renders a textarea using the [[%SYSTEMWEB%.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=
Expand Down Expand Up @@ -175,7 +175,7 @@ A topic reference using JQSelect2Contrib for autocompletion.

* =web=: the web the user can choose topics from; defaults to current web
* =default=: the default value to use if no value exists yet
* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"view"}%/%SYSTEMWEB%/MoreFormfieldsAjaxHelper?section=select2::topic;skin=text;contenttype=application/json=
* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"rest"}%/RenderPlugin/tempalte?expand=select2::topic;contenttype=application/json=
* =TopicType=: name of a !TopicType to be selected

Custom parameters may be added. These will be appended to the autocompletion url.
Expand All @@ -194,7 +194,7 @@ A user reference using JQSelect2Contrib for autocompletion.

*Parameters*:

* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"view"}%/%SYSTEMWEB%/MoreFormfieldsAjaxHelper?section=select2::user;skin=text;contenttype=application/json=
* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"rest"}%/RenderPlugin/tempalte?expand=select2::user;contenttype=application/json=
* =form=: !DataForm supposed to be attached to user profile pages; this form is used to search for users, default: !UserForm

---++ Installation Instructions
Expand All @@ -204,6 +204,13 @@ A user reference using JQSelect2Contrib for autocompletion.
%$DEPENDENCIES%

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 16 Jan 2017: | replace <nop>MoreFormfieldsAjaxHelper with a template solution to be able to override it when required; \
fixes in =id= and =autofill= formfields; \
defaulting to YYYY/MM/DD in =date2= formfield now to prevent browsers from interpreting date formfields using their own idea of locales; \
added an =afterSaveHandler= for formfield classes; \
add register of latest fontawesome icons for the =icon= formfield |
| 29 Jun 2016: | replaced <nop>MoreformfieldAjaxHelper topic with a template approach for higher flexibility |
| 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 |
Expand All @@ -220,7 +227,7 @@ A user reference using JQSelect2Contrib for autocompletion.
%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="Copyright" title="Copyright" value="&copy; 2010-2017 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"}%
35 changes: 21 additions & 14 deletions lib/Foswiki/Form/Autofill.pm
Expand Up @@ -13,6 +13,7 @@ BEGIN {

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

sub new {
Expand Down Expand Up @@ -64,26 +65,27 @@ sub param {
return (defined $key) ? $this->{_params}{$key} : $this->{_params};
}

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

#print STDERR "called Foswiki::Form::Autofill::afterSaveHandler()\n";

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

my @fields;
if (defined $fields) {
@fields = split(/\s*,\s*/, $fields);
} else {
@fields = map {$_->{name}} $topicObject->find("FIELD");
}
my @fields = ();
@fields = split(/\s*,\s*/, $fields) if defined $fields;

my $result;

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

@fields = map {$_->{name}} $topicObject->find("FIELD")
unless @fields;

foreach my $name (@fields) {
my $field = $topicObject->get('FIELD', $name);
Expand All @@ -98,7 +100,10 @@ sub beforeSaveHandler {
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 '';
next unless defined $field;
my $value = $field->{value};
$value = '' unless defined $value;
push @result, $field->{value};
}

$result = join($sep, @result);
Expand All @@ -109,32 +114,34 @@ sub beforeSaveHandler {
$thisField = {
name => $this->{name},
title => $this->{name},
value => "",
} unless defined $thisField;

# remove it from the request so that it doesn't override things here
my $request = Foswiki::Func::getRequestObject();
$request->delete($this->{name});

$thisField->{value} = $header.$result.$footer;
my $value = Foswiki::Func::expandCommonVariables(Foswiki::Func::decodeFormatTokens($header . $result . $footer), $topicObject->topic, $topicObject->web, $topicObject);

return if $thisField->{value} eq $value;

$thisField->{value} = $value;
$topicObject->putKeyed('FIELD', $thisField);

return 1; # trigger mustSave
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2013-2016 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2013-2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2001-2007 TWiki Contributors. All Rights Reserved.
TWiki 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
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Form/Date2.pm
Expand Up @@ -28,7 +28,7 @@ sub renderForDisplay {

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

return $this->SUPER::renderForDisplay($format, $value, $attrs);
}
Expand Down Expand Up @@ -67,7 +67,7 @@ sub renderForEdit {
1;
__DATA__
Copyright (C) 2015-2016 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2015-2017 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
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-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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
16 changes: 7 additions & 9 deletions lib/Foswiki/Form/Id.pm
Expand Up @@ -51,10 +51,10 @@ sub renderForEdit {
);
}

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

#print STDERR "called Foswiki::Form::Id::beforeSaveHandler()\n";
#print STDERR "called Foswiki::Form::Id::afterSaveHandler()\n";

my $topic = $topicObject->topic;

Expand All @@ -69,34 +69,32 @@ sub beforeSaveHandler {
$thisField = {
name => $this->{name},
title => $this->{name},
value => "",
} unless defined $thisField;

# remove it from the request so that it doesn't override things here
my $request = Foswiki::Func::getRequestObject();
$request->delete($this->{name});

$thisField->{value} = $value;
return if $thisField->{value} eq $value;

$thisField->{value} = $value;
$topicObject->putKeyed('FIELD', $thisField);

#print STDERR "result=$thisField->{value}\n";
return 1; # trigger mustSave
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2013-2016 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2013-2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2001-2007 TWiki Contributors. All Rights Reserved.
TWiki 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
Expand Down
2 changes: 1 addition & 1 deletion 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-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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/Ipv6address.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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/Macaddress.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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/Natedit.pm
Expand Up @@ -70,7 +70,7 @@ sub renderForEdit {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2017 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
2 changes: 1 addition & 1 deletion lib/Foswiki/Form/Netmask.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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
4 changes: 2 additions & 2 deletions lib/Foswiki/Form/NetworkAddressField.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2016 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 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 @@ -26,7 +26,7 @@ sub addJavascript {
#my $this = shift;
Foswiki::Func::addToZone("script",
"MOREFORMFIELDSPLUGIN::IPADDRESS::JS",
"<script src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsPlugin/networkaddress.js'></script>",
"<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsPlugin/networkaddress.js'></script>",
"JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::LIVEQUERY, JQUERYPLUGIN::VALIDATE");

Foswiki::Plugins::JQueryPlugin::createPlugin("validate");
Expand Down

0 comments on commit 6133cf1

Please sign in to comment.