Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item9999: added time and icon formfields
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
Showing
15 changed files
with
4,512 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.