Skip to content

Commit

Permalink
Item9999: added time and icon formfields
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/MoreFormfieldsContrib@17784 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jun 23, 2014
1 parent 75f8825 commit 5ac871c
Show file tree
Hide file tree
Showing 15 changed files with 4,512 additions and 48 deletions.
3 changes: 2 additions & 1 deletion data/System/MoreFormfieldsAjaxHelper.txt
@@ -1,4 +1,5 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1378387359" format="1.1" reprev="7" version="7"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1403528623" format="1.1" reprev="7" version="8"}%
%META:TOPICPARENT{name="MoreFormfieldsContrib"}%
---+!! %TOPIC%

---++ topic field backend
Expand Down
5 changes: 3 additions & 2 deletions data/System/MoreFormfieldsContrib.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="autosave" date="1356278776" format="1.1" version="1"}%
%META:TOPICINFO{author="micha" comment="autosave" date="1403544053" format="1.1" version="3"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%

Expand All @@ -15,6 +15,8 @@ These are:
* =topic=
* =autofill=
* =phonenumber=
* =time=
* =icon=

---++ !ExampleForm definition

Expand All @@ -23,7 +25,6 @@ These are:
| Netmask | netmask | 15 | | netmask | |
| <nop>MacAddress | macaddress | 17 | | hardware-addresse | |


---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%
Expand Down
3 changes: 2 additions & 1 deletion lib/Foswiki/Contrib/MoreFormfieldsContrib/DEPENDENCIES
@@ -1,2 +1,3 @@
Foswiki::Plugins::JQueryPlugin,>3.31,perl,Required
Foswiki::Plugins::JQueryPlugin,>5.11,perl,Required
Foswiki::Contrib::JQSelect2Contrib,>0,perl,Required
YAML,>=0.90,cpan,Required
16 changes: 14 additions & 2 deletions lib/Foswiki/Contrib/MoreFormfieldsContrib/MANIFEST
Expand Up @@ -2,16 +2,28 @@ data/System/MoreFormfieldsAjaxHelper.txt 0644
data/System/MoreFormfieldsContrib.txt 0644
lib/Foswiki/Contrib/MoreFormfieldsContrib.pm 0644
lib/Foswiki/Form/Autofill.pm 0644
lib/Foswiki/Form/Icon.pm 0644
lib/Foswiki/Form/Id.pm 0644
lib/Foswiki/Form/Ipaddress.pm 0644
lib/Foswiki/Form/Macaddress.pm 0644
lib/Foswiki/Form/Netmask.pm 0644
lib/Foswiki/Form/NetworkAddressField.pm 0644
lib/Foswiki/Form/Phonenumber.pm 0644
lib/Foswiki/Form/Select2.pm 0644
lib/Foswiki/Form/Time.pm 0644
lib/Foswiki/Form/Topic.pm 0644
lib/Foswiki/Form/User.pm 0644
lib/Foswiki/Form/Id.pm 0644
lib/Foswiki/Form/Select2.pm 0644
lib/Foswiki/Plugins/MoreFormfieldsPlugin.pm 0644
pub/System/MoreFormfieldsContrib/clockpicker.css 0644
pub/System/MoreFormfieldsContrib/clockpicker.css.gz 0644
pub/System/MoreFormfieldsContrib/clockpicker.js 0644
pub/System/MoreFormfieldsContrib/clockpicker.js.gz 0644
pub/System/MoreFormfieldsContrib/clockpicker.uncompressed.css 0644
pub/System/MoreFormfieldsContrib/clockpicker.uncompressed.js 0644
pub/System/MoreFormfieldsContrib/iconfield.js 0644
pub/System/MoreFormfieldsContrib/iconfield.js.gz 0644
pub/System/MoreFormfieldsContrib/iconfield.uncompressed.js 0644
pub/System/MoreFormfieldsContrib/icons.yml 0644
pub/System/MoreFormfieldsContrib/Makefile 0644
pub/System/MoreFormfieldsContrib/moreformfields.css 0644
pub/System/MoreFormfieldsContrib/moreformfields.css.gz 0644
Expand Down
128 changes: 128 additions & 0 deletions lib/Foswiki/Form/Icon.pm
@@ -0,0 +1,128 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsContrib is Copyright (C) 2010-2014 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Form::Icon;

use strict;
use warnings;

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

our %icons = ();

BEGIN {
if ($Foswiki::cfg{UseLocale}) {
require locale;
import locale();
}
}

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);

my $size = $this->{size} || '';
$size =~ s/\D//g;
$size = 10 if (!$size || $size < 1);
$this->{size} = $size;

if ($this->{type} =~ /\+/) {
my %modifiers = map {lc($_) => 1} grep {!/^icon$/} split(/\+/,$this->{type});
@{$this->{modifiers}} = keys %modifiers;
$this->{groupPattern} = join("|", @{$this->{modifiers}});
}

$this->{hasMultipleGroups} = (!defined($this->{modifiers}) || scalar(@{$this->{modifiers}}) > 1);

return $this;
}

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

Foswiki::Plugins::JQueryPlugin::createPlugin("fontawesome");
Foswiki::Plugins::JQueryPlugin::createPlugin("select2");

Foswiki::Func::addToZone("script", "FOSWIKI::ICONFIELD", <<'HERE', "JQUERYPLUGIN::FONTAWESOME, JQUERYPLUGIN::SELECT2");
<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsContrib/iconfield.js'></script>
HERE

$this->readIcons();

my $html = "<select class='".$this->cssClasses("foswikiFontAwesomeIconPicker")."' style='width:".$this->{size}."em' name='".$this->{name}."'>\n";
$html .= '<option></option>';
foreach my $group (sort keys %icons) {
next if $this->{groupPattern} && $group !~ /$this->{groupPattern}/i;

$html .= " <optgroup label='$group'>\n" if scalar$this->{hasMultipleGroups};

foreach my $entry (sort {$a->{id} cmp $b->{id}} @{$icons{$group}}) {
$html .= " <option value='$entry->{id}'".($value && $entry->{id} eq $value?"selected":"").">$entry->{id}</option>\n";
}

$html .= " </optgroup>\n" if $this->{hasMultipleGroups};
}
$html .= "</select>\n";

return ('', $html);
}

sub readIcons {
my $this = shift;

return if %icons;

my $iconFile = $Foswiki::cfg{PubDir}.'/'.$Foswiki::cfg{SystemWebName}.'/MoreFormfieldsContrib/icons.yml';

my $yml = YAML::LoadFile($iconFile);


foreach my $entry (@{$yml->{icons}}) {
foreach my $cat (@{$entry->{categories}}) {
push @{$icons{$cat}}, $entry;
if ($entry->{aliases}) {
foreach my $alias (@{$entry->{aliases}}) {
my %clone = %$entry;
$clone{id} = $alias;
$clone{_isAlias} = 1;
push @{$icons{$cat}}, \%clone;
}
}
}
}
}

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

Foswiki::Plugins::JQueryPlugin::createPlugin("fontawesome");

my $displayValue = $this->getDisplayValue($value);
$format =~ s/\$value\(display\)/$displayValue/g;
$format =~ s/\$value/$value/g;

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

sub getDisplayValue {
my ( $this, $value ) = @_;

return "<i class='fa fa-$value'></i> ".$value;
}

1;
68 changes: 68 additions & 0 deletions lib/Foswiki/Form/Time.pm
@@ -0,0 +1,68 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MoreFormfieldsContrib is Copyright (C) 2010-2014 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Form::Time;

use strict;
use warnings;

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

BEGIN {
if ($Foswiki::cfg{UseLocale}) {
require locale;
import locale();
}
}

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 renderForEdit {
my ($this, $topicObject, $value) = @_;

Foswiki::Func::addToZone("script", "FOSWIKI::TIMEFIELD", <<'HERE', "JQUERYPLUGIN");
<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsContrib/clockpicker.js'></script>
<script type='text/javascript'>
jQuery(function($) {
$(".foswikiTimeField").livequery(function() {
$(this).clockpicker();
});
});
</script>
HERE

Foswiki::Func::addToZone("head", "FOSWIKI::TIMEFIELD", <<"HERE", "JQUERYPLUGIN");
<link rel='stylesheet' type='text/css' href='%PUBURLPATH%/%SYSTEMWEB%/MoreFormfieldsContrib/clockpicker.css'></script>
HERE

return (
'',
"<input type='text' name='$this->{name}' size='$this->{size}' value='$value' data-autoclose='true' class='" . $this->cssClasses('foswikiInputField', 'foswikiTimeField') . "' />",
);
}

1;

11 changes: 10 additions & 1 deletion pub/System/MoreFormfieldsContrib/Makefile
Expand Up @@ -4,6 +4,15 @@ TARGET= \
networkaddress.js \
userfield.js \
topicfield.js \
phonenumber.js
phonenumber.js \
clockpicker.js \
clockpicker.css \
iconfield.js

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

clockpicker.uncompressed.js: clockpicker/dist/jquery-clockpicker.js
@echo "creating $@"; cp $< $@

clockpicker.uncompressed.css: clockpicker/dist/jquery-clockpicker.css
@echo "creating $@"; cp $< $@

0 comments on commit 5ac871c

Please sign in to comment.