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:
parent
c523f9c09d
commit
4adfc0737c
13 changed files with 131 additions and 35 deletions
|
|
@ -27,8 +27,7 @@
|
|||
<a href="<tmpl_var linkUrl>"><tmpl_var linkTitle></a>
|
||||
</tmpl_if>
|
||||
</tmpl_if>
|
||||
<tmpl_var attachment.icon> <tmpl_var attachment.name> <tmpl_var attachment.name>
|
||||
<p />
|
||||
<tmpl_if attachment.name><p><p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /> <tmpl_var attachment.name></a></p></p></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if pagination.pageCount.isMultiple>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
<a href="<tmpl_var linkUrl>"><tmpl_var linkTitle></a>
|
||||
</tmpl_if>
|
||||
</tmpl_if>
|
||||
<tmpl_var attachment.icon> <tmpl_var attachment.name> <tmpl_var attachment.name>
|
||||
<tmpl_if attachment.name><p><p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /> <tmpl_var attachment.name></a></p></p></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if pagination.pageCount.isMultiple>
|
||||
|
|
|
|||
|
|
@ -6,18 +6,12 @@
|
|||
</tmpl_if>
|
||||
|
||||
<tmpl_if displaytitle>
|
||||
<tmpl_if linkurl>
|
||||
<a href="<tmpl_var linkurl>">
|
||||
</tmpl_if>
|
||||
<span class="itemTitle"><tmpl_var title></span>
|
||||
<tmpl_if linkurl>
|
||||
</a>
|
||||
</tmpl_if>
|
||||
<tmpl_if linkurl><a href="<tmpl_var linkurl>"></tmpl_if><span class="itemTitle"><tmpl_var title></span><tmpl_if linkurl></a></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if attachment.name>
|
||||
<tmpl_if displaytitle> - </tmpl_if>
|
||||
<a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.Icon>" alt="<tmpl_var attachment.name>" width="16" height="16" border="0" align="middle" /></a>
|
||||
<p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /></a></p>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if description>
|
||||
|
|
|
|||
|
|
@ -6,18 +6,12 @@
|
|||
</tmpl_if>
|
||||
|
||||
<tmpl_if displaytitle>
|
||||
<tmpl_if linkurl>
|
||||
<a href="<tmpl_var linkurl>" target="_blank">
|
||||
</tmpl_if>
|
||||
<span class="itemTitle"><tmpl_var title></span>
|
||||
<tmpl_if linkurl>
|
||||
</a>
|
||||
</tmpl_if>
|
||||
<tmpl_if linkurl><a href="#" onclick="window.open('<tmpl_var linkurl>');"></tmpl_if><span class="itemTitle"><tmpl_var title></span><tmpl_if linkurl></a></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if attachment.name>
|
||||
<tmpl_if displaytitle> - </tmpl_if>
|
||||
<a href="<tmpl_var attachment.url>" target="_blank"><img src="<tmpl_var attachment.Icon>" alt="<tmpl_var attachment.name>" width="16" height="16" border="0" align="middle" /></a>
|
||||
<p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /></a></p>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if description>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
</tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_var attachment.icon> <tmpl_var attachment.name> <tmpl_var attachment.name> <p />
|
||||
<tmpl_if attachment.name><p><p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /> <tmpl_var attachment.name></a></p></p></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if pagination.isFirstPage>
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@
|
|||
</tmpl_if>
|
||||
|
||||
<tmpl_if pagination.isLastPage>
|
||||
<tmpl_var attachment.icon> <tmpl_var attachment.name> <tmpl_var attachment.name>
|
||||
<p />
|
||||
<tmpl_if attachment.name><p><p style="display:inline;vertical-align:middle;"><a href="<tmpl_var attachment.url>"><img src="<tmpl_var attachment.icon>" style="vertical-align:middle;border: 0px;" alt="<tmpl_var attachment.name>" /> <tmpl_var attachment.name></a></p></p></tmpl_if>
|
||||
</tmpl_if>
|
||||
|
||||
<tmpl_if pagination.isFirstPage>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use File::Path;
|
|||
use WebGUI::Workflow;
|
||||
use WebGUI::Workflow::Cron;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Storage;
|
||||
|
||||
my $toVersion = "6.99.0"; # make this match what version you're going to
|
||||
my $quiet; # this line required
|
||||
|
|
@ -54,6 +55,25 @@ finish($session); # this line required
|
|||
sub updateArticle {
|
||||
print "\tAllowing articles to have direct attachments.\n";
|
||||
$session->db->write("alter table Article add column storageId varchar(22) binary");
|
||||
my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Article'");
|
||||
while (my ($id) = $rs->array) {
|
||||
my $asset = WebGUI::Asset->new($id, "WebGUI::Asset::Wobject::Article");
|
||||
if (defined $asset) {
|
||||
my $children = $asset->getLineage(["children"],{returnObjects=>1, includeOnlyClasses=>["WebGUI::Asset::File","WebGUI::Asset::File::Image"]});
|
||||
if (scalar(@{$children})) {
|
||||
my $storage = undef;
|
||||
if ($asset->get("storageId")) {
|
||||
$storage = WebGUI::Storage->get($session,$asset->get("storageId"));
|
||||
} else {
|
||||
$storage = WebGUI::Storage->create($session);
|
||||
$asset->update({storageId=>$storage->getId});
|
||||
}
|
||||
foreach my $child (@{$children}) {
|
||||
$child->getStorageLocation->copy($storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue