made it so it's possible to use file form elements without any auxillary code

fixed a bug in Post
storage copy can accept an optional new storage location to copy to
articles can now accept direct attachments
This commit is contained in:
JT Smith 2006-04-16 17:30:01 +00:00
parent c523f9c09d
commit 4adfc0737c
13 changed files with 131 additions and 35 deletions

View file

@ -1536,10 +1536,14 @@ sub processPropertiesFromFormPost {
$data{$property} = $definition->{properties}{$property}{defaultValue} if $self->session->form->process("assetId") eq "new";
next;
}
my %params = %{$definition->{properties}{$property}};
$params{name} = $property;
$params{value} = $self->get($property);
$data{$property} = $self->session->form->process(
$property,
$definition->{properties}{$property}{fieldType},
$definition->{properties}{$property}{defaultValue}
$definition->{properties}{$property}{defaultValue},
\%params
);
}
}

View file

@ -700,7 +700,7 @@ sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Post where assetId=".$self->session->db->quote($self->getId));
while (my ($storageId) = $sth->array) {
my $storage = WebGUI::Storage->get($storageId);
my $storage = WebGUI::Storage->get($self->session, $storageId);
$storage->delete if defined $storage;
}
$sth->finish;

View file

@ -66,6 +66,24 @@ text will come out formatted as paragraphs.
=cut
#-------------------------------------------------------------------
=head2 addRevision
Override the default method in order to deal with attachments.
=cut
sub addRevision {
my $self = shift;
my $newSelf = $self->SUPER::addRevision(@_);
if ($self->get("storageId")) {
my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy;
$newSelf->update({storageId=>$newStorage->getId});
}
return $newSelf;
}
#-------------------------------------------------------------------
sub definition {
my $class = shift;
@ -163,6 +181,39 @@ sub exportAssetData {
}
#-------------------------------------------------------------------
sub getStorageLocation {
my $self = shift;
unless (exists $self->{_storageLocation}) {
if ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
} else {
$self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
}
}
return $self->{_storageLocation};
}
#-------------------------------------------------------------------
=head2 indexContent ( )
Indexing the content of attachments and user defined fields. See WebGUI::Asset::indexContent() for additonal details.
=cut
sub indexContent {
my $self = shift;
my $indexer = $self->SUPER::indexContent;
$indexer->addKeywords($self->get("linkTitle"));
$indexer->addKeywords($self->get("linkUrl"));
my $storage = $self->getStorageLocation;
foreach my $file (@{$storage->getFiles}) {
$indexer->addFile($storage->getPath($file));
}
}
#-------------------------------------------------------------------
=head2 prepareView ( )
@ -184,6 +235,19 @@ sub prepareView {
}
#-------------------------------------------------------------------
sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Articlewhere assetId=?",[$self->getId]);
while (my ($storageId) = $sth->array) {
my $storage = WebGUI::Storage::Image->get($self->session,$storageId);
$storage->delete if defined $storage;
}
$sth->finish;
return $self->SUPER::purge;
}
#-------------------------------------------------------------------
=head2 purgeCache ()
@ -200,6 +264,14 @@ sub purgeCache {
#-------------------------------------------------------------------
sub purgeRevision {
my $self = shift;
$self->getStorageLocation->delete;
return $self->SUPER::purgeRevision;
}
#-------------------------------------------------------------------
=head2 view ( )
view defines all template variables, processes the template and
@ -215,7 +287,7 @@ sub view {
}
my %var;
if ($self->get("storageId")) {
my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
my $storage = $self->getStorageLocation;
foreach my $file (@{$storage->getFiles}) {
if ($storage->isImage($file)) {
$var{'image.url'} = $storage->getUrl($file);
@ -292,7 +364,7 @@ sub www_deleteFile {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
if ($self->get("storageId") ne "") {
my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
my $storage = $self->getStorageLocation;
$storage->deleteFile($self->session->form->param("filename"));
}
return $self->www_edit;

View file

@ -156,7 +156,12 @@ sub getValueFromPost {
} elsif ($self->session->form->param($self->privateName('action')) eq 'keep') {
return $value;
} elsif ($self->session->form->param($self->privateName('action')) eq 'upload') {
my $storage = WebGUI::Storage::Image->create($self->session);
my $storage = undef;
if ($self->get("value") ne "") {
$storage = WebGUI::Storage::Image->get($self->session, $self->get("value"));
} else {
$storage = WebGUI::Storage::Image->create($self->session);
}
$storage->addFileFromFormPost($self->get("name"),1000);
my @files = @{ $storage->getFiles };
if (scalar(@files) < 1) {

View file

@ -58,7 +58,7 @@ sub AUTOLOAD {
our $AUTOLOAD;
my $self = shift;
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
my $fieldName = shift;
my $params = shift;
my $cmd = "use WebGUI::Form::".$name;
eval ($cmd);
if ($@) {
@ -66,7 +66,7 @@ sub AUTOLOAD {
return undef;
}
my $class = "WebGUI::Form::".$name;
return $class->new($self->session, {name=>$fieldName})->getValueFromPost;
return $class->new($self->session, $params)->getValueFromPost;
}
#-------------------------------------------------------------------
@ -181,7 +181,7 @@ sub paramsHashRef {
#-------------------------------------------------------------------
=head2 process ( name, type [ , default ] )
=head2 process ( name, type [ , default, params ] )
Returns whatever would be the expected result of the method type that was specified. This method also checks to make sure that the field is not returning a string filled with nothing but whitespace.
@ -197,21 +197,26 @@ The type of form element this variable came from. Defaults to "text" if not spec
The default value for this variable. If the variable is undefined then the default value will be returned instead.
=head3 params
A full set of form params just as you'd pass into any of the form controls when building it.
=cut
sub process {
my ($self, $name, $type, $default) = @_;
my ($self, $name, $type, $default, $params) = @_;
$type = ucfirst($type);
return $self->param($name) if ($type eq "");
$params->{name} = $name;
if (wantarray) {
my @values = $self->$type($name);
my @values = $self->$type($params);
if (scalar(@values) < 1 && ref $default eq "ARRAY") {
return @{$default};
} else {
return @values;
}
} else {
my $value = $self->$type($name);
my $value = $self->$type($params);
unless (defined $value) {
return $default;
}

View file

@ -289,15 +289,19 @@ sub addFileFromScalar {
#-------------------------------------------------------------------
=head2 copy ( )
=head2 copy ( [ storage ] )
Copies a storage location and it's contents. Returns a new storage location object. Note that this does not copy privileges or other special filesystem properties.
=head3 storage
Optionally pass in a storage object to copy the data to.
=cut
sub copy {
my $self = shift;
my $newStorage = WebGUI::Storage->create($self->session);
my $newStorage = shift || WebGUI::Storage->create($self->session);
my $filelist = $self->getFiles(1);
foreach my $file (@{$filelist}) {
my $source = FileHandle->new($self->getPath($file),"r");