Conflicts: docs/gotcha.txt docs/previousVersion.sql docs/templates.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/Event.pm lib/WebGUI/Asset/File.pm lib/WebGUI/Asset/MapPoint.pm lib/WebGUI/Asset/RichEdit.pm lib/WebGUI/Asset/Sku/Product.pm lib/WebGUI/Asset/Snippet.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Template/TemplateToolkit.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/Carousel.pm lib/WebGUI/Asset/Wobject/Collaboration.pm lib/WebGUI/Asset/Wobject/Dashboard.pm lib/WebGUI/Asset/Wobject/DataForm.pm lib/WebGUI/Asset/Wobject/Folder.pm lib/WebGUI/Asset/Wobject/Map.pm lib/WebGUI/Asset/Wobject/Search.pm lib/WebGUI/Asset/Wobject/Shelf.pm lib/WebGUI/Asset/Wobject/StockData.pm lib/WebGUI/Asset/Wobject/StoryTopic.pm lib/WebGUI/Asset/Wobject/SyndicatedContent.pm lib/WebGUI/Asset/Wobject/Thingy.pm lib/WebGUI/Asset/Wobject/WeatherData.pm lib/WebGUI/AssetClipboard.pm lib/WebGUI/AssetCollateral/DataForm/Entry.pm lib/WebGUI/AssetExportHtml.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetMetaData.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/AssetVersioning.pm lib/WebGUI/Auth.pm lib/WebGUI/Cache/CHI.pm lib/WebGUI/Content/AssetManager.pm lib/WebGUI/Fork/ProgressBar.pm lib/WebGUI/Form/JsonTable.pm lib/WebGUI/Form/TimeField.pm lib/WebGUI/Form/Zipcode.pm lib/WebGUI/Group.pm lib/WebGUI/International.pm lib/WebGUI/Macro/AssetProxy.pm lib/WebGUI/Macro/FileUrl.pm lib/WebGUI/Operation/SSO.pm lib/WebGUI/Operation/User.pm lib/WebGUI/Role/Asset/Subscribable.pm lib/WebGUI/Shop/Cart.pm lib/WebGUI/Shop/Transaction.pm lib/WebGUI/Shop/TransactionItem.pm lib/WebGUI/Test.pm lib/WebGUI/URL/Content.pm lib/WebGUI/URL/Uploads.pm lib/WebGUI/User.pm lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm lib/WebGUI/Workflow/Activity/SendNewsletters.pm lib/WebGUI/i18n/English/Asset.pm lib/WebGUI/i18n/English/WebGUI.pm sbin/installClass.pl sbin/rebuildLineage.pl sbin/search.pl sbin/testEnvironment.pl t/Asset/Asset.t t/Asset/AssetClipboard.t t/Asset/AssetLineage.t t/Asset/AssetMetaData.t t/Asset/Event.t t/Asset/File.t t/Asset/File/Image.t t/Asset/Post/notification.t t/Asset/Sku.t t/Asset/Story.t t/Asset/Template.t t/Asset/Wobject/Collaboration/templateVariables.t t/Asset/Wobject/Collaboration/unarchiveAll.t t/Asset/Wobject/Shelf.t t/Auth.t t/Macro/EditableToggle.t t/Macro/FilePump.t t/Shop/Cart.t t/Shop/Transaction.t t/Storage.t t/User.t t/Workflow.t
346 lines
10 KiB
Perl
346 lines
10 KiB
Perl
package WebGUI::Asset::Wobject::Folder;
|
|
|
|
=head1 LEGAL
|
|
|
|
-------------------------------------------------------------------
|
|
WebGUI is Copyright 2001-2009 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 Moose;
|
|
use WebGUI::Definition::Asset;
|
|
extends 'WebGUI::Asset::Wobject';
|
|
|
|
define assetName => ["assetName", 'Asset_Folder'];
|
|
define icon => 'folder.gif';
|
|
define tableName => 'Folder';
|
|
|
|
property visitorCacheTimeout => (
|
|
tab => "display",
|
|
fieldType => "interval",
|
|
default => 3600,
|
|
uiLevel => 8,
|
|
label => ["visitor cache timeout", 'Asset_Folder'],
|
|
hoverHelp => ["visitor cache timeout help", 'Asset_Folder'],
|
|
);
|
|
# TODO: This should probably be a proper "sortBy" with multiple possible fields
|
|
property sortAlphabetically => (
|
|
fieldType => "yesNo",
|
|
default => 0,
|
|
tab => 'display',
|
|
label => ['sort alphabetically', 'Asset_Folder'],
|
|
hoverHelp => ['sort alphabetically help', 'Asset_Folder'],
|
|
);
|
|
|
|
property sortOrder => (
|
|
tab => 'display',
|
|
fieldType => "selectBox",
|
|
options => \&_sortOrder_options,
|
|
default => "ASC",
|
|
label => [ "editForm sortOrder label" , 'Asset_Folder'],
|
|
hoverHelp => [ "editForm sortOrder description" , 'Asset_Folder'],
|
|
);
|
|
sub _sortOrder_options {
|
|
my $self = shift;
|
|
my $i18n = WebGUI::International->new($self->session, 'Asset_Folder');
|
|
my $optionsSortOrder = {
|
|
ASC => $i18n->get( "editForm sortOrder ascending" ),
|
|
DESC => $i18n->get( "editForm sortOrder descending" ),
|
|
};
|
|
return $optionsSortOrder;
|
|
}
|
|
|
|
property templateId => (
|
|
fieldType => "template",
|
|
default => 'PBtmpl0000000000000078',
|
|
namespace => 'Folder',
|
|
tab => 'display',
|
|
label => ['folder template title', 'Asset_Folder'],
|
|
hoverHelp => ['folder template description', 'Asset_Folder'],
|
|
);
|
|
has '+uiLevel' => (
|
|
default => 5,
|
|
);
|
|
|
|
use Number::Format ();
|
|
|
|
=head1 NAME
|
|
|
|
Package WebGUI::Asset::Wobject::Folder
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Display a list of assets and sub folders just like in an operating system filesystem.
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use WebGUI::Asset::Wobject::Folder;
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
These methods are available from this class:
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 getContentLastModified
|
|
|
|
Overridden to check the revision dates of children as well
|
|
|
|
=cut
|
|
|
|
sub getContentLastModified {
|
|
my $self = shift;
|
|
my $mtime = $self->get("lastModified");
|
|
my $childIter = $self->getLineageIterator(["children"]);
|
|
while ( 1 ) {
|
|
my $child;
|
|
eval { $child = $childIter->() };
|
|
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
|
|
$self->session->log->error($x->full_message);
|
|
next;
|
|
}
|
|
last unless $child;
|
|
my $child_mtime = $child->getContentLastModified;
|
|
$mtime = $child_mtime if ($child_mtime > $mtime);
|
|
}
|
|
return $mtime;
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 getContentLastModifiedBy
|
|
|
|
Overridden to check the updated dates of children as well
|
|
|
|
=cut
|
|
|
|
sub getContentLastModifiedBy {
|
|
my $self = shift;
|
|
my $mtime = $self->SUPER::getContentLastModified;
|
|
my $userId = $self->get('revisedBy');
|
|
my $childIter = $self->getLineageIterator(["children"]);
|
|
while ( 1 ) {
|
|
my $child;
|
|
eval { $child = $childIter->() };
|
|
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
|
|
$self->session->log->error($x->full_message);
|
|
next;
|
|
}
|
|
last unless $child;
|
|
my $child_mtime = $child->getContentLastModified;
|
|
if ($child_mtime > $mtime) {
|
|
$mtime = $child_mtime;
|
|
$userId = $child->get("revisedBy");
|
|
}
|
|
}
|
|
return $userId;
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 getEditForm ( )
|
|
|
|
Returns the TabForm object that will be used in generating the edit page for this asset.
|
|
|
|
=cut
|
|
|
|
sub getEditForm {
|
|
my $self = shift;
|
|
my $tabform = $self->SUPER::getEditForm();
|
|
my $i18n = WebGUI::International->new($self->session,"Asset_Folder");
|
|
if ($self->get("assetId") eq "new") {
|
|
$tabform->getTab("properties")->whatNext(
|
|
-options=>{
|
|
view=>$i18n->get(823),
|
|
"viewParent"=>$i18n->get(847)
|
|
},
|
|
-value=>"view"
|
|
);
|
|
}
|
|
return $tabform;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head2 getTemplateVars ( )
|
|
|
|
Get the shared template vars for all views of the Folder.
|
|
|
|
=cut
|
|
|
|
sub getTemplateVars {
|
|
my $self = shift;
|
|
my $vars = $self->get;
|
|
my $i18n = WebGUI::International->new($self->session, 'Asset_Folder');
|
|
|
|
$vars->{ 'addFile.label' } = $i18n->get('add file label');
|
|
$vars->{ 'addFile.url' } = $self->getUrl('func=add;className=WebGUI::Asset::FilePile');
|
|
$vars->{ canEdit } = $self->canEdit;
|
|
$vars->{ canAddFile } = $self->canEdit;
|
|
|
|
return $vars;
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 prepareView ( )
|
|
|
|
See WebGUI::Asset::prepareView() for details.
|
|
|
|
=cut
|
|
|
|
sub prepareView {
|
|
my $self = shift;
|
|
$self->SUPER::prepareView();
|
|
my $template = WebGUI::Asset::Template->newById($self->session, $self->templateId);
|
|
if (!$template) {
|
|
WebGUI::Error::ObjectNotFound::Template->throw(
|
|
error => qq{Template not found},
|
|
templateId => $self->templateId,
|
|
assetId => $self->getId,
|
|
);
|
|
}
|
|
$template->prepare($self->getMetaDataAsTemplateVariables);
|
|
$self->{_viewTemplate} = $template;
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 purgeCache ( )
|
|
|
|
See WebGUI::Asset::purgeCache() for details.
|
|
|
|
=cut
|
|
|
|
override purgeCache => sub {
|
|
my $self = shift;
|
|
$self->session->cache->remove("view_".$self->getId);
|
|
super();
|
|
};
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 view ( )
|
|
|
|
See WebGUI::Asset::view for details. Generate template variables and
|
|
render the template. Also handles caching.
|
|
|
|
=cut
|
|
|
|
sub view {
|
|
my $self = shift;
|
|
|
|
# Use cached version for visitors
|
|
my $cache = $self->session->cache;
|
|
if ($self->session->user->isVisitor) {
|
|
my $out = $cache->get("view_".$self->getId);
|
|
return $out if $out;
|
|
}
|
|
|
|
my $vars = $self->getTemplateVars;
|
|
# TODO: Getting the children template vars should be a seperate method.
|
|
|
|
my %rules = ( );
|
|
if ( $self->sortAlphabetically ) {
|
|
$rules{ orderByClause } = "assetData.title " . $self->get( "sortOrder" );
|
|
}
|
|
else {
|
|
$rules{ orderByClause } = "asset.lineage " . $self->sortOrder;
|
|
}
|
|
|
|
my $childIter = $self->getLineageIterator( ["children"], \%rules);
|
|
while ( 1 ) {
|
|
my $child;
|
|
eval { $child = $childIter->() };
|
|
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
|
|
$self->session->log->error($x->full_message);
|
|
next;
|
|
}
|
|
last unless $child;
|
|
# TODO: Instead of this it should be using $child->getTemplateVars || $child->get
|
|
if ( $child->isa("WebGUI::Asset::Wobject::Folder") ) {
|
|
push @{ $vars->{ "subfolder_loop" } }, {
|
|
id => $child->getId,
|
|
url => $child->getUrl,
|
|
title => $child->title,
|
|
menuTitle => $child->menuTitle,
|
|
synopsis => $child->synopsis || '',
|
|
canView => $child->canView(),
|
|
"icon.small" => $child->getIcon(1),
|
|
"icon.big" => $child->getIcon,
|
|
};
|
|
}
|
|
else {
|
|
my $childVars = {
|
|
id => $child->getId,
|
|
canView => $child->canView(),
|
|
title => $child->title,
|
|
menuTitle => $child->menuTitle,
|
|
synopsis => $child->synopsis || '',
|
|
size => Number::Format::format_bytes($child->assetSize),
|
|
"date.epoch" => $child->revisionDate,
|
|
"icon.small" => $child->getIcon(1),
|
|
"icon.big" => $child->getIcon,
|
|
type => $child->getName,
|
|
url => $child->getUrl,
|
|
canEdit => $child->canEdit,
|
|
controls => $child->getToolbar,
|
|
};
|
|
|
|
if ( $child->isa('WebGUI::Asset::File::Image') ) {
|
|
$childVars->{ "isImage" } = 1;
|
|
$childVars->{ "thumbnail.url" } = $child->getThumbnailUrl;
|
|
}
|
|
|
|
if ( $child->isa('WebGUI::Asset::File') ) {
|
|
$childVars->{ "isFile" } = 1;
|
|
$childVars->{ "file.url" } = $child->getFileUrl;
|
|
}
|
|
|
|
push @{ $vars->{ "file_loop" } }, $childVars;
|
|
}
|
|
}
|
|
|
|
my $out = $self->processTemplate( $vars, undef, $self->{_viewTemplate} );
|
|
|
|
# Update the cache
|
|
if ($self->session->user->isVisitor) {
|
|
$cache->set("view_".$self->getId, $out, $self->visitorCacheTimeout);
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 www_view ( )
|
|
|
|
See WebGUI::Asset::Wobject::www_view() for details.
|
|
|
|
=cut
|
|
|
|
override www_view => sub {
|
|
my $self = shift;
|
|
$self->session->http->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor);
|
|
super();
|
|
};
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable;
|
|
1;
|
|
|