Skip to content

Commit

Permalink
Item14600: fixed previews in some formfields
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jan 12, 2018
1 parent e22fe73 commit d3b29ea
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 79 deletions.
33 changes: 17 additions & 16 deletions data/System/MoreFormfieldsPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="micha" comment="reprev" date="1496927925" format="1.1" reprev="9" version="9"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1515756256" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand All @@ -11,18 +11,18 @@ 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* |
| attachment | attachment | 20 | | | |
| date2 | date2 | 30 | | | |
| icon | icon | 20 | | | |
| ipaddress | ipaddress | 15 | | network address | |
| ipv6address | ipv6address | 40 | | network address | |
| macaddress | macaddress | 17 | | hardware-addresse | |
| netmask | netmask | 15 | | netmask | |
| phonenumber | phonenumber | 20 | | | |
| select2 | select2 | 20 | | | |
| time | time | 20 | | | |
| topic | topic | 20 | | | |
| user | user | 20 | | | |
| Attachment | attachment | 20 | | | |
| Date2 | date2 | 30 | | | |
| Icon | icon | 20 | | | |
| Ipaddress | ipaddress | 15 | | network address | |
| Ipv6address | ipv6address | 40 | | network address | |
| Macaddress | macaddress | 17 | | hardware-addresse | |
| Netmask | netmask | 15 | | netmask | |
| Phonenumber | phonenumber | 20 | | | |
| Select2 | select2 | 20 | | | |
| Time | time | 20 | | | |
| Topic | topic | 20 | | | |
| User | user | 20 | | | |

When defining a formfield additional parameters may be used in the =Values= column to further customize the behavior of the element.

Expand Down Expand Up @@ -183,7 +183,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{"rest"}%/RenderPlugin/tempalte?expand=select2::topic;contenttype=application/json=
* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"rest"}%/RenderPlugin/template?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 @@ -202,7 +202,7 @@ A user reference using JQSelect2Contrib for autocompletion.

*Parameters*:

* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"rest"}%/RenderPlugin/tempalte?expand=select2::user;contenttype=application/json=
* =url=: url for autocompletion, default: =%<nop>SCRIPTURL{"rest"}%/RenderPlugin/template?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 @@ -213,6 +213,7 @@ A user reference using JQSelect2Contrib for autocompletion.

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 12 Jan 2018: | fixed thumbnails in topic, user and attachment formfields |
| 13 Sep 2017: | added =attachment= formfield |
| 27 Jan 2017: | render empty =date2= formfields as an empty string, not 01 Jan 1970 |
| 25 Jan 2017: | fixed =topic= formfield to properly store web dot topic values |
Expand All @@ -238,7 +239,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-2017 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2010-2018 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"}%
4 changes: 2 additions & 2 deletions lib/Foswiki/Form/Attachment.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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 @@ -223,7 +223,7 @@ sub addJavascript {
Foswiki::Plugins::JQueryPlugin::createPlugin("fontawesome");
Foswiki::Plugins::JQueryPlugin::createPlugin("uploader");
Foswiki::Plugins::JQueryPlugin::createPlugin("select2");
Foswiki::Func::addToZone("script", "FOSWIKI::TOPICFIELD", <<"HERE", "JQUERYPLUGIN::SELECT2, JQUERYPLUGIN::UPLOADER");
Foswiki::Func::addToZone("script", "FOSWIKI::ATTACHMENTFIELD", <<"HERE", "JQUERYPLUGIN::SELECT2, JQUERYPLUGIN::UPLOADER");
<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsPlugin/attachmentfield.js'></script>
HERE
}
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-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/Ipaddress.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/Netmask.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/NetworkAddressField.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/Phonenumber.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/Select2.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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/Time.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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
46 changes: 36 additions & 10 deletions lib/Foswiki/Form/Topic.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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 @@ -32,6 +32,7 @@ sub new {
$this->{_formfieldClass} = 'foswikiTopicField';
$this->{_web} = $this->param("web") || $this->{session}{webName};
$this->{_url} = Foswiki::Func::expandTemplate("select2::topic::url");
$this->{_thumbnailFormat} = Foswiki::Func::expandTemplate("select2::topic::thumbnail::url");

return $this;
}
Expand Down Expand Up @@ -158,6 +159,8 @@ sub renderForEdit {
$value = $param3;
}

my $thisWeb = $topicObject->web;
my $thisTopic = $topicObject->topic;
my $baseWeb = $this->param("web") || $this->{session}{webName};
my $baseTopic = $this->{session}{topicName};

Expand All @@ -176,32 +179,37 @@ sub renderForEdit {
push @htmlData, 'data-width="' . $size . '"';

if ($this->isMultiValued) {
push @htmlData, 'data-multiple="true"';
my @topicTitles = ();
my @thumbnails = ();
foreach my $v (split(/\s*,\s*/, $value)) {
push @topicTitles, '"' . $v . '":"' . encode($this->getTopicTitle($baseWeb, $v)) . '"';
my $thumb = $this->getThumbnailUrl($baseWeb, $v);
push @thumbnails, '"' . $v .'":"'. $thumb . '"';
}
push @htmlData, "data-value-text='{" . join(', ', @topicTitles) . "}'";
push @htmlData, "data-thumbnail='{" . join(', ', @thumbnails) . "}'";
} else {
my $topicTitle = encode($this->getTopicTitle($baseWeb, $value));
push @htmlData, 'data-value-text="' . $topicTitle . '"';
my $thumb = $this->getThumbnailUrl($baseWeb, $value);
push @htmlData, 'data-thumbnail="' .$thumb. '"';
}

unless (defined $this->param("url")) {
if (defined $this->{_url}) {
my $url = Foswiki::Func::expandCommonVariables($this->{_url}, $baseTopic, $baseWeb);
my $url = Foswiki::Func::expandCommonVariables($this->{_url}, $thisTopic, $thisWeb, $topicObject);
push @htmlData, 'data-url="' . $url . '"';
}
push @htmlData, 'data-topic="' . $baseWeb . '.' . $baseTopic .'"';
push @htmlData, 'data-topic="' . $thisWeb . '.' . $thisTopic .'"';
}

while (my ($key, $val) = each %{$this->param()}) {
$key = lc(Foswiki::spaceOutWikiWord($key, "-"));
next if $key eq 'web';
push @htmlData, 'data-' . $key . '="' . $val . '"';
}

if ($this->isMultiValued) {
push @htmlData, 'data-multiple="true"';
}
push @htmlData, 'data-web="' . $baseWeb . '"';

$this->addJavascript();
$this->addStyles();
Expand All @@ -223,7 +231,7 @@ sub addJavascript {
#my $this = shift;

Foswiki::Plugins::JQueryPlugin::createPlugin("select2");
Foswiki::Func::addToZone("script", "FOSWIKI::FILEFIELD", <<"HERE", "JQUERYPLUGIN::SELECT2");
Foswiki::Func::addToZone("script", "FOSWIKI::TOPICFIELD", <<"HERE", "JQUERYPLUGIN::SELECT2");
<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsPlugin/topicfield.js'></script>
HERE
}
Expand Down Expand Up @@ -257,12 +265,30 @@ sub getTopicTitle {
# default to topic name
$title ||= $topic;

$title =~ s/\s*$//;
$title =~ s/^\s*//;
$title =~ s/^\s+|\s+$//g;

return $title;
}

sub getThumbnailUrl {
my ($this, $web, $topic, $size) = @_;

$size ||= '32x32>';

return "" unless $topic;

($web, $topic) = Foswiki::Func::normalizeWebTopicName($web, $topic);

my $result = $this->{_thumbnailFormat};
$result =~ s/\%web\%/$web/g;
$result =~ s/\%topic\%/$topic/g;
$result =~ s/\%size\%/$size/g;
$result = Foswiki::Func::expandCommonVariables($result);

return $result;
}


sub encode {
my $text = shift;

Expand Down
5 changes: 4 additions & 1 deletion lib/Foswiki/Form/User.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2010-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2010-2018 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 @@ -32,9 +32,12 @@ sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);

Foswiki::Func::readTemplate("user");

$this->{_formfieldClass} = 'foswikiUserField';
$this->{_web} = $this->param("web") || $Foswiki::cfg{UsersWebName};
$this->{_url} = Foswiki::Func::expandTemplate("select2::user::url");
$this->{_thumbnailFormat} = Foswiki::Func::expandTemplate("user::photo::thumbnail::url") || $this->{_thumbnailFormat};

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Foswiki/Plugins/MoreFormfieldsPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki -V The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2013-2018 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 @@ -25,8 +25,8 @@ use Foswiki::Plugins ();

use Error qw(:try);

our $VERSION = '4.00';
our $RELEASE = '13 Sep 2017';
our $VERSION = '4.10';
our $RELEASE = '12 Jan 2018';
our $SHORTDESCRIPTION = 'Additional formfield types for %SYSTEMWEB%.DataForms';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/MoreFormfieldsPlugin/IconService.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# MoreFormfieldsPlugin is Copyright (C) 2013-2018 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
12 changes: 6 additions & 6 deletions pub/System/MoreFormfieldsPlugin/attachmentfield.uncompressed.js
Expand Up @@ -12,15 +12,15 @@ jQuery(function($) {

function formatItem(item) {
if (item.thumbnail) {
return "<div class='image-item' style='background-image:url("+item.thumbnail + ")'>"+
return "<div class='image-item' style='background-image:url(\""+item.thumbnail + "\")'>"+
item.text +
"</div>";
} else {
return item.text;
}
}

function getResizeUrl(file) {
function getThumbnailUrl(file) {
if (file.match(/\.(gif|png|jpe?g|svg|mp4)$/)) {
return foswiki.getScriptUrlPath("rest", "ImagePlugin", "resize", {
topic: foswiki.getPreference("WEB")+"."+foswiki.getPreference("TOPIC"),
Expand Down Expand Up @@ -86,14 +86,14 @@ jQuery(function($) {
data.push({
id: this,
text: decodeURIComponent(this),
thumbnail: getResizeUrl(this)
thumbnail: getThumbnailUrl(this)
});
});
} else {
data = {
id:val,
text:val,
thumbnail: getResizeUrl(val)
thumbnail: getThumbnailUrl(val)
};
}
callback(data);
Expand All @@ -119,13 +119,13 @@ jQuery(function($) {
data.push({
id: fileName,
text: fileName,
thumbnail: getResizeUrl(fileName)
thumbnail: getThumbnailUrl(fileName)
});
} else {
data = {
id: fileName,
text: fileName,
thumbnail: getResizeUrl(fileName)
thumbnail: getThumbnailUrl(fileName)
};
}
$this.select2("data", data);
Expand Down

0 comments on commit d3b29ea

Please sign in to comment.