diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml index a0d01ae300..a8a6b82748 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml @@ -41,4 +41,5 @@ @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "quote", entityId = "2" }) + @await Component.InvokeAsync(typeof(CommentingViewComponent), new { entityType = "quote", entityId = "2" }) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index 4df6575fbf..5749c5f66e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json @@ -5,8 +5,10 @@ "YourComment": "Your comment", "YourReply": "Your reply", "Send": "Send", - "Delete": "delete", - "Reply": "reply", + "Delete": "Delete", + "Reply": "Reply", + "Update": "Update", + "Edit": "Edit", "MessageDeletionConfirmationMessage": "This comment will be deleted completely." } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Comments/CommentPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Comments/CommentPublicAppService.cs index eb09af2afa..06991e6a42 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Comments/CommentPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Comments/CommentPublicAppService.cs @@ -56,6 +56,11 @@ namespace Volo.CmsKit.Comments { var comment = await CommentRepository.GetAsync(id); + if (comment.CreatorId != CurrentUser.Id) + { + throw new BusinessException(); + } + comment.SetText(input.Text); var updatedComment = await CommentRepository.UpdateAsync(comment); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml index b590cc8381..dc3df1d270 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml @@ -33,52 +33,83 @@ ; } +@{ + Func GetCommentContentArea(Guid id, Guid authorId, bool isReply, string text) => + @
+
+

+ @text +

+
+ + @if (!isReply) + { + + @L["Reply"] + + } + @if (authorId == CurrentUser.Id) + { + @if (!isReply) + { + | + } + + + @L["Delete"] + + + | + + + @L["Edit"] + + } + +
; +}
@foreach (var comment in Model.Comments) {
-

+

@GetCommentAuthorName(comment.Author).Invoke(null) -
-

- @comment.Text -

+ - @if (comment.Author.Id == CurrentUser.Id) - { - - @L["Delete"] - - } + @GetCommentContentArea(comment.Id, comment.Author.Id, false, comment.Text).Invoke(null) - - @L["Reply"] - + @GetCommentArea(comment.Id.ToString(), true).Invoke(null) - @foreach (var reply in comment.Replies) + @if (comment.Replies.Any()) { -
-
- - @GetCommentAuthorName(reply.Author).Invoke(null) -
-

- @reply.Text -

+
+ @foreach (var reply in comment.Replies) + { +
+
+ + @GetCommentAuthorName(reply.Author).Invoke(null) +
- @if (reply.Author.Id == CurrentUser.Id) - { - - @L["Delete"] - - } + @GetCommentContentArea(reply.Id, reply.Author.Id, true, reply.Text).Invoke(null) + +
+ }
} - @GetCommentArea(comment.Id.ToString(), true).Invoke(null)
}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js index 10dc9c1766..29def70797 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js @@ -15,6 +15,40 @@ }; } + function registerEditLinks($container) { + $container.find('.comment-edit-link').each(function () { + var $link = $(this); + $link.on('click', function (e) { + e.preventDefault(); + + var commentId = $link.data('id'); + + var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id='+ commentId +']'); + var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id='+ commentId +']'); + + $relatedCommentContentArea.hide(); + $relatedCommentEditFormArea.show(); + $link.removeAttr('href'); + }); + }); + $container.find('.comment-edit-cancel-button').each(function () { + var $button = $(this); + $button.on('click', function (e) { + e.preventDefault(); + + var commentId = $button.data('id'); + + var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id='+ commentId +']'); + var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id='+ commentId +']'); + var $link = $container.find('.comment-edit-link[data-id='+ commentId +']'); + + $relatedCommentContentArea.show(); + $relatedCommentEditFormArea.hide(); + $link.attr('href','#'); + }); + }); + } + function registerReplyLinks($container) { $container.find('.comment-reply-link').each(function () { var $link = $(this); @@ -23,9 +57,10 @@ var replyCommentId = $link.data('reply-id'); - var relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id='+ replyCommentId +']'); + var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id='+ replyCommentId +']'); - relatedCommentArea.show(); + $relatedCommentArea.show(); + $link.removeAttr('href'); }); }); $container.find('.reply-cancel-button').each(function () { @@ -35,9 +70,11 @@ var replyCommentId = $button.data('reply-id'); - var relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id='+ replyCommentId +']'); + var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id='+ replyCommentId +']'); + var $replyLink = $container.find('.comment-reply-link[data-reply-id='+ replyCommentId +']'); - relatedCommentArea.hide(); + $relatedCommentArea.hide(); + $replyLink.attr('href','#'); }); }); } @@ -48,11 +85,31 @@ $link.on('click', '', function (e) { e.preventDefault(); - abp.message.confirm(l("MessageDeletionConfirmationMessage"), function () { - volo.cmsKit.comments.commentPublic.delete($link.data('comment-id') - ).then(function () { - widgetManager.refresh($widget); - }); + abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) { + if (ok){ + volo.cmsKit.comments.commentPublic.delete($link.data('id') + ).then(function () { + widgetManager.refresh($widget); + }); + } + }); + }); + }); + } + + function registerUpdateOfNewComment($container) { + $container.find('.cms-comment-update-form').each(function () { + var $form = $(this); + $form.submit(function (e) { + e.preventDefault(); + var formAsObject = $form.serializeFormToObject(); + volo.cmsKit.comments.commentPublic.update( + formAsObject.id, + { + text: formAsObject.commentText + } + ).then(function () { + widgetManager.refresh($widget); }); }); }); @@ -64,13 +121,13 @@ $form.submit(function (e) { e.preventDefault(); var formAsObject = $form.serializeFormToObject(); + console.log(formAsObject); volo.cmsKit.comments.commentPublic.create( $.extend(getFilters(), { repliedCommentId: formAsObject.repliedCommentId, text: formAsObject.commentText }) ).then(function () { - $form.find('textarea').val(''); widgetManager.refresh($widget); }); }); @@ -79,7 +136,10 @@ function init() { registerReplyLinks($widget); + registerEditLinks($widget); registerDeleteLinks($widget); + + registerUpdateOfNewComment($widget); registerSubmissionOfNewComment($widget); }