Cleaned the pollution from the forms system.

This commit is contained in:
JT Smith 2008-04-16 16:11:10 +00:00
parent 53b81b36d0
commit 8500c4d506
81 changed files with 2675 additions and 1570 deletions

View file

@ -53,10 +53,6 @@ The following additional parameters have been added via this sub class.
If no name is specified a default name of "file" will be used.
=head4 profileEnabled
Flag that tells the User Profile system that this is a valid form element in a User Profile
=head4 forceImageOnly
When set, form control will not allow file uploads unless the file has recognized image file extension
@ -67,77 +63,21 @@ sub definition {
my $class = shift;
my $session = shift;
my $definition = shift || [];
my $i18n = WebGUI::International->new($session);
push(@{$definition}, {
formName=>{
defaultValue=>$i18n->get("image")
},
name=>{
defaultValue=>"image"
},
profileEnabled=>{
defaultValue=>1
},
forceImageOnly=>{
defaultValue=>0
},
enforceSizeLimits => {
defaultValue => 1
},
dbDataType => {
defaultValue => "VARCHAR(22) BINARY",
},
});
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
=head2 displayForm ( )
If an image is uploaded, then return the image and a control to
delete it. Otherwise, display a form element to upload a file.
=cut
sub displayForm {
my ($self) = @_;
return $self->toHtml unless $self->get('value');
##There are files inside here, for each one, display the image
##and another form control for deleting it.
my $location = WebGUI::Storage::Image->get($self->session, $self->get('value'));
my $i18n = WebGUI::International->new($self->session);
my $fileForm = '';
my $file = shift @{ $location->getFiles };
$fileForm .= sprintf qq!<img src="%s" /><br />!, $location->getUrl($file);
$fileForm .= $i18n->get(392)
. "&nbsp"x4
. WebGUI::Form::YesNo->new($self->session, {-name=>$self->privateName('delete'), -value=>0})->toHtml;
$fileForm .= $self->toHtmlAsHidden();
$fileForm .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml();
return $fileForm;
}
#-------------------------------------------------------------------
=head2 displayValue ( )
This utility method is used to format values for the Profile system. It
displays each image in the storage location that is the value of the
profile field.
=cut
sub displayValue {
my ($self) = @_;
return '' unless $self->get("value");
my $location = WebGUI::Storage::Image->get($self->session,$self->get("value"));
my $file = shift @{ $location->getFiles };
my $fileValue = sprintf qq|<img src="%s" />&nbsp;%s|, $location->getUrl($file), $file;
return $fileValue;
}
#-------------------------------------------------------------------
=head2 getFilePreview ( storage )
@ -154,6 +94,7 @@ sub getFilePreview {
my $self = shift;
my $storage = shift;
my $preview = "";
my $i18n = WebGUI::International->new($self->session);
foreach my $file (@{$storage->getFiles}) {
if ($self->get("deleteFileUrl")) {
$preview .= '<p style="display:inline;vertical-align:middle;"><a href="'.$self->get("deleteFileUrl").$file.'">'
@ -163,12 +104,26 @@ sub getFilePreview {
$preview .= '<p style="display:inline;vertical-align:middle;"><a href="'.$storage->getUrl($file).'">'
.'<img src="'.$image.'" style="vertical-align:middle;border: 0px;" alt="'
.$file.'" /> '.$file.'</a></p><br />';
$preview .= $i18n->get(392) . "&nbsp"x4 . WebGUI::Form::YesNo->new($self->session, {-name=>$self->privateName('delete'), -value=>0})->toHtml;
}
return $preview;
}
#-------------------------------------------------------------------
=head2 getName ( session )
Returns the human readable name of this control.
=cut
sub getName {
my ($self, $session) = @_;
return WebGUI::International->new($session, 'WebGUI')->get('image');
}
#-------------------------------------------------------------------
=head2 getStorageLocation ( )
Returns the WebGUI::Storage object for this control.
@ -177,22 +132,23 @@ Returns the WebGUI::Storage object for this control.
sub getStorageLocation {
my $self = shift;
my $storage = WebGUI::Storage::Image->get($self->session, $self->get("value")) if ($self->get("value"));
my $value = $self->getDefaultValue;
my $storage = WebGUI::Storage::Image->get($self->session, $value) if ($value);
return $storage;
}
#-------------------------------------------------------------------
=head2 getValueFromPost ( )
=head2 getValue ( )
See WebGUI::Form::File::getValueFromPost() for details. Generates a thumbnail.
See WebGUI::Form::File::getValue() for details. Generates a thumbnail.
=cut
sub getValueFromPost {
sub getValue {
my $self = shift;
my $id = $self->SUPER::getValueFromPost(@_);
my $id = $self->SUPER::getValue(@_);
if (defined $id) {
my $storage = WebGUI::Storage::Image->get($self->session, $id);
if (defined $storage) {
@ -215,5 +171,35 @@ sub getValueFromPost {
return $id;
}
#-------------------------------------------------------------------
=head2 getValueAsHtml ( )
Displays the image using an img tag.
=cut
sub getValueAsHtml {
my ($self) = @_;
my $value = $self->getValue;
return '' unless $value;
my $location = WebGUI::Storage::Image->get($self->session, $value);
my $file = shift @{ $location->getFiles };
my $fileValue = sprintf qq|<img src="%s" />&nbsp;%s|, $location->getUrl($file), $file;
return $fileValue;
}
#-------------------------------------------------------------------
=head2 isDynamicCompatible ( )
A class method that returns a boolean indicating whether this control is compatible with the DynamicField control.
=cut
sub isDynamicCompatible {
return 1;
}
1;