Add POD missing from File and Image. Remove duplicate code in Image that

can be inherited from File.
This commit is contained in:
Colin Kuskie 2009-07-05 00:31:20 +00:00
parent 05cf48fb18
commit 27931774e8
2 changed files with 178 additions and 46 deletions

View file

@ -135,6 +135,12 @@ sub definition {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 duplicate
Extend the master method to duplicate the storage location.
=cut
sub duplicate { sub duplicate {
my $self = shift; my $self = shift;
my $newAsset = $self->SUPER::duplicate(@_); my $newAsset = $self->SUPER::duplicate(@_);
@ -161,6 +167,12 @@ sub exportAssetData {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 exportWriteFile
Places a copy of the file from storage into the right location during an export.
=cut
sub exportWriteFile { sub exportWriteFile {
my $self = shift; my $self = shift;
@ -244,6 +256,13 @@ sub getEditFormUploadControl {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getFileUrl
Returns the URL for the file stored in the storage location.
=cut
sub getFileUrl { sub getFileUrl {
my $self = shift; my $self = shift;
#return $self->get("url"); #return $self->get("url");
@ -251,15 +270,35 @@ sub getFileUrl {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getFileIconUrl
Returns the icon for the file stored in the storage location. If there's no
file, then it returns undef.
=cut
sub getFileIconUrl { sub getFileIconUrl {
my $self = shift; my $self = shift;
return undef unless $self->get("filename"); ## Why do I have to do this when creating new Files? return undef unless $self->get("filename"); ## Why do I have to do this when creating new Files?
return $self->getStorageLocation->getFileIconUrl($self->get("filename")); return $self->getStorageLocation->getFileIconUrl($self->get("filename"));
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getIcon ($small)
Return an icon indicating what type of file this is. If the $small flag is set,
then the icon returned is a file type icon, rather than an asset icon.
=head3 $small
Indicates that a small icon should be returned.
=cut
sub getIcon { sub getIcon {
my $self = shift; my $self = shift;
my $small = shift; my $small = shift;
@ -303,6 +342,13 @@ sub getStorageFromPost {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getStorageLocation
Returns the storage location for this asset. If one does not exist, then it
is created.
=cut
sub getStorageLocation { sub getStorageLocation {
my $self = shift; my $self = shift;
unless (exists $self->{_storageLocation}) { unless (exists $self->{_storageLocation}) {
@ -345,6 +391,13 @@ sub prepareView {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 processPropertiesFromFormPost
Extend the master method to handle file uploads and applying constraints.
=cut
sub processPropertiesFromFormPost { sub processPropertiesFromFormPost {
my $self = shift; my $self = shift;
my $session = $self->session; my $session = $self->session;
@ -369,6 +422,12 @@ sub processPropertiesFromFormPost {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 purge
Extends the master method to delete all storage locations associated with this asset.
=cut
sub purge { sub purge {
my $self = shift; my $self = shift;
my $sth = $self->session->db->read("select storageId from FileAsset where assetId=".$self->session->db->quote($self->getId)); my $sth = $self->session->db->read("select storageId from FileAsset where assetId=".$self->session->db->quote($self->getId));
@ -383,7 +442,7 @@ sub purge {
=head2 purgeCache ( ) =head2 purgeCache ( )
See WebGUI::Asset::purgeCache() for details. Extends the master method to clear the view cache.
=cut =cut
@ -395,6 +454,12 @@ sub purgeCache {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 purgeRevision
Extends the master method to delete the storage location for this asset.
=cut
sub purgeRevision { sub purgeRevision {
my $self = shift; my $self = shift;
$self->getStorageLocation->delete; $self->getStorageLocation->delete;
@ -457,6 +522,19 @@ sub setSize {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 setStorageLocation ($storage)
Updates the locally cached storage location. If this asset does not have a
storage location, then one is created. Otherwise, the storage location's storageId
is fetched from the db and used to create a storage location which is then placed
in the local object cache.
=head3 $storage
If defined, the locally cached storage location is set to this object.
=cut
sub setStorageLocation { sub setStorageLocation {
my $self = shift; my $self = shift;
my $storage = shift; my $storage = shift;
@ -520,6 +598,13 @@ sub updatePropertiesFromStorage {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 view
Generate the view method for the Asset, and handle caching.
=cut
sub view { sub view {
my $self = shift; my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
@ -540,6 +625,14 @@ sub view {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_edit
Display the edit form to the user. Manually handles the template for displaying
the inline view of the asset.
=cut
sub www_edit { sub www_edit {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
@ -556,6 +649,11 @@ sub www_edit {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_view
When viewed directly, stream the stored file to the user.
=cut
sub www_view { sub www_view {
my $self = shift; my $self = shift;

View file

@ -185,19 +185,14 @@ sub getEditForm {
return $tabform; return $tabform;
} }
#---------------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getStorageClass =head2 getThumbnailUrl
Returns the class name of the WebGUI::Storage we should use for this asset. Returns the URL to the thumbnail of the image stored in the Asset.
=cut =cut
sub getStorageClass {
return 'WebGUI::Storage';
}
#-------------------------------------------------------------------
sub getThumbnailUrl { sub getThumbnailUrl {
my $self = shift; my $self = shift;
return $self->getStorageLocation->getThumbnailUrl($self->get("filename")); return $self->getStorageLocation->getThumbnailUrl($self->get("filename"));
@ -219,21 +214,12 @@ sub getToolbar {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 prepareView ( ) =head2 view
See WebGUI::Asset::prepareView() for details. Renders this asset.
=cut =cut
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
$template->prepare($self->getMetaDataAsTemplateVariables);
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
sub view { sub view {
my $self = shift; my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
@ -282,6 +268,14 @@ sub setFile {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_edit
Override the master class to add image editing controls to the edit screen.
Also adds the Image template form variable.
=cut
sub www_edit { sub www_edit {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
@ -303,6 +297,14 @@ sub www_edit {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_undo
Rolls back the last revision of this asset, undoing any work that may
have been done to it.
=cut
sub www_undo { sub www_undo {
my $self = shift; my $self = shift;
my $previous = (@{$self->getRevisions()})[1]; my $previous = (@{$self->getRevisions()})[1];
@ -332,6 +334,12 @@ sub www_undo {
# All of the image operations will have to be updated to support annotations. # All of the image operations will have to be updated to support annotations.
# #
=head2 www_annotate
Allow the user to place some text on their image. This is done via JS and tooltips
=cut
sub www_annotate { sub www_annotate {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
@ -421,6 +429,19 @@ sub www_annotate {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 annotate_js ($opts)
Returns some javascript and other supporting text.
=head3 $opts
A hash reference of options
=head4 just_image
=cut
sub annotate_js { sub annotate_js {
my $self = shift; my $self = shift;
my $opts = shift; my $opts = shift;
@ -531,11 +552,20 @@ sub annotate_js {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_rotate
Displays a form to the user to rotate their image. If the C<Rotate> form variable
is true, does the rotation as well.
Returns the user to the roate form.
=cut
sub www_rotate { sub www_rotate {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked; return $self->session->privilege->locked() unless $self->canEditIfLocked;
# warn(sprintf("Rotate_formId: %s", $self->session->form->process("Rotate")));
if (defined $self->session->form->process("Rotate")) { if (defined $self->session->form->process("Rotate")) {
my $newSelf = $self->addRevision(); my $newSelf = $self->addRevision();
delete $newSelf->{_storageLocation}; delete $newSelf->{_storageLocation};
@ -579,6 +609,16 @@ sub www_rotate {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_resize
Displays a form for the user to resize this image. If either of the C<newWidth> or
C<newHeight> form variables are true, also does the resizing.
Returns the user to the resize form.
=cut
sub www_resize { sub www_resize {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
@ -672,16 +712,27 @@ sub www_resize {
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_crop
Display a form that allows the user to Crop their images. Also does the
cropping if any of the C<Width>, C<Height>, C<Top> or C<Left> form
variables are true.
Returns the user to the cropping form.
=cut
sub www_crop { sub www_crop {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked; return $self->session->privilege->locked() unless $self->canEditIfLocked;
if ($self->session->form->process("Width") || $self->session->form->process("Height") if ($self->session->form->process("Width") || $self->session->form->process("Height")
|| $self->session->form->process("Top") || $self->session->form->process("Left")) { || $self->session->form->process("Top") || $self->session->form->process("Left")) {
my $newSelf = $self->addRevision(); my $newSelf = $self->addRevision();
delete $newSelf->{_storageLocation}; delete $newSelf->{_storageLocation};
$newSelf->getStorageLocation->crop( $newSelf->getStorageLocation->crop(
$newSelf->get("filename"), $newSelf->get("filename"),
$newSelf->session->form->process("Width"), $newSelf->session->form->process("Width"),
$newSelf->session->form->process("Height"), $newSelf->session->form->process("Height"),
@ -690,7 +741,7 @@ sub www_crop {
); );
$self = $newSelf; $self = $newSelf;
$self->generateThumbnail; $self->generateThumbnail;
} }
my $filename = $self->get("filename"); my $filename = $self->get("filename");
@ -777,21 +828,4 @@ sub www_crop {
return $self->getAdminConsole->render($f->print.$image,$i18n->get("crop image")); return $self->getAdminConsole->render($f->print.$image,$i18n->get("crop image"));
} }
#-------------------------------------------------------------------
# Use superclass method for now.
sub www_view {
my $self = shift;
return($self->SUPER::www_view);
}
#sub www_view {
# my $self = shift;
# my $storage = $self->getStorageLocation;
# $self->session->http->setRedirect($storage->getUrl($self->get("filename")));
# $self->session->http->setStreamedFile($storage->getPath($self->get("filename")));
# return "1";
#}
1; 1;