From 3e587762beeec624cc46bb8b355714d396956a44 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 23 Aug 2005 15:58:55 +0000 Subject: [PATCH] renamed the form fields to upper case for proper perl style --- lib/WebGUI/Form.pm | 9 +- lib/WebGUI/Form/Asset.pm | 129 ++++++++++++++++++++ lib/WebGUI/Form/Button.pm | 96 +++++++++++++++ lib/WebGUI/Form/CheckList.pm | 164 ++++++++++++++++++++++++++ lib/WebGUI/Form/Checkbox.pm | 118 +++++++++++++++++++ lib/WebGUI/Form/Codearea.pm | 72 ++++++++++++ lib/WebGUI/Form/Color.pm | 84 +++++++++++++ lib/WebGUI/Form/Combo.pm | 94 +++++++++++++++ lib/WebGUI/Form/ContentType.pm | 145 +++++++++++++++++++++++ lib/WebGUI/Form/DatabaseLink.pm | 156 ++++++++++++++++++++++++ lib/WebGUI/Form/Date.pm | 156 ++++++++++++++++++++++++ lib/WebGUI/Form/DateTime.pm | 148 +++++++++++++++++++++++ lib/WebGUI/Form/Email.pm | 87 ++++++++++++++ lib/WebGUI/Form/FieldType.pm | 164 ++++++++++++++++++++++++++ lib/WebGUI/Form/File.pm | 156 ++++++++++++++++++++++++ lib/WebGUI/Form/FilterContent.pm | 142 ++++++++++++++++++++++ lib/WebGUI/Form/Float.pm | 129 ++++++++++++++++++++ lib/WebGUI/Form/Group.pm | 195 ++++++++++++++++++++++++++++++ lib/WebGUI/Form/HTMLArea.pm | 4 +- lib/WebGUI/Form/Hidden.pm | 108 +++++++++++++++++ lib/WebGUI/Form/HiddenList.pm | 140 ++++++++++++++++++++++ lib/WebGUI/Form/Integer.pm | 129 ++++++++++++++++++++ lib/WebGUI/Form/Interval.pm | 158 +++++++++++++++++++++++++ lib/WebGUI/Form/LdapLink.pm | 196 +++++++++++++++++++++++++++++++ lib/WebGUI/Form/Password.pm | 105 +++++++++++++++++ lib/WebGUI/Form/Phone.pm | 87 ++++++++++++++ lib/WebGUI/Form/Radio.pm | 111 +++++++++++++++++ lib/WebGUI/Form/RadioList.pm | 122 +++++++++++++++++++ lib/WebGUI/Form/ReadOnly.pm | 95 +++++++++++++++ lib/WebGUI/Form/SelectList.pm | 177 ++++++++++++++++++++++++++++ lib/WebGUI/Form/Submit.pm | 69 +++++++++++ lib/WebGUI/Form/Template.pm | 150 +++++++++++++++++++++++ lib/WebGUI/Form/Text.pm | 104 ++++++++++++++++ lib/WebGUI/Form/Textarea.pm | 115 ++++++++++++++++++ lib/WebGUI/Form/TimeField.pm | 146 +++++++++++++++++++++++ lib/WebGUI/Form/Url.pm | 119 +++++++++++++++++++ lib/WebGUI/Form/WhatNext.pm | 124 +++++++++++++++++++ lib/WebGUI/Form/YesNo.pm | 134 +++++++++++++++++++++ lib/WebGUI/Form/Zipcode.pm | 115 ++++++++++++++++++ lib/WebGUI/FormProcessor.pm | 7 +- lib/WebGUI/HTMLForm.pm | 6 +- lib/WebGUI/TabForm.pm | 4 +- 42 files changed, 4753 insertions(+), 16 deletions(-) create mode 100644 lib/WebGUI/Form/Asset.pm create mode 100644 lib/WebGUI/Form/Button.pm create mode 100644 lib/WebGUI/Form/CheckList.pm create mode 100644 lib/WebGUI/Form/Checkbox.pm create mode 100644 lib/WebGUI/Form/Codearea.pm create mode 100644 lib/WebGUI/Form/Color.pm create mode 100644 lib/WebGUI/Form/Combo.pm create mode 100644 lib/WebGUI/Form/ContentType.pm create mode 100644 lib/WebGUI/Form/DatabaseLink.pm create mode 100644 lib/WebGUI/Form/Date.pm create mode 100644 lib/WebGUI/Form/DateTime.pm create mode 100644 lib/WebGUI/Form/Email.pm create mode 100644 lib/WebGUI/Form/FieldType.pm create mode 100644 lib/WebGUI/Form/File.pm create mode 100644 lib/WebGUI/Form/FilterContent.pm create mode 100644 lib/WebGUI/Form/Float.pm create mode 100644 lib/WebGUI/Form/Group.pm create mode 100644 lib/WebGUI/Form/Hidden.pm create mode 100644 lib/WebGUI/Form/HiddenList.pm create mode 100644 lib/WebGUI/Form/Integer.pm create mode 100644 lib/WebGUI/Form/Interval.pm create mode 100644 lib/WebGUI/Form/LdapLink.pm create mode 100644 lib/WebGUI/Form/Password.pm create mode 100644 lib/WebGUI/Form/Phone.pm create mode 100644 lib/WebGUI/Form/Radio.pm create mode 100644 lib/WebGUI/Form/RadioList.pm create mode 100644 lib/WebGUI/Form/ReadOnly.pm create mode 100644 lib/WebGUI/Form/SelectList.pm create mode 100644 lib/WebGUI/Form/Submit.pm create mode 100644 lib/WebGUI/Form/Template.pm create mode 100644 lib/WebGUI/Form/Text.pm create mode 100644 lib/WebGUI/Form/Textarea.pm create mode 100644 lib/WebGUI/Form/TimeField.pm create mode 100644 lib/WebGUI/Form/Url.pm create mode 100644 lib/WebGUI/Form/WhatNext.pm create mode 100644 lib/WebGUI/Form/YesNo.pm create mode 100644 lib/WebGUI/Form/Zipcode.pm diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 67561400c..775dce572 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -64,7 +64,7 @@ Dynamically creates functions on the fly for all the different form control type sub AUTOLOAD { our $AUTOLOAD; - my $name = (split /::/, $AUTOLOAD)[-1]; + my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); my @params = @_; my $cmd = "use WebGUI::Form::".$name; eval ($cmd); @@ -124,11 +124,11 @@ The field options. See the documentation for the desired field for more informat =cut sub dynamicField { - my $fieldType = shift; + my $fieldType = ucfirst(shift); my $param = shift; # Set options for fields that use a list. - if (isIn($fieldType,qw(selectList checkList radioList))) { + if (isIn($fieldType,qw(SelectList CheckList RadioList))) { delete $param->{size}; my %options; tie %options, 'Tie::IxHash'; @@ -142,7 +142,7 @@ sub dynamicField { $param->{options} = \%options; } # Convert value to list for selectList / checkList - if (isIn($fieldType,qw(selectList checkList)) && ref $param->{value} ne "ARRAY") { + if (isIn($fieldType,qw(SelectList CheckList)) && ref $param->{value} ne "ARRAY") { my @defaultValues; foreach (split(/\n/, $param->{value})) { s/\s+$//; # remove trailing spaces @@ -154,7 +154,6 @@ sub dynamicField { # Return the appropriate field. no strict 'refs'; return &$fieldType($param); - } diff --git a/lib/WebGUI/Form/Asset.pm b/lib/WebGUI/Form/Asset.pm new file mode 100644 index 000000000..95edf8238 --- /dev/null +++ b/lib/WebGUI/Form/Asset.pm @@ -0,0 +1,129 @@ +package WebGUI::Form::Asset; + +=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::Asset; +use WebGUI::Form::Button; +use WebGUI::Form::Hidden; +use WebGUI::Form::Text; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Asset + +=head1 DESCRIPTION + +Creates an asset selector 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 name + +The name of the field. Defaults to "asset". + +=head4 class + +Limits the list of selectable assets to a specific class, such as "WebGUI::Asset::Wobject::Article", specified by this parameter. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=> "asset" + }, + class=>{ + defaultValue=> undef + }, + }); + 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("asset","Asset"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an asset selector. + +=cut + +sub toHtml { + my $self = shift; + my $asset = WebGUI::Asset->newByDynamicClass($self->{value}) || WebGUI::Asset->getRoot; + return WebGUI::Form::Hidden->new( + name=>$self->{name}, + extras=>$self->{extras}, + value=>$asset->getId, + id=>$self->{id} + )->toHtml + .WebGUI::Form::Text->new( + name=>$self->{name}."_display", + extras=>' readonly="1" ', + value=>$asset->get("title"), + id=>$self->{id}."_display" + )->toHtml + .WebGUI::Form::Button->new( + value=>"...", + extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$self->{class}."&formId=".$self->{id}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"' + )->toHtml; +} + +1; + diff --git a/lib/WebGUI/Form/Button.pm b/lib/WebGUI/Form/Button.pm new file mode 100644 index 000000000..65733e95c --- /dev/null +++ b/lib/WebGUI/Form/Button.pm @@ -0,0 +1,96 @@ +package WebGUI::Form::Button; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Button + +=head1 DESCRIPTION + +Creates a form button. + +=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 + +The default text to appear on the button. Defaults to an internationalized version of the word "save". + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + defaultValue=>{ + defaultValue=>WebGUI::International::get(62,"WebGUI") + }, + }); + 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("button","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a button. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixQuotes($self->{value}); + return '{extras}.' />'; +} + +1; + diff --git a/lib/WebGUI/Form/CheckList.pm b/lib/WebGUI/Form/CheckList.pm new file mode 100644 index 000000000..7500e8ccd --- /dev/null +++ b/lib/WebGUI/Form/CheckList.pm @@ -0,0 +1,164 @@ +package WebGUI::Form::CheckList; + +=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::Checkbox; +use WebGUI::Form::HiddenList; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::CheckList + +=head1 DESCRIPTION + +Creates a series of check box form fields. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Control. Also take a look ath WebGUI::Form::Checkbox as this class creates a list of checkboxes. + +=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 options + +A hash reference containing key values that will be returned with the form post and displayable text pairs. Defaults to an empty hash reference. + +=head4 defaultValue + +An array reference of the items to be checked if no value is specified. Defaults to an empty array reference. + +=head4 vertical + +Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + options=>{ + defaultValue=>{} + }, + defaultValue=>{ + defaultValue=>[], + }, + vertical=>{ + defaultValue=>0 + } + }); + 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("941","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. + +=cut + +sub getValueFromPost { + my $self = shift; + my @data = $session{cgi}->param($self->{name}); + return wantarray ? @data : join("\n",@data); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a series of checkboxes. + +=cut + +sub toHtml { + my $self = shift; + my $output; + foreach my $key (keys %{$self->{options}}) { + my $checked = 0; + foreach my $item (@{$self->{value}}) { + if ($item eq $key) { + $checked = 1; + } + } + $output .= WebGUI::Form::Checkbox->new({ + name=>$self->{name}, + value=>$key, + extras=>$self->{extras}, + checked=>$checked + })->toHtml; + $output .= ${$self->{options}}{$key}; + if ($self->{vertical}) { + $output .= "
\n"; + } else { + $output .= "    \n"; + } + } + return $output; +} + +#------------------------------------------------------------------- + +=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=>$self->{options} + )->toHtmlAsHidden; +} + +1; + diff --git a/lib/WebGUI/Form/Checkbox.pm b/lib/WebGUI/Form/Checkbox.pm new file mode 100644 index 000000000..bbfb686bb --- /dev/null +++ b/lib/WebGUI/Form/Checkbox.pm @@ -0,0 +1,118 @@ +package WebGUI::Form::Checkbox; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Checkbox + +=head1 DESCRIPTION + +Creates a check box form 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 checked + +Defaults to "0". Set to "1" if this field should be checked. + +=head4 defaultValue + +The value returned by this field if it is checked and no value is specified. Defaults to "1". + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + checked=>{ + defaultValue=> 0 + }, + defaultValue=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + + +#------------------------------------------------------------------- + +=head2 generateIdParameter ( ) + +A class method that returns a value to be used as the autogenerated ID for this field instance. Returns undef because this field type can have more than one with the same name, therefore autogenerated ID's aren't terribly useful. + +=cut + +sub generateIdParameter { + return undef +} + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("943","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders and input tag of type checkbox. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value}))); + my $checkedText = ' checked="checked"' if ($self->{checked}); + my $idText = ' id="'.$self->{id}.'" ' if ($self->{id}); + return '{extras}.' />'; +} + + +1; + diff --git a/lib/WebGUI/Form/Codearea.pm b/lib/WebGUI/Form/Codearea.pm new file mode 100644 index 000000000..2d76ce14b --- /dev/null +++ b/lib/WebGUI/Form/Codearea.pm @@ -0,0 +1,72 @@ +package WebGUI::Form::Codearea; + +=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::Textarea'; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::Codearea + +=head1 DESCRIPTION + +Creates a code area form field, which is just like a text area except stretches to fit it's space and allows tabs in it's content. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Textarea. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("codearea","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a code area field. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/TabFix.js',{type=>"text/javascript"}); + $self->{extras} .= ' style="width: 99%; min-width: 440px; height: 400px" onkeypress="return TabFix_keyPress(event)" onkeydown="return TabFix_keyDown(event)"'; + return $self->SUPER::toHtml; +} + + +1; + diff --git a/lib/WebGUI/Form/Color.pm b/lib/WebGUI/Form/Color.pm new file mode 100644 index 000000000..3b3f637b8 --- /dev/null +++ b/lib/WebGUI/Form/Color.pm @@ -0,0 +1,84 @@ +package WebGUI::Form::Color; + +=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::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::Color + +=head1 DESCRIPTION + +Creates a color picker which returns hex colors like #000000. + +=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 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("color","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a hex color like "#000000". Returns undef if the return value is not a valid color. + +=cut + +sub getValueFromPost { + my $self = shift; + my $color = $session{cgi}->param($self->{name}); + return undef unless $color =~ /\#\w{6}/; + return $color; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a color picker control. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/colorPicker.js',{ type=>'text/javascript' }); + return ''; +} + +1; + diff --git a/lib/WebGUI/Form/Combo.pm b/lib/WebGUI/Form/Combo.pm new file mode 100644 index 000000000..fcc99ea13 --- /dev/null +++ b/lib/WebGUI/Form/Combo.pm @@ -0,0 +1,94 @@ +package WebGUI::Form::Combo; + +=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::SelectList'; +use WebGUI::Form::Text; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Combo + +=head1 DESCRIPTION + +Creates a select list merged with a text box form control. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::SelectList. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("combobox","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. + +=cut + +sub getValueFromPost { + my $self = shift; + if ($session{cgi}->param($self->{name}."_new")) { + return $session{cgi}->param($self->{name}."_new"); + } + return $self->SUPER::getValueFromPost; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a combo box form control. + +=cut + +sub toHtml { + my $self = shift; + $self->{options}->{''} = '['.WebGUI::International::get(582).']'; + $self->{options}->{_new_} = WebGUI::International::get(581).'->'; + return $self->SUPER::toHtml + .WebGUI::Form::Text->new( + size=>$session{setting}{textBoxSize}-5, + name=>$self->{name}."_new", + id=>$self->{id}."_new" + )->toHtml; +} + + + +1; + diff --git a/lib/WebGUI/Form/ContentType.pm b/lib/WebGUI/Form/ContentType.pm new file mode 100644 index 000000000..c9166b143 --- /dev/null +++ b/lib/WebGUI/Form/ContentType.pm @@ -0,0 +1,145 @@ +package WebGUI::Form::ContentType; + +=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::SelectList; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::ContentType + +=head1 DESCRIPTION + +Creates a content type selector which can be used in conjunction with WebGUI::HTML::filter(). + +=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 types + +An array reference of field types to be displayed. The types are "mixed", "html", "code", and "text". Defaults to all. + +=head4 defaultValue + +An array reference of the items to be checked if no value is specified. Defaults to "mixed". Possible values are "mixed", "code", "html", and "text". + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + types=>{ + defaultValue=>[qw(mixed html code text)] + }, + defaultValue=>{ + defaultValue=>"mixed", + } + }); + 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("1007","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns either what's posted or if nothing comes back it returns "mixed". + +=cut + +sub getValueFromPost { + my $self = shift; + return $session{cgi}->param($self->{name}) || "mixed"; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a select list form control. + +=cut + +sub toHtml { + my $self = shift; + my %types; + foreach my $type (@{$self->{types}}) { + if ($type eq "text") { + $types{text} = WebGUI::International::get(1010); + } elsif ($type eq "mixed") { + $types{mixed} = WebGUI::International::get(1008); + } elsif ($type eq "code") { + $types{code} = WebGUI::International::get(1011); + } elsif ($type eq "html") { + $types{html} = WebGUI::International::get(1009); + } + } + return WebGUI::Form::SelectList->new( + options=>\%types, + id=>$self->{id}, + name=>$self->{name}, + value=>[$self->{value}], + extras=>$self->{extras}, + defaultValue=>[$self->{defaultValue}] + )->toHtml; + +} + + + +1; + diff --git a/lib/WebGUI/Form/DatabaseLink.pm b/lib/WebGUI/Form/DatabaseLink.pm new file mode 100644 index 000000000..f50a9ada7 --- /dev/null +++ b/lib/WebGUI/Form/DatabaseLink.pm @@ -0,0 +1,156 @@ +package WebGUI::Form::DatabaseLink; + +=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::DatabaseLink; +use WebGUI::Form::SelectList; +use WebGUI::Grouping; +use WebGUI::Icon; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::URL; + +=head1 NAME + +Package WebGUI::Form::DatabaseLink + +=head1 DESCRIPTION + +Creates a database connection chooser control. + +=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 name + +The identifier for this field. Defaults to "databaseLinkId". + +=head4 defaultValue + +A database link id. Defaults to "0", which is the WebGUI database. + +=head4 afterEdit + +A URL that will be acted upon after editing a database link. + +=head4 hoverHelp + +A tooltip to tell the user what to do with the field. Defaults a standard piece of help for Database Links. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=>"databaseLinkId" + }, + defaultValue=>{ + defaultValue=>0 + }, + afterEdit=>{ + defaultValue=>undef + }, + hoverHelp=>{ + defaultValue=>WebGUI::International::get('1075 description') + }, + }); + 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("1075","WebGUI"); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a database connection picker control. + +=cut + +sub toHtml { + my $self = shift; + return WebGUI::Form::SelectList->new( + id=>$self->{id}, + name=>$self->{name}, + options=>WebGUI::DatabaseLink::getList(), + value=>[$self->{value}], + extras=>$self->{extras} + )->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 { + my $self = shift; + if (WebGUI::Grouping::isInGroup(3)) { + my $subtext; + if ($self->{afterEdit}) { + $subtext = editIcon("op=editDatabaseLink&lid=".$self->{value}."&afterEdit=".WebGUI::URL::escape($self->{afterEdit})); + } + $subtext .= manageIcon("op=listDatabaseLinks"); + $self->{subtext} = $subtext . $self->{subtext}; + } + return $self->SUPER::toHtmlWithWrapper; +} + + + + +1; + diff --git a/lib/WebGUI/Form/Date.pm b/lib/WebGUI/Form/Date.pm new file mode 100644 index 000000000..35e67f4ff --- /dev/null +++ b/lib/WebGUI/Form/Date.pm @@ -0,0 +1,156 @@ +package WebGUI::Form::Date; + +=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::DateTime; +use WebGUI::Form::text; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::Date + +=head1 DESCRIPTION + +Accepts and returns and epoch date and creates a date picker control. + +=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 10. Determines the maximum number of characters allowed in this field. + +=head4 size + +Defaults to 10. The displayed size of the box for the date to be typed in. + +=head4 noDate + +By default a date is placed in the value field. Set this to "1" to leave it empty. + +=head4 defaultValue + +If no value is specified, this will be used. Defaults to today and now. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + defaultValue=>{ + defaultValue=>time() + }, + maxlength=>{ + defaultValue=> 10 + }, + size=>{ + defaultValue=> 10 + }, + noDate=>{ + defaultValue=>0 + } + }); + 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("479","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a validated form post result. If the result does not pass validation, it returns undef instead. + +=cut + +sub getValueFromPost { + my $self = shift; + return WebGUI::DateTime::setToEpoch($session{cgi}->param($self->{name})); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a date picker control. + +=cut + +sub toHtml { + my $self = shift; + $self->{value} = WebGUI::DateTime::epochToSet($self->{value}) unless ($self->{noDate} && $self->{value} eq ''); + my $language = WebGUI::International::getLanguage($session{user}{language},"languageAbbreviation"); + unless ($language) { + $language = WebGUI::International::getLanguage("English","languageAbbreviation"); + } + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ type=>'text/javascript' }); + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' }); + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ type=>'text/javascript' }); + WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" }); + my $mondayFirst = $session{user}{firstDayOfWeek} ? "true" : "false"; + return WebGUI::Form::Text->new( + name=>$self->{name}, + value=>$self->{value}, + extras=>$self->{extras}, + size=>$self->{size}, + maxlength=>$self->{maxlength}, + id=>$self->{id} + )->toHtml . ''; +} + +1; + diff --git a/lib/WebGUI/Form/DateTime.pm b/lib/WebGUI/Form/DateTime.pm new file mode 100644 index 000000000..a288d9dcc --- /dev/null +++ b/lib/WebGUI/Form/DateTime.pm @@ -0,0 +1,148 @@ +package WebGUI::Form::DateTime; + +=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::DateTime; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::DateTime + +=head1 DESCRIPTION + +Accepts and returns and epoch date and creates a date picker control. + +=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 19. Determines the maximum number of characters allowed in this field. + +=head4 size + +Defaults to 19. The displayed size of the box for the date to be typed in. + +=head4 defaultValue + +If no value is specified, this will be used. Defaults to today and now. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + defaultValue=>{ + defaultValue=>time() + }, + maxlength=>{ + defaultValue=> 19 + }, + size=>{ + defaultValue=> 19 + } + }); + 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("972","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a validated form post result. If the result does not pass validation, it returns undef instead. + +=cut + +sub getValueFromPost { + my $self = shift; + return WebGUI::DateTime::setToEpoch($session{cgi}->param($self->{name})); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a date picker control. + +=cut + +sub toHtml { + my $self = shift; + my $value = WebGUI::DateTime::epochToSet($self->{value},1); + my $language = WebGUI::International::getLanguage($session{user}{language},"languageAbbreviation"); + unless ($language) { + $language = WebGUI::International::getLanguage("English","languageAbbreviation"); + } + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ type=>'text/javascript' }); + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' }); + WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ type=>'text/javascript' }); + WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" }); + my $mondayFirst = $session{user}{firstDayOfWeek} ? "true" : "false"; + return WebGUI::Form::Text->new( + name=>$self->{name}, + value=>$value, + size=>$self->{size}, + extras=>$self->{extras}, + id=>$self->{id}, + maxlength=>$self->{maxlength} + )->toHtml . ''; +} + +1; + diff --git a/lib/WebGUI/Form/Email.pm b/lib/WebGUI/Form/Email.pm new file mode 100644 index 000000000..eb64265ea --- /dev/null +++ b/lib/WebGUI/Form/Email.pm @@ -0,0 +1,87 @@ +package WebGUI::Form::Email; + +=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::Email + +=head1 DESCRIPTION + +Creates an email 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 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("480","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a validated email address. If the result does not pass validation, it returns undef instead. + +=cut + +sub getValueFromPost { + my $self = shift; + my $value = $session{cgi}->param($self->{name}); + if ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) { + return $value; + } + return undef; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an email address field. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ type=>'text/javascript' }); + $self->{extras} .= ' onchange="emailCheck(this.value)" '; + return $self->SUPER::toHtml; +} + +1; + diff --git a/lib/WebGUI/Form/FieldType.pm b/lib/WebGUI/Form/FieldType.pm new file mode 100644 index 000000000..5ee0bf723 --- /dev/null +++ b/lib/WebGUI/Form/FieldType.pm @@ -0,0 +1,164 @@ +package WebGUI::Form::FieldType; + +=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::SelectList; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::FieldType + +=head1 DESCRIPTION + +Creates a form control that will allow you to select a form control type. + +=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 + +Defaults to 1. How many characters tall should this control be represented. + +=head4 types + +An array reference containing the form control types to be selectable. Defaults to all available types. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + size=>{ + defaultValue=>1 + }, + types=>{ + defaultValue=>$class->getTypes + } + }); + 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("744","WebGUI"); +} + +#------------------------------------------------------------------- + +=head2 getTypes ( ) + +A class method that returns an array reference of all the form control types present in the system. + +=cut + +sub getTypes { + my $class = shift; + opendir(DIR,$session{config}{webguiRoot}."/lib/WebGUI/Form/"); + my @rawTypes = readdir(DIR); + closedir(DIR); + my @types; + foreach my $type (@rawTypes) { + if ($type =~ /^(.*)\.pm$/) { + next if ($1 eq "Control"); + push(@types,$1); + } + } + return \@types; +} + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns either what's posted or if nothing comes back it returns "text". + +=cut + +sub getValueFromPost { + my $self = shift; + return $session{cgi}->param($self->{name}) || "text"; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a question selector asking the user where they want to go. + +=cut + +sub toHtml { + my $self = shift; + my %options; + foreach my $type (@{$self->{types}}) { + my $class = "WebGUI::Form::".$type; + my $cmd = "use ".$class; + eval ($cmd); + if ($@) { + WebGUI::ErrorHandler::error("Couldn't compile form control: ".$type.". Root cause: ".$@); + next; + } + $options{$type} = $class->getName; + } + return WebGUI::Form::SelectList->new( + id=>$self->{id}, + name=>$self->{name}, + options=>\%options, + value=>[$self->{value}], + extras=>$self->{extras}, + size=>$self->{size} + )->toHtml; +} + + + +1; + diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm new file mode 100644 index 000000000..fbc8d7cac --- /dev/null +++ b/lib/WebGUI/Form/File.pm @@ -0,0 +1,156 @@ +package WebGUI::Form::File; + +=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::International; +use WebGUI::Session; +use WebGUI::Storage; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::File + +=head1 DESCRIPTION + +Creates a text input box form 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 name + +If no name is specified a default name of "file" will be used. + +=head4 maxAttachments + +Defaults to 1. Determines how many files the user can upload with this form control. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + name=>{ + defaultValue=>"file" + }, + maxAttachments=>{ + 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("file","WebGUI"); +} + + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the storageId for the storage location that the file(s) got uploaded to. Returns undef if no files were uploaded. + +=cut + +sub getValueFromPost { + my $self = shift; + my $storage = WebGUI::Storage->create; + $storage->addFileFromFormPost($self->{name}); + my @files = $storage->getFiles; + if (scalar(@files) < 1) { + $storage->delete; + return undef; + } else { + return $storage->getId; + } +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a file upload control. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"}); + my $uploadControl = ''; + return $uploadControl; +} + +#------------------------------------------------------------------- + +=head4 toHtmlAsHidden ( ) + +Returns undef. + +=cut + +sub toHtmlAsHidden { + return undef; +} + + +1; + diff --git a/lib/WebGUI/Form/FilterContent.pm b/lib/WebGUI/Form/FilterContent.pm new file mode 100644 index 000000000..4d7262f76 --- /dev/null +++ b/lib/WebGUI/Form/FilterContent.pm @@ -0,0 +1,142 @@ +package WebGUI::Form::FilterContent; + +=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::Form::SelectList; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::FilterContent + +=head1 DESCRIPTION + +Creates a select list containing the content filter options. This is for use with WebGUI::HTML::filter(). + +=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 name + +The name of this field to be passed through the URI. Defaults to "filterContent". + +=head4 hoverHelp + +A tooltip for what to do with this field. Defaults to a general explaination of content filters. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=>"filterContent" + }, + hoverHelp=>{ + defaultValue=>WebGUI::International::get('418 description') + } + }); + 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("418","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns either what's posted or if nothing comes back it returns "most". + +=cut + +sub getValueFromPost { + my $self = shift; + return $session{cgi}->param($self->{name}) || "most"; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Returns a select list containing the content filter options. This is for use with WebGUI::HTML::filter(). + +=cut + +sub toHtml { + my $self = shift; + my %filter; + tie %filter, 'Tie::IxHash'; + %filter = ( + 'none'=>WebGUI::International::get(420), + 'macros'=>WebGUI::International::get(891), + 'javascript'=>WebGUI::International::get(526), + 'most'=>WebGUI::International::get(421), + 'all'=>WebGUI::International::get(419) + ); + return WebGUI::Form::SelectList->new( + id=>$self->{id}, + options=>\%filter, + name=>$self->{name}, + value=>[$self->{value}], + extras=>$self->{extras}, + defaultValue=>[$self->{defaultValue}] + )->toHtml; + +} + + +1; + diff --git a/lib/WebGUI/Form/Float.pm b/lib/WebGUI/Form/Float.pm new file mode 100644 index 000000000..09d7a3816 --- /dev/null +++ b/lib/WebGUI/Form/Float.pm @@ -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; + diff --git a/lib/WebGUI/Form/Group.pm b/lib/WebGUI/Form/Group.pm new file mode 100644 index 000000000..354aeb59e --- /dev/null +++ b/lib/WebGUI/Form/Group.pm @@ -0,0 +1,195 @@ +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). + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + 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}, + id=>$self->{id}, + 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 = manageIcon("op=listGroups"); + $self->{subtext} = $subtext . $self->{subtext}; + } + return $self->SUPER::toHtmlWithWrapper; +} + + +1; + diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index 0f435c16f..ee2cd8bf5 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -15,7 +15,7 @@ package WebGUI::Form::HTMLArea; =cut use strict; -use base 'WebGUI::Form::textarea'; +use base 'WebGUI::Form::Textarea'; use WebGUI::Asset::RichEdit; use WebGUI::HTML; use WebGUI::International; @@ -32,7 +32,7 @@ Creates an HTML Area form control if the user's browser supports it. This basica =head1 SEE ALSO -This is a subclass of WebGUI::Form::textarea. +This is a subclass of WebGUI::Form::Textarea. =head1 METHODS diff --git a/lib/WebGUI/Form/Hidden.pm b/lib/WebGUI/Form/Hidden.pm new file mode 100644 index 000000000..165f47567 --- /dev/null +++ b/lib/WebGUI/Form/Hidden.pm @@ -0,0 +1,108 @@ +package WebGUI::Form::Hidden; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Hidden + +=head1 DESCRIPTION + +Creates a hidden 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 generateIdParameter ( ) + +A class method that returns a value to be used as the autogenerated ID for this field instance. Returns undef because this field type can have more than one with the same name, therefore autogenerated ID's aren't terribly useful. + +=cut + +sub generateIdParameter { + return undef +} + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("hidden","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtml { + my $self = shift; + $self->toHtmlAsHidden; +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Renders an input tag of type hidden. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value}))); + my $idText = ' id="'.$self->{id}.'" ' if ($self->{id}); + return '{extras}.$idText.' />'."\n"; +} + +#------------------------------------------------------------------- + +=head2 toHtmlWithWrapper ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtmlWithWrapper { + my $self = shift; + return $self->toHtmlAsHidden; +} + + +1; + diff --git a/lib/WebGUI/Form/HiddenList.pm b/lib/WebGUI/Form/HiddenList.pm new file mode 100644 index 000000000..5a0acf1ee --- /dev/null +++ b/lib/WebGUI/Form/HiddenList.pm @@ -0,0 +1,140 @@ +package WebGUI::Form::HiddenList; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::HiddenList + +=head1 DESCRIPTION + +Creates a list of hidden fields. This is to be used by list type controls (selectList, checkList, etc) to store their vaiuses as hidden values. + +=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 options + +A hash reference containing name value pairs. The name of each pair will be used to fill the value attribute of the hidden field. Defaults to an empty hash reference. + +=head4 defaultValue + +value and defaultValue are array referneces containing the names from the options list that should be stored. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + options=>{ + defaultValue=>{} + }, + defaultValue=>{ + 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("hidden list","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtml { + my $self = shift; + $self->toHtmlAsHidden; +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Renders an input tag of type hidden. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + my $output; + foreach my $key (keys %{$self->{options}}) { + foreach my $item (@{$self->{values}}) { + if ($item eq $key) { + $output .= WebGUI::Form::Hidden->( + name=>$self->{name}, + value=>$key + ); + } + } + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 toHtmlWithWrapper ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtmlWithWrapper { + my $self = shift; + return $self->toHtmlAsHidden; +} + + +1; + diff --git a/lib/WebGUI/Form/Integer.pm b/lib/WebGUI/Form/Integer.pm new file mode 100644 index 000000000..295b32db5 --- /dev/null +++ b/lib/WebGUI/Form/Integer.pm @@ -0,0 +1,129 @@ +package WebGUI::Form::Integer; + +=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::Integer + +=head1 DESCRIPTION + +Creates an input field that accepts positive and negative integer. + +=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 11. 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=> 11 + }, + 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("482","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the integer from the form post, or returns 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; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an integer 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; + diff --git a/lib/WebGUI/Form/Interval.pm b/lib/WebGUI/Form/Interval.pm new file mode 100644 index 000000000..9d597370e --- /dev/null +++ b/lib/WebGUI/Form/Interval.pm @@ -0,0 +1,158 @@ +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 warnings; +use base qw(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}); + my $out = WebGUI::Form::Integer->new( + name=>$self->{name}."_interval", + value=>$interval, + extras=>$self->{extras}, + id=>$self->{id}."_interval", + )->toHtml; + $out .= WebGUI::Form::SelectList->new( + options=>\%units, + name=>$self->{name}."_units", + id=>$self->{id}."_units", + value=>[$units] + )->toHtml; + return $out; +} + + +#------------------------------------------------------------------- + +=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; + diff --git a/lib/WebGUI/Form/LdapLink.pm b/lib/WebGUI/Form/LdapLink.pm new file mode 100644 index 000000000..59f1db467 --- /dev/null +++ b/lib/WebGUI/Form/LdapLink.pm @@ -0,0 +1,196 @@ +package WebGUI::Form::LdapLink; + +=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::LDAPLink; +use WebGUI::Form::SelectList; +use WebGUI::Form::HiddenList; +use WebGUI::Grouping; +use WebGUI::Icon; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::URL; + +=head1 NAME + +Package WebGUI::Form::LdapLink + +=head1 DESCRIPTION + +Creates an LDAP connection chooser control. + +=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 name + +The identifier for this field. Defaults to "ldapLinkId". + +=head4 defaultValue + +An LDAP link id. Defaults to "0", which is nothing. + +=head4 afterEdit + +A URL that will be acted upon after editing an LDAP link. + +=head4 size + +The number of characters tall this list should be. Defaults to '1'. + +=head4 multiple + +Boolean indicating whether the user can select multiple items from this list like a checkList. Defaults to "0". + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=>"ldapLinkId" + }, + defaultValue=>{ + defaultValue=>[0] + }, + size=>{ + defaultValue=>1 + }, + multiple=>{ + defaultValue=>0 + }, + afterEdit=>{ + defaultValue=>undef + } + }); + 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("LDAPLink_1075","AuthLDAP"); +} + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. + +=cut + +sub getValueFromPost { + my $self = shift; + my @data = $session{cgi}->param($self->{name}); + return wantarray ? @data : join("\n",@data); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a database connection picker control. + +=cut + +sub toHtml { + my $self = shift; + return WebGUI::Form::SelectList->new( + name=>$self->{name}, + id=>$self->{id}, + options=>WebGUI::LDAPLink::getList(), + value=>$self->{value}, + multiple=>$self->{multiple}, + size=>$self->{size}, + extras=>$self->{extras} + )->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}, + name=>$self->{name}, + options=>WebGUI::LDAPLink::getList() + )->toHtmlAsHidden; +} + +#------------------------------------------------------------------- + +=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 { + my $self = shift; + if (WebGUI::Grouping::isInGroup(3)) { + my $subtext; + if ($self->{afterEdit}) { + $subtext = editIcon("op=editLDAPLink&llid=".$self->{value}."&afterEdit=".WebGUI::URL::escape($self->{afterEdit})); + } + $subtext .= manageIcon("op=listLDAPLinks"); + $self->{subtext} = $subtext . $self->{subtext}; + } + return $self->SUPER::toHtmlWithWrapper; +} + + + +1; + diff --git a/lib/WebGUI/Form/Password.pm b/lib/WebGUI/Form/Password.pm new file mode 100644 index 000000000..1629a99f4 --- /dev/null +++ b/lib/WebGUI/Form/Password.pm @@ -0,0 +1,105 @@ +package WebGUI::Form::Password; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Password + +=head1 DESCRIPTION + +Creates a password input box form 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 maxlength + +Defaults to 35. Determines the maximum number of characters allowed in this field. + +=head4 size + +Defaults to 30. Specifies how big of a text box to display. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=>35 + }, + size=>{ + defaultValue=>30 + } + }); + 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("51","WebGUI"); +} + + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an input tag of type password. + +=cut + +sub toHtml { + my $self = shift; + return '{extras}.' />'; +} + + +1; + diff --git a/lib/WebGUI/Form/Phone.pm b/lib/WebGUI/Form/Phone.pm new file mode 100644 index 000000000..c8017a77b --- /dev/null +++ b/lib/WebGUI/Form/Phone.pm @@ -0,0 +1,87 @@ +package WebGUI::Form::Phone; + +=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::Phone + +=head1 DESCRIPTION + +Creates a telephone number 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 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("944","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a string filtered to allow only digits, spaces, and these special characters: + - ( ) or it will return undef it the number doesn't validate to those. + +=cut + +sub getValueFromPost { + my $self = shift; + my $value = $session{cgi}->param($self->{name}); + if ($value =~ /^[\d\s\-\+\(\)]+$/) { + return $value; + } + return undef; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a phone number 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; + diff --git a/lib/WebGUI/Form/Radio.pm b/lib/WebGUI/Form/Radio.pm new file mode 100644 index 000000000..8d128348e --- /dev/null +++ b/lib/WebGUI/Form/Radio.pm @@ -0,0 +1,111 @@ +package WebGUI::Form::Radio; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Radio + +=head1 DESCRIPTION + +Creates a radio button form 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 checked + +Defaults to "0". Set to "1" if this field should be checked. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + checked=>{ + defaultValue=> 0 + } + }); + return $class->SUPER::definition($definition); +} + + +#------------------------------------------------------------------- + +=head2 generateIdParameter ( ) + +A class method that returns a value to be used as the autogenerated ID for this field instance. Returns undef because this field type can have more than one with the same name, therefore autogenerated ID's aren't terribly useful. + +=cut + +sub generateIdParameter { + return undef +} + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("radio","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders and input tag of type radio. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value}))); + my $checkedText = ' checked="checked"' if ($self->{checked}); + my $idText = ' id="'.$self->{id}.'" ' if ($self->{id}); + return '{extras}.' />'; +} + + +1; + diff --git a/lib/WebGUI/Form/RadioList.pm b/lib/WebGUI/Form/RadioList.pm new file mode 100644 index 000000000..7b2e813f2 --- /dev/null +++ b/lib/WebGUI/Form/RadioList.pm @@ -0,0 +1,122 @@ +package WebGUI::Form::RadioList; + +=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::Radio; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::RadioList + +=head1 DESCRIPTION + +Creates a series of radio button form fields. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Control. Also take a look ath WebGUI::Form::checkbox as this class creates a list of checkboxes. + +=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 options + +A hash reference containing key values that will be returned with the form post and displayable text pairs. Defaults to an empty hash reference. + +=head4 vertical + +Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + options=>{ + defaultValue=>{} + }, + vertical=>{ + defaultValue=>0 + } + }); + 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("942","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a series of radio buttons. + +=cut + +sub toHtml { + my $self = shift; + my $output; + foreach my $key (keys %{$self->{options}}) { + my $checked = 0; + if ($self->{value} eq $key) { + $checked = 1; + } + $output .= WebGUI::Form::Radio->new({ + name=>$self->{name}, + value=>$key, + extras=>$self->{extras}, + checked=>$checked + })->toHtml; + $output .= ${$self->{options}}{$key}; + if ($self->{vertical}) { + $output .= "
\n"; + } else { + $output .= "    \n"; + } + } + return $output; +} + +1; + diff --git a/lib/WebGUI/Form/ReadOnly.pm b/lib/WebGUI/Form/ReadOnly.pm new file mode 100644 index 000000000..8876eb951 --- /dev/null +++ b/lib/WebGUI/Form/ReadOnly.pm @@ -0,0 +1,95 @@ +package WebGUI::Form::ReadOnly; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::ReadOnly + +=head1 DESCRIPTION + +Prints out the value directly with no form control. + +=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 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("read only","WebGUI"); +} + + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns undef. + +=cut + +sub getValueFromPost { + return undef; +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders the value. + +=cut + +sub toHtml { + my $self = shift; + return $self->{value}; +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Outputs nothing. + +=cut + +sub toHtmlAsHidden { + return undef; +} + + +1; + diff --git a/lib/WebGUI/Form/SelectList.pm b/lib/WebGUI/Form/SelectList.pm new file mode 100644 index 000000000..c18dd8a4a --- /dev/null +++ b/lib/WebGUI/Form/SelectList.pm @@ -0,0 +1,177 @@ +package WebGUI::Form::SelectList; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::selectList + +=head1 DESCRIPTION + +Creates a select list, aka dropdown list form control. + +=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 options + +A hash reference containing key values that will be returned with the form post and displayable text pairs. Defaults to an empty hash reference. + +=head4 defaultValue + +An array reference of the items to be checked if no value is specified. Defaults to an empty array reference. + +=head4 size + +The number of characters tall this list should be. Defaults to '1'. + +=head4 multiple + +Boolean indicating whether the user can select multiple items from this list like a checkList. Defaults to "0". + +=head4 sortByValue + +A boolean value for whether or not the values in the options hash should be sorted. Defaults to "0". + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + options=>{ + defaultValue=>{} + }, + defaultValue=>{ + defaultValue=>[], + }, + multiple=>{ + defaultValue=>0 + }, + sortByValue=>{ + defaultValue=>0 + }, + size=>{ + 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("484","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. + +=cut + +sub getValueFromPost { + my $self = shift; + my @data = $session{cgi}->param($self->{name}); + return wantarray ? @data : join("\n",@data); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a select list form control. + +=cut + +sub toHtml { + my $self = shift; + my $multiple = ' multiple="1"' if ($self->{multiple}); + my $output = ''."\n"; + return $output; +} + +#------------------------------------------------------------------- + +=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=>$self->{options} + )->toHtmlAsHidden; +} + +1; + diff --git a/lib/WebGUI/Form/Submit.pm b/lib/WebGUI/Form/Submit.pm new file mode 100644 index 000000000..8dce0f321 --- /dev/null +++ b/lib/WebGUI/Form/Submit.pm @@ -0,0 +1,69 @@ +package WebGUI::Form::Submit; + +=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::Button'; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Submit + +=head1 DESCRIPTION + +Creates a submit form button. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Button. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("submit","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a button. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixQuotes($self->{value}); + $self->{extras} ||= 'onclick="this.value=\''.WebGUI::International::get(452).'\'"'; + return '{extras}.' />'; +} + +1; + diff --git a/lib/WebGUI/Form/Template.pm b/lib/WebGUI/Form/Template.pm new file mode 100644 index 000000000..0fd5f0066 --- /dev/null +++ b/lib/WebGUI/Form/Template.pm @@ -0,0 +1,150 @@ +package WebGUI::Form::Template; + +=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::Asset::Template; +use WebGUI::Form::SelectList; +use WebGUI::Icon; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::URL; + +=head1 NAME + +Package WebGUI::Form::Template + +=head1 DESCRIPTION + +Creates a template chooser control. + +=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 name + +The identifier for this field. Defaults to "templateId". + +=head4 namespace + +The namespace for the list of templates to return. If this is omitted, all templates will be displayed. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=>"templateId" + }, + namespace=>{ + defaultValue=>undef + }, + }); + 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("template","Asset_Template"); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a database connection picker control. + +=cut + +sub toHtml { + my $self = shift; + my $templateList = WebGUI::Asset::Template->getList($self->{namespace}); + #Remove entries from template list that the user does not have permission to view. + for my $assetId ( keys %{$templateList} ) { + my $asset = WebGUI::Asset::Template->new($assetId); + if (!$asset->canView($session{user}{userId})) { + delete $templateList->{$assetId}; + } + } + my $selectList = WebGUI::Form::SelectList->new( + id=>$self->{id}, + name=>$self->{name}, + options=>$templateList, + value=>[$self->{value}], + extras=>$self->{extras} + ); + return $selectList->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 { + my $self = shift; + my $template = WebGUI::Asset::Template->new($self->{value}); + if (defined $template && $template->canEdit) { + my $returnUrl; + if (exists $session{asset}) { + $returnUrl = "&proceed=goBackToPage&returnUrl=".WebGUI::URL::escape($session{asset}->getUrl); + } + my $buttons = editIcon("func=edit".$returnUrl,$template->get("url")); + $buttons .= manageIcon("func=manageAssets",$template->getParent->get("url")); + $self->{subtext} = $buttons . $self->{subtext}; + } + return $self->SUPER::toHtmlWithWrapper; +} + + +1; + diff --git a/lib/WebGUI/Form/Text.pm b/lib/WebGUI/Form/Text.pm new file mode 100644 index 000000000..5a42198b3 --- /dev/null +++ b/lib/WebGUI/Form/Text.pm @@ -0,0 +1,104 @@ +package WebGUI::Form::Text; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Text + +=head1 DESCRIPTION + +Creates a text input box form 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 maxlength + +Defaults to 255. Determines the maximum number of characters allowed in this field. + +=head4 size + +Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=> 255 + }, + size=>{ + defaultValue=>$session{setting}{textBoxSize} || 30 + } + }); + 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("475","WebGUI"); +} + + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an input tag of type text. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value}))); + return '{extras}.' />'; +} + +1; + diff --git a/lib/WebGUI/Form/Textarea.pm b/lib/WebGUI/Form/Textarea.pm new file mode 100644 index 000000000..42d9f8c44 --- /dev/null +++ b/lib/WebGUI/Form/Textarea.pm @@ -0,0 +1,115 @@ +package WebGUI::Form::Textarea; + +=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::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Textarea + +=head1 DESCRIPTION + +Creates a text area form 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 rows + +The number of rows (in characters) tall the box should be. Defaults to the setting textAreaRows or 5 if that's not specified. + +=head4 columns + +The number of columns (in characters) wide the box should be. Defaults to the setting textAreaCols or 50 if that's not specified. + +=head4 wrap + +The style of wrapping this form should use. Defaults to "virtual". Other possible values are "off" and "physical". + +=head + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + rows=>{ + defaultValue=> $session{setting}{textAreaRows} || 5 + }, + columns=>{ + defaultValue=> $session{setting}{textAreaCols} || 50 + }, + wrap=>{ + defaultValue=>"virtual" + } + }); + 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("476","WebGUI"); +} + + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an input tag of type text. + +=cut + +sub toHtml { + my $self = shift; + my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->{value}))); + return ''; +} + + +1; + diff --git a/lib/WebGUI/Form/TimeField.pm b/lib/WebGUI/Form/TimeField.pm new file mode 100644 index 000000000..72b7be69a --- /dev/null +++ b/lib/WebGUI/Form/TimeField.pm @@ -0,0 +1,146 @@ +package WebGUI::Form::TimeField; + +=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::DateTime; +use WebGUI::Form::Button; +use WebGUI::Form::Hidden; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::TimeField + +=head1 DESCRIPTION + +Creates a time form 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 8. Determines the maximum number of characters allowed in this field. + +=head4 size + +Default to 8. Determines how many characters wide the field wlll be. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=>8 + }, + size=>{ + defaultValue=>8 + } + }); + 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("971","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the number of seconds since 00:00:00 on a 24 hour clock. Note, this will adjust for the user's time offset in the reverse manner that the form field adjusts for it in order to make the times come out appropriately. + +=cut + +sub getValueFromPost { + my $self = shift; + return WebGUI::DateTime::timeToSeconds($session{cgi}->param($self->{name}))-($session{user}{timeOffset}*3600); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a time field. + +=cut + +sub toHtml { + my $self = shift; + my $value = WebGUI::DateTime::secondsToTime($self->{value}); + WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' }); + $self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789:\')"'; + return $self->SUPER::toHtml + .WebGUI::Form::Button->new( + id=>$self->{id}, + extras=>'style="font-size: 8pt;" onClick="window.timeField = this.form.'.$self->{name}.';clockSet = window.open(\''.$session{config}{extrasURL}. '/timeChooser.html\',\'timeChooser\',\'WIDTH=230,HEIGHT=100\');return false"', + value=>WebGUI::International::get(970) + )->toHtml; +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Renders the field as a hidden field. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + return WebGUI::Form::Hidden->new( + name=>$self->{name}, + value=>secondsToTime($self->{value}) + )->toHtmlAsHidden; +} + + + + +1; + diff --git a/lib/WebGUI/Form/Url.pm b/lib/WebGUI/Form/Url.pm new file mode 100644 index 000000000..5478a3db9 --- /dev/null +++ b/lib/WebGUI/Form/Url.pm @@ -0,0 +1,119 @@ +package WebGUI::Form::Url; + +=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::Url + +=head1 DESCRIPTION + +Creates a URL form 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 2048. Determines the maximum number of characters allowed in this field. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=> 2048 + } + }); + 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("478","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Parses the posted value and tries to make corrections if necessary. + +=cut + +sub getValueFromPost { + my $self = shift; + my $value = $session{cgi}->param($self->{name}); + if ($value =~ /mailto:/) { + return $value; + } elsif ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) { + return "mailto:".$value; + } elsif ($value =~ /^\// || $value =~ /:\/\// || $value =~ /^\^/) { + return $value; + } + return "http://".$value; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a URL field. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/addHTTP.js',{ type=>'text/javascript' }); + $self->{extras} .= ' onBlur="addHTTP(this.form.'.$self->{name}.')"'; + return $self->SUPER::toHtml; +} + +1; + diff --git a/lib/WebGUI/Form/WhatNext.pm b/lib/WebGUI/Form/WhatNext.pm new file mode 100644 index 000000000..a91743ad7 --- /dev/null +++ b/lib/WebGUI/Form/WhatNext.pm @@ -0,0 +1,124 @@ +package WebGUI::Form::WhatNext; + +=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::SelectList; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::WhatNext + +=head1 DESCRIPTION + +Creates a what next question field. This is used to allow users direct the flow of forms from one page to another. + +=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 name + +The identifier for this field. Defaults to "proceed". + +=head4 defaultValue + +A database link id. Defaults to "0", which is the WebGUI database. + +=head4 afterEdit + +A URL that will be acted upon after editing a database link. + +=head4 hoverHelp + +A tooltip to tell the user what to do with the field. Defaults a standard piece of help for Database Links. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + label=>{ + defaultValue=>$class->getName() + }, + name=>{ + defaultValue=>"proceed" + }, + options=>{ + 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("744","WebGUI"); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a question selector asking the user where they want to go. + +=cut + +sub toHtml { + my $self = shift; + return WebGUI::Form::SelectList->new( + id=>$self->{id}, + name=>$self->{name}, + options=>$self->{options}, + value=>[$self->{value}], + extras=>$self->{extras} + )->toHtml; +} + + + +1; + diff --git a/lib/WebGUI/Form/YesNo.pm b/lib/WebGUI/Form/YesNo.pm new file mode 100644 index 000000000..34cfd48ef --- /dev/null +++ b/lib/WebGUI/Form/YesNo.pm @@ -0,0 +1,134 @@ +package WebGUI::Form::YesNo; + +=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::Radio; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::yesNo + +=head1 DESCRIPTION + +Creates a yes/no question 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 defaultValue + +Can be a 1 or 0. Defaults to 0 if no value is specified. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + defaultValue=>{ + defaultValue=>0 + } + }); + 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("482","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns either a 1 or 0 representing yes, no. + +=cut + +sub yesNo { + my $self = shift; + if ($session{cgi}->param($self->{name}) > 0) { + return 1; + } + return 0; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a yes/no question field. + +=cut + +sub toHtml { + my $self = shift; + my ($checkYes, $checkNo); + if ($self->{value}) { + $checkYes = 1; + } else { + $checkNo = 1; + } + my $output = WebGUI::Form::Radio->new( + checked=>$checkYes, + name=>$self->{name}, + value=>1, + extras=>$self->{extras} + )->toHtml; + $output .= WebGUI::International::get(138); + $output .= '   '; + $output .= WebGUI::Form::Radio->new( + checked=>$checkNo, + name=>$self->{name}, + value=>0, + extras=>$self->{extras} + )->toHtml; + $output .= WebGUI::International::get(139); + return $output; +} + + +1; + diff --git a/lib/WebGUI/Form/Zipcode.pm b/lib/WebGUI/Form/Zipcode.pm new file mode 100644 index 000000000..3bbad7134 --- /dev/null +++ b/lib/WebGUI/Form/Zipcode.pm @@ -0,0 +1,115 @@ +package WebGUI::Form::Zipcode; + +=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::Zipcode + +=head1 DESCRIPTION + +Creates a zip code form 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 10. Determines the maximum number of characters allowed in this field. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=> 10 + } + }); + 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("944","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns a validated form post result. If the result does not pass validation, it returns undef instead. + +=cut + +sub getValueFromPost { + my $self = shift; + my $value = $session{cgi}->param($self->{name}); + if ($value =~ /^[A-Z\d\s\-]+$/) { + return $value; + } + return undef; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a zip code 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}.',\'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- \')"'; + return $self->SUPER::toHtml; +} + +1; + diff --git a/lib/WebGUI/FormProcessor.pm b/lib/WebGUI/FormProcessor.pm index 875fd5d68..c55b52615 100644 --- a/lib/WebGUI/FormProcessor.pm +++ b/lib/WebGUI/FormProcessor.pm @@ -55,7 +55,7 @@ Dynamically creates functions on the fly for all the different form control type sub AUTOLOAD { our $AUTOLOAD; - my $name = (split /::/, $AUTOLOAD)[-1]; + my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); my $fieldName = shift; my $cmd = "use WebGUI::Form::".$name; eval ($cmd); @@ -93,16 +93,15 @@ sub process { my ($name, $type, $default) = @_; my $value; - $type = "text" if ($type eq ""); + $type = ucfirst($type); + $type = "Text" if ($type eq ""); $value = &$type($name); - unless (defined $value) { return $default; } if ($value =~ /^[\s]+$/) { return undef; } - return $value; } diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 4bdf233ac..f39884498 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -119,7 +119,7 @@ Dynamically creates functions on the fly for all the different form control type sub AUTOLOAD { our $AUTOLOAD; my $self = shift; - my $name = (split /::/, $AUTOLOAD)[-1]; + my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); my %params = @_; $params{uiLevelOverride} ||= $self->{_uiLevelOverride}; my $cmd = "use WebGUI::Form::".$name; @@ -167,7 +167,7 @@ The field options. See the documentation for the desired field for more informat sub dynamicField { my $self = shift; - my $fieldType = shift; + my $fieldType = ucfirst(shift); my %param = @_; foreach my $key (keys %param) { # strip off the leading minus sign in each parameter key. $key=~/^-(.*)$/; @@ -180,7 +180,7 @@ sub dynamicField { $output .= _subtext($param{subtext}); $output = $self->_tableFormRow($param{label},$output,$param{hoverHelp}); } else { - $output = WebGUI::Form::hidden({ + $output = WebGUI::Form::Hidden({ "name"=>$param{name}, "value"=>$param{value}, "defaultValue"=>$param{defaultValue} diff --git a/lib/WebGUI/TabForm.pm b/lib/WebGUI/TabForm.pm index 6214e9cd5..ee5b00fdb 100644 --- a/lib/WebGUI/TabForm.pm +++ b/lib/WebGUI/TabForm.pm @@ -152,7 +152,7 @@ B This uses the same syntax of the WebGUI::Form::hidden() method. sub hidden { my $self = shift; my $params = shift; - $self->{_hidden} .= WebGUI::Form::hidden($params); + $self->{_hidden} .= WebGUI::Form::Hidden($params); } @@ -263,7 +263,7 @@ B This uses the same syntax of the WebGUI::Form::submit() method. sub submit { my $self = shift; my $submit = shift; - $self->{_submit} = WebGUI::Form::submit($submit); + $self->{_submit} = WebGUI::Form::Submit($submit); }