From ebae62c366eda847c7da30cac1dbfdc99a4c6941 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 13 Feb 2005 18:58:28 +0000 Subject: [PATCH] added attachments for CS --- lib/WebGUI/Asset/Post.pm | 105 ++++++++++++++++++---- lib/WebGUI/Asset/Wobject/Collaboration.pm | 6 +- lib/WebGUI/Storage.pm | 2 +- www/extras/FileUploadControl.js | 8 +- 4 files changed, 97 insertions(+), 24 deletions(-) diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 54ddb42c9..451fd7359 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -29,6 +29,7 @@ use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; +use WebGUI::Storage::Image; use WebGUI::URL; use WebGUI::User; use WebGUI::Utility; @@ -248,6 +249,21 @@ sub getIcon { return $session{config}{extrasURL}.'/assets/post.gif'; } +#------------------------------------------------------------------- +sub getImageUrl { + my $self = shift; + return undef if ($self->get("storageId") eq ""); + my $storage = $self->getStorageLocation; + my $url; + foreach my $filename (@{$storage->getFiles}) { + if ($storage->isImage($filename)) { + $url = $storage->getUrl($filename); + last; + } + } + return $url; +} + #------------------------------------------------------------------- sub getName { return "Post"; @@ -315,6 +331,20 @@ sub getStatus { } } +#------------------------------------------------------------------- +sub getStorageLocation { + my $self = shift; + unless (exists $self->{_storageLocation}) { + if ($self->get("storageId") eq "") { + $self->{_storageLocation} = WebGUI::Storage::Image->create; + $self->update({storageId=>$self->{_storageLocation}->getId}); + } else { + $self->{_storageLocation} = WebGUI::Storage::Image->get($self->get("storageId")); + } + } + return $self->{_storageLocation}; +} + #------------------------------------------------------------------- sub getSynopsisAndContentFromFormPost { my $self = shift; @@ -361,18 +391,30 @@ sub getTemplateVars { $var{'rate.url.4'} = $self->getRateUrl(4); $var{'rate.url.5'} = $self->getRateUrl(5); $var{'hasRated'} = $self->hasRated; -# if ($submission->{image} ne "") { -# $file = WebGUI::Attachment->new($submission->{image},$self->wid,$submissionId); -# $var{"image.url"} = $file->getURL; -# $var{"image.thumbnail"} = $file->getThumbnail; -# } -# if ($submission->{attachment} ne "") { -# $file = WebGUI::Attachment->new($submission->{attachment},$self->wid,$submissionId); -# $var{"attachment.box"} = $file->box; -# $var{"attachment.url"} = $file->getURL; -# $var{"attachment.icon"} = $file->getIcon; -# $var{"attachment.name"} = $file->getFilename; - # } + my $gotImage; + my $gotAttachment; + unless ($self->get("storageId") eq "") { + my $storage = $self->getStorageLocation; + foreach my $filename (@{$storage->getFiles}) { + if (!$gotImage && $storage->isImage($filename)) { + $var{"image.url"} = $storage->getUrl($filename); + $var{"image.thumbnail"} = $storage->getThumbnailUrl($filename); + $gotImage = 1; + } + if (!$gotAttachment && !$storage->isImage($filename)) { + $var{"attachment.url"} = $storage->getUrl($filename); + $var{"attachment.icon"} = $storage->getFileIconUrl($filename); + $var{"attachment.name"} = $filename; + } + push(@{$var{"attachment_loop"}}, { + url=>$storage->getUrl($filename), + icon=>$storage->getFileIconUrl($filename), + filename=>$filename, + thumbnail=>$storage->getThumbnailUrl($filename), + isImage=>$storage->isImage($filename) + }); + } + } return \%var; } @@ -385,13 +427,36 @@ sub getThread { return $self->{_thread}; } +#------------------------------------------------------------------- +sub getThumbnailUrl { + my $self = shift; + return undef if ($self->get("storageId") eq ""); + my $storage = $self->getStorageLocation; + my $url; + foreach my $filename (@{$storage->getFiles}) { + if ($storage->isImage($filename)) { + $url = $storage->getThumbnailUrl($filename); + last; + } + } + return $url; +} + #------------------------------------------------------------------- sub getUploadControl { my $self = shift; - my $existingFiles = shift; + my $uploadControl; + if ($self->get("storageId")) { + my $i; + foreach my $filename (@{$self->getStorageLocation->getFiles}) { + $uploadControl .= ''.$filename.'
'; + $i++; + } + return $uploadControl unless ($i < $self->getThread->getParent->get("attachmentsPerPost")); + } WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"}); - my $uploadControl = '
+ $uploadControl .= '
'; - if ($self->get("storageId")) { - foreach my $filename (@{$self->getStorageLocation->getFiles}) { - $uploadControl .= ''.$filename.'
'; - } - } return $uploadControl; } @@ -579,6 +639,13 @@ sub processPropertiesFromFormPost { } else { $self->setStatusApproved; } + my $storage = $self->getStorageLocation; + my $filename = $storage->addFileFromFormPost("file"); + if (defined $filename) { + $self->setSize($storage->getFileSize($filename)); + $storage->setPrivileges($self->get("ownerUserId"), $self->get("groupIdView"), $self->get("groupIdEdit")); + $storage->generateThumbnail($filename); + } $session{form}{proceed} = "redirectToParent"; } diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 4d5130e21..f2f941aff 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -43,7 +43,7 @@ sub appendPostListTemplateVars { foreach my $row (@$page) { my $post = WebGUI::Asset::Wobject::Collaboration->newByPropertyHashRef($row); $post->{_parent} = $self; # caching parent for efficiency - my $controls = deleteIcon('func=delete',$post->get("url"),"Delete").editIcon('func=edit',$post->get("ur")); + my $controls = deleteIcon('func=delete',$post->get("url"),"Delete").editIcon('func=edit',$post->get("url")); if ($self->get("sortBy") eq "lineage") { if ($self->get("sortOrder") eq "desc") { $controls .= moveUpIcon('func=demote',$post->get("url")).moveDownIcon('func=promote',$post->get("url")); @@ -68,8 +68,8 @@ sub appendPostListTemplateVars { rating_loop=>\@rating_loop, "content"=>$post->formatContent, "status"=>$post->getStatus, - # "thumbnail"=>$submission->getThumbnailUrl, - # "submission.image"=>$submission->getImageUrl, + "thumbnail"=>$post->getThumbnailUrl, + "image.url"=>$post->getImageUrl, "dateSubmitted.human"=>epochToHuman($post->get("dateSubmitted"),"%z"), "dateUpdated.human"=>epochToHuman($post->get("dateUpdated"),"%z"), "timeSubmitted.human"=>epochToHuman($post->get("dateSubmitted"),"%Z"), diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index c06c4e16c..010458d20 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -498,7 +498,7 @@ sub getFiles { } return \@list; } - return undef; + return []; } diff --git a/www/extras/FileUploadControl.js b/www/extras/FileUploadControl.js index 8a4e3d673..994a99816 100755 --- a/www/extras/FileUploadControl.js +++ b/www/extras/FileUploadControl.js @@ -5,6 +5,8 @@ function FileUploadControl(workspaceId, imageArray) { this.images = images; + this.fileLimit = fileLimit; + this.fileCount = 1; this.dom=document.getElementById&&!document.all; this.topLevelElement=this.dom? "HTML" : "BODY" @@ -104,6 +106,7 @@ function FileUploadControl_removeButtonClick(e) { var control = FileUploadControl_getControl(firedobj); control.removeRow(firedobj); + control.fileCount--; } @@ -116,7 +119,10 @@ function FileUploadControl_valueChange(e) { var control = FileUploadControl_getControl(firedobj); if (control.tbody.childNodes[control.tbody.childNodes.length -1].childNodes[1].childNodes[0].value != "") { - control.addRow(); + if (control.fileCount < control.fileLimit) { + control.addRow(); + control.fileCount++; + } } control.swapImage(firedobj);