fix: GalleryAlbum and Photo were not showing correct confirmation messages on editSave
add: Ability to edit comments to Photos add: Ability to choose which rich editor for Albums
This commit is contained in:
parent
a69dff3dcf
commit
8af6f28988
10 changed files with 340 additions and 122 deletions
|
|
@ -111,22 +111,53 @@ sub definition {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 appendTemplateVarsForCommentForm ( var )
|
||||
=head2 appendTemplateVarsCommentForm ( var [, comment ] )
|
||||
|
||||
Add the template variables necessary for the comment form to the given hash
|
||||
reference. Returns the hash reference for convenience.
|
||||
reference. Returns the hash reference for convenience. C<comment> is a hash
|
||||
reference of values to populate the form with.
|
||||
|
||||
=cut
|
||||
|
||||
sub appendTemplateVarsForCommentForm {
|
||||
sub appendTemplateVarsCommentForm {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $comment = shift || {};
|
||||
my $session = $self->session;
|
||||
|
||||
# Default comment
|
||||
$comment->{ commentId } ||= "new";
|
||||
|
||||
$var->{ commentForm_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => "func", value => "addCommentSave" } )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "func",
|
||||
value => "editCommentSave"
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "commentId",
|
||||
value => $comment->{ commentId }
|
||||
} )
|
||||
;
|
||||
|
||||
# Add hidden fields for editing a comment
|
||||
if ( $comment->{ commentId } ne "new" ) {
|
||||
$var->{ commentForm_start }
|
||||
.= WebGUI::Form::hidden( $session, {
|
||||
name => "userId",
|
||||
value => $comment->{ userId }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "visitorIp",
|
||||
value => $comment->{ visitorIp }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "creationDate",
|
||||
value => $comment->{ creationDate }
|
||||
} )
|
||||
;
|
||||
}
|
||||
|
||||
$var->{ commentForm_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
|
|
@ -134,6 +165,7 @@ sub appendTemplateVarsForCommentForm {
|
|||
= WebGUI::Form::HTMLArea( $session, {
|
||||
name => "bodyText",
|
||||
richEditId => $self->getGallery->get("richEditIdComment"),
|
||||
value => $comment->{ bodyText },
|
||||
});
|
||||
|
||||
$var->{ commentForm_submit }
|
||||
|
|
@ -605,6 +637,53 @@ sub prepareView {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processCommentEditForm ( )
|
||||
|
||||
Process the Comment Add / Edit Form. Returns a hash reference of properties
|
||||
that can be passed to C<setComment>.
|
||||
|
||||
Will die with an i18n-friendly error message if something is missing or
|
||||
wrong.
|
||||
|
||||
=cut
|
||||
|
||||
sub processCommentEditForm {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $now = WebGUI::DateTime->new( $session, time );
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
# Using die here to suppress line number and file path info
|
||||
die $i18n->get("commentForm error no commentId") . "\n"
|
||||
unless $form->get("commentId");
|
||||
die $i18n->get("commentForm error no bodyText") . "\n"
|
||||
unless $form->get("bodyText");
|
||||
|
||||
my $new = $form->get('commentId') eq "new"
|
||||
? 1
|
||||
: 0
|
||||
;
|
||||
|
||||
my $visitorIp = $session->user->userId eq "1"
|
||||
? $session->env->get("REMOTE_ADDR")
|
||||
: undef
|
||||
;
|
||||
|
||||
my $properties = {
|
||||
commentId => $form->get("commentId"),
|
||||
assetId => $self->getId,
|
||||
bodyText => $form->get("bodyText"),
|
||||
creationDate => ( $new ? $now->toDatabaseDate : $form->get("creationDate") ),
|
||||
userId => ( $new ? $session->user->userId : $form->get("userId") ),
|
||||
visitorIp => ( $new ? $visitorIp : $form->get("visitorIp") ),
|
||||
};
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
||||
|
||||
|
|
@ -656,31 +735,37 @@ sub purge {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 setComment ( commentId, properties )
|
||||
=head2 setComment ( properties )
|
||||
|
||||
Set a comment. If C<commentId> is C<"new">, create a new comment. C<properties>
|
||||
is a hash reference of comment information.
|
||||
Set a comment. C<properties> is a hash reference of comment information with
|
||||
the following keys:
|
||||
|
||||
assetId - The assetId of the asset this comment is for
|
||||
commentId - The ID of the comment. If "new", will make a new comment.
|
||||
bodyText - The body of the comment
|
||||
userId - The userId of the user who made the comment
|
||||
visitorIp - If the user was a visitor, the IP address of the user
|
||||
creationDate - A MySQL-formatted date/time when the comment was posted
|
||||
|
||||
=cut
|
||||
|
||||
sub setComment {
|
||||
my $self = shift;
|
||||
my $commentId = shift;
|
||||
my $properties = shift;
|
||||
|
||||
croak "Photo->setComment: commentId must be defined"
|
||||
unless $commentId;
|
||||
croak "Photo->setComment: properties must be a hash reference"
|
||||
unless $properties && ref $properties eq "HASH";
|
||||
croak "Photo->setComment: commentId must be defined"
|
||||
unless $properties->{ commentId };
|
||||
croak "Photo->setComment: properties must contain a bodyText key"
|
||||
unless $properties->{ bodyText };
|
||||
|
||||
$properties->{ creationDate } ||= WebGUI::DateTime->new($self->session, time)->toDatabase;
|
||||
$properties->{ assetId } = $self->getId;
|
||||
|
||||
$self->session->db->setRow(
|
||||
return $self->session->db->setRow(
|
||||
"Photo_comment", "commentId",
|
||||
{ %$properties, commentId => $commentId }
|
||||
$properties,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -725,7 +810,7 @@ sub view {
|
|||
my $session = $self->session;
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$self->appendTemplateVarsForCommentForm( $var );
|
||||
$self->appendTemplateVarsCommentForm( $var );
|
||||
|
||||
# Keywords
|
||||
my $k = WebGUI::Keyword->new( $session );
|
||||
|
|
@ -743,6 +828,8 @@ sub view {
|
|||
for my $comment ( @{ $p->getPageData } ) {
|
||||
$comment->{ url_deleteComment }
|
||||
= $self->getUrl('func=deleteComment;commentId=' . $comment->{commentId} );
|
||||
$comment->{ url_editComment }
|
||||
= $self->getUrl('func=editComment;commentId=' . $comment->{commentId} );
|
||||
|
||||
my $user = WebGUI::User->new( $session, $comment->{userId} );
|
||||
$comment->{ username } = $user->username;
|
||||
|
|
@ -759,38 +846,6 @@ sub view {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_addCommentSave ( )
|
||||
|
||||
Save a new comment to the Photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canComment;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
my $form = $self->session->form;
|
||||
|
||||
my $properties = {
|
||||
assetId => $self->getId,
|
||||
creationDate => WebGUI::DateTime->new( $session, time )->toDatabase,
|
||||
userId => $session->user->userId,
|
||||
visitorIp => ( $session->user->userId eq "1" ? $session->env("REMOTE_ADDR") : undef ),
|
||||
bodyText => $form->get("bodyText"),
|
||||
};
|
||||
|
||||
$self->setComment( "new", $properties );
|
||||
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_delete ( )
|
||||
|
||||
Show the page to confirm the deletion of this Photo. Show a list of albums
|
||||
|
|
@ -1016,19 +1071,74 @@ sub www_edit {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
=head2 www_editComment ( params )
|
||||
|
||||
Save the edit form. Overridden to display a confirm message to the user.
|
||||
Form to edit a comment. C<params> is a hash reference of parameters
|
||||
with the following keys:
|
||||
|
||||
errors = An array reference of errors to show the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
sub www_editComment {
|
||||
my $self = shift;
|
||||
$self->SUPER::www_editSave;
|
||||
my $params = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $self->session );
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
sprintf $i18n->get("save message"), $self->getUrl,
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
if ( $params->{ errors } ) {
|
||||
$var->{ errors } = [ map { { "error" => $_ } } @{ $params->{errors} } ];
|
||||
}
|
||||
|
||||
my $commentId = $session->form->get( "commentId" );
|
||||
my $comment = $self->getComment( $commentId );
|
||||
$self->appendTemplateVarsCommentForm( $var, $comment );
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdEditComment") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editCommentSave ( )
|
||||
|
||||
Save a comment being edited
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
my $comment = eval { $self->processCommentEditForm };
|
||||
if ( $@ ) {
|
||||
return $self->www_editComment( { errors => [ $@ ] } );
|
||||
}
|
||||
|
||||
# setComment changes commentId, so keep track if we're adding a new comment
|
||||
my $isNew = $comment->{commentId} eq "new";
|
||||
|
||||
$self->setComment( $comment );
|
||||
|
||||
# Return different message for adding and editing
|
||||
if ( $isNew ) {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('editCommentSave message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -118,6 +118,13 @@ sub definition {
|
|||
label => $i18n->get("maxSpacePerUser label"),
|
||||
hoverHelp => $i18n->get("maxSpacePerUser description"),
|
||||
},
|
||||
richEditIdAlbum => {
|
||||
tab => "properties",
|
||||
fieldType => "selectRichEditor",
|
||||
defaultValue => "PBrichedit000000000001", # Content Managers editor
|
||||
label => $i18n->get("richEditIdAlbum label"),
|
||||
hoverHelp => $i18n->get("richEditIdAlbum description"),
|
||||
},
|
||||
richEditIdComment => {
|
||||
tab => "properties",
|
||||
fieldType => "selectRichEditor",
|
||||
|
|
@ -157,6 +164,14 @@ sub definition {
|
|||
label => $i18n->get("templateIdEditAlbum label"),
|
||||
hoverHelp => $i18n->get("templateIdEditAlbum description"),
|
||||
},
|
||||
templateIdEditComment => {
|
||||
tab => "display",
|
||||
fieldType => "template",
|
||||
defaultValue => "OxJWQgnGsgyGohP2L3zJPQ",
|
||||
namespace => "GalleryFile/EditComment",
|
||||
label => $i18n->get("templateIdEditComment label"),
|
||||
hoverHelp => $i18n->get("templateIdEditComment description"),
|
||||
},
|
||||
templateIdEditFile => {
|
||||
tab => "display",
|
||||
fieldType => "template",
|
||||
|
|
|
|||
|
|
@ -814,29 +814,6 @@ sub www_edit {
|
|||
);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
|
||||
Save the asset edit form. Overridden to give a nice message when a photo or
|
||||
album is added
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
my $i18n = __PACKAGE__->i18n($self->session);
|
||||
$self->SUPER::www_editSave;
|
||||
|
||||
if ( $form->get("assetId") eq "new" ) {
|
||||
return sprintf $i18n->get("addFile message"), $self->getUrl,
|
||||
}
|
||||
else {
|
||||
return sprintf $i18n->get("save message"), $self->getUrl,
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_showConfirmation ( )
|
||||
|
|
|
|||
|
|
@ -260,6 +260,32 @@ our $HELP = {
|
|||
],
|
||||
},
|
||||
|
||||
'help editComment' => {
|
||||
title => 'help editComment title',
|
||||
body => 'help editComment body',
|
||||
isa => [
|
||||
{
|
||||
tag => 'help common',
|
||||
namespace => 'Asset_Photo',
|
||||
},
|
||||
{
|
||||
tag => 'help commentForm',
|
||||
namespace => 'Asset_Photo',
|
||||
},
|
||||
],
|
||||
variables => [
|
||||
{
|
||||
name => 'errors',
|
||||
description => 'helpvar errors',
|
||||
variables => [
|
||||
{
|
||||
name => 'error',
|
||||
description => 'helpvar error',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,16 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"richEditIdAlbum label" => {
|
||||
message => "Rich Editor for Albums",
|
||||
lastUpdated => 0,
|
||||
context => 'Asset property label',
|
||||
},
|
||||
"richEditIdAlbum description" => {
|
||||
message => "The Rich Text Editor to use for Albums",
|
||||
lastUpdated => 0,
|
||||
context => 'Asset property description',
|
||||
},
|
||||
"richEditIdFileComment label" => {
|
||||
message => "Rich Editor for Comments",
|
||||
lastUpdated => 0,
|
||||
|
|
@ -147,6 +157,16 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditComment label" => {
|
||||
message => "Template to Edit Comments",
|
||||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditComment description" => {
|
||||
message => "The template to edit a comment.",
|
||||
lastUpdated => 0,
|
||||
context => '',
|
||||
},
|
||||
"templateIdEditFile label" => {
|
||||
message => "Template to Edit Files",
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'editCommentSave message' => {
|
||||
message => q{The comment has been updated. <a href="%s">Back to Photo</a>.},
|
||||
lastUpdated => 0,
|
||||
context => q{Message after a comment is edited.},
|
||||
},
|
||||
|
||||
'help commentForm title' => {
|
||||
message => 'Photo -- Comment Form',
|
||||
lastUpdated => 0,
|
||||
|
|
@ -463,6 +469,48 @@ our $I18N = {
|
|||
context => 'Label for "save" button',
|
||||
},
|
||||
|
||||
'help editComment title' => {
|
||||
message => 'Photo Edit Comment Template',
|
||||
lastUpdated => 0,
|
||||
context => 'Help page title',
|
||||
},
|
||||
|
||||
'help editComment body' => {
|
||||
message => 'These variables are available to the Photo Edit Comment page',
|
||||
lastUpdated => 0,
|
||||
context => 'Help page body text',
|
||||
},
|
||||
|
||||
'helpvar errors' => {
|
||||
message => 'A loop of error messages to show the user',
|
||||
lastUpdated => 0,
|
||||
context => 'Description of template variable',
|
||||
},
|
||||
|
||||
'helpvar error' => {
|
||||
message => 'The i18n error message',
|
||||
lastUpdated => 0,
|
||||
context => 'Description of template variable',
|
||||
},
|
||||
|
||||
'template error happened' => {
|
||||
message => q{An error occurred while processing your request.},
|
||||
lastUpdated => 0,
|
||||
context => "Text shown when friendly error messages are being displayed",
|
||||
},
|
||||
|
||||
'commentForm error no commentId' => {
|
||||
message => q{No comment ID was given. This indicates a problem with the template. Please notify an administrator.},
|
||||
lastUpdated => 0,
|
||||
context => q{Error message when no comment ID was given. This should never happen unless the template is made wrong.},
|
||||
},
|
||||
|
||||
'commentForm error no bodyText' => {
|
||||
message => q{No text was entered. Please enter some text to create a comment.},
|
||||
lastUpdated => 0,
|
||||
context => q{Error message for Photo comments},
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue