adding a few new form controls
This commit is contained in:
parent
848a106e1a
commit
4eaf8c3827
6 changed files with 477 additions and 3 deletions
|
|
@ -62,7 +62,7 @@ sub definition {
|
|||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
options=>{
|
||||
types=>{
|
||||
defaultValue=>[qw(mixed html code text)]
|
||||
},
|
||||
defaultValue=>{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use base 'WebGUI::Form::Control';
|
|||
use WebGUI::DatabaseLink;
|
||||
use WebGUI::Form::selectList;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
|
|
@ -128,6 +129,8 @@ sub toHtml {
|
|||
|
||||
=head2 toHtmlWithWrapper ( )
|
||||
|
||||
Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. Also adds manage and edit icons next to the field if the current user is in the admins group.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlWithWrapper {
|
||||
|
|
|
|||
129
lib/WebGUI/Form/float.pm
Normal file
129
lib/WebGUI/Form/float.pm
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
package WebGUI::Form::float;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::float
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Returns a floating point number (decimal) field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::text.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the superclass for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 maxlength
|
||||
|
||||
Defaults to 14. Determines the maximum number of characters allowed in this field.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
Defaults to 0. Used if no value is specified.
|
||||
|
||||
=head4 size
|
||||
|
||||
Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
maxlength=>{
|
||||
defaultValue=> 14
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
size=>{
|
||||
defaultValue=>11
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ()
|
||||
|
||||
Returns the human readable name or type of this form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
return WebGUI::International::get("float","WebGUI");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns the integer from the form post, or returns 0.0 if the post result is invalid.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{cgi}->param($self->{name});
|
||||
if ($value =~ /^[\d\-\.]+$/) {
|
||||
return $value;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a floating point field.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789-.\')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
188
lib/WebGUI/Form/group.pm
Normal file
188
lib/WebGUI/Form/group.pm
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
package WebGUI::Form::group;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Form::hiddenList;
|
||||
use WebGUI::Form::selectList;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::group
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a group chooser field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 size
|
||||
|
||||
How many rows should be displayed at once? Defaults to 1.
|
||||
|
||||
=head4 multiple
|
||||
|
||||
Set to "1" if multiple groups should be selectable. Defaults to 0.
|
||||
|
||||
=head4 excludeGroups
|
||||
|
||||
An array reference containing a list of groups to exclude from the list. Defaults to an empty array reference.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
This will be used if no value is specified. Should be passed as an array reference. Defaults to 7 (Everyone).
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
size=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>[7]
|
||||
},
|
||||
multiple=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
excludeGroups=>{
|
||||
defaultValue=>[]
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ()
|
||||
|
||||
Returns the human readable name or type of this form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
return WebGUI::International::get("group","WebGUI");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns either what's posted or if nothing comes back it returns "2" the ID of the Registered Users group.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my @data = $session{cgi}->param($self->{name});
|
||||
if (scalar(@data)) {
|
||||
return wantarray ? @data : join("\n",@data);
|
||||
}
|
||||
return wantarray ? @[2] : 2;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Returns a group pull-down field. A group pull down provides a select list that provides name value pairs for all the groups in the WebGUI system.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $where;
|
||||
if ($self->{excludeGroups}[0] ne "") {
|
||||
$where = "and groupId not in (".quoteAndJoin($self->{excludeGroups}).")";
|
||||
}
|
||||
return WebGUI::Form::selectList->new(
|
||||
options=>WebGUI::SQL->buildHashRef("select groupId,groupName from groups where showInForms=1 $where order by groupName"),
|
||||
name=>$self->{name},
|
||||
value=>$self->{value},
|
||||
extras=>$self->{extras},
|
||||
size=>$self->{size},
|
||||
multiple=>$self->{multiple},
|
||||
defaultValue=>$self->{defaultValue}
|
||||
)->toHtml;
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlAsHidden ( )
|
||||
|
||||
Creates a series of hidden fields representing the data in the list.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return WebGUI::Form::hiddenList->new(
|
||||
value=>$self->{value},
|
||||
defaultValue=>$self->{defaultValue},
|
||||
name=>$self->{name},
|
||||
options=>WebGUI::SQL->buildHashRef("select groupId,groupName from groups")
|
||||
)->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlWithWrapper ( )
|
||||
|
||||
Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. Also adds a manage icon next to the field if the current user is in the admins group.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlWithWrapper {
|
||||
my $self = shift;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $subtext;
|
||||
$subtext = .= manageIcon("op=listGroups");
|
||||
$self->{subtext} = $subtext . $self->{subtext};
|
||||
}
|
||||
return $self->SUPER::toHtmlWithWrapper;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ Package WebGUI::Form::integer
|
|||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a zip code form field.
|
||||
Creates an input field that accepts positive and negative integer.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ sub getValueFromPost {
|
|||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an input tag of type text.
|
||||
Renders an integer field.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
154
lib/WebGUI/Form/interval.pm
Normal file
154
lib/WebGUI/Form/interval.pm
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
package WebGUI::Form::interval;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use Tie::IxHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Form::hidden;
|
||||
use WebGUI::Form::integer;
|
||||
use WebGUI::Form::selectList;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::interval
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates an interval (hours, minutes, seconds, etc) selector.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
A time interval in seconds that is used if value is not specified. Defaults to 1.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
defaultValue=>{
|
||||
defaultValue=>1,
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ()
|
||||
|
||||
Returns the human readable name or type of this form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
return WebGUI::International::get("interval","WebGUI");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns either the interval that was posted (in seconds) or if nothing comes back it returns 0.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::intervalToSeconds($session{cgi}->param($self->{name}."_interval"),$session{cgi}->param($self->{name}."_units")) || 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an interval control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my %units;
|
||||
tie %units, 'Tie::IxHash';
|
||||
%units = ('seconds'=>WebGUI::International::get(704),
|
||||
'minutes'=>WebGUI::International::get(705),
|
||||
'hours'=>WebGUI::International::get(706),
|
||||
'days'=>WebGUI::International::get(700),
|
||||
'weeks'=>WebGUI::International::get(701),
|
||||
'months'=>WebGUI::International::get(702),
|
||||
'years'=>WebGUI::International::get(703));
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->{value});
|
||||
return WebGUI::Form::integer->new(
|
||||
name=>$self->{name}."_interval",
|
||||
value=>$interval,
|
||||
extras=>$self->{extras}
|
||||
)->toHtml
|
||||
.WebGUI::Form::selectList->new(
|
||||
options=>\%units
|
||||
name=>$self->{name}."_units",
|
||||
value=>[$self->{value}]
|
||||
)->toHtml;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlAsHidden ( )
|
||||
|
||||
Returns the field as hidden controls rather than displayable controls.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->{value});
|
||||
return WebGUI::Form::hidden->new(
|
||||
"name"=>$self->{name}.'_interval',
|
||||
"value"=>$interval
|
||||
)->toHtmlAsHidden
|
||||
.WebGUI::Form::hidden->new(
|
||||
"name"=>$self->{name}.'_units',
|
||||
"value"=>$units
|
||||
)->toHtmmlAsHidden;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue