diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs index 264f752b4..c6466dda1 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs @@ -1,17 +1,20 @@ -using System.Collections.Generic; +using System; using Orchard.Data; using Orchard.Models; using Orchard.Models.Driver; using Orchard.Models.ViewModels; +using Orchard.Comments.Services; namespace Orchard.Comments.Models { public class HasCommentsProvider : ContentProvider { private readonly IRepository _commentsRepository; private readonly IRepository _closedCommentsRepository; + private readonly ICommentService _commentService; - public HasCommentsProvider(IRepository commentsRepository, IRepository closedCommentsRepository) { + public HasCommentsProvider(IRepository commentsRepository, IRepository closedCommentsRepository, ICommentService commentService) { _commentsRepository = commentsRepository; _closedCommentsRepository = closedCommentsRepository; + _commentService = commentService; Filters.Add(new ActivatingFilter("sandboxpage")); Filters.Add(new ActivatingFilter("blogpost")); } @@ -34,6 +37,19 @@ namespace Orchard.Comments.Models { if (context.ContentItem.Has() == false) { return; } + CommentsViewModel viewModel = new CommentsViewModel(); + context.Updater.TryUpdateModel(viewModel, String.Empty, null, null); + bool closed = viewModel.Closed == null ? false : true; + bool currentStatus = _commentService.CommentsClosedForCommentedContent(context.ContentItem.Id); + if (currentStatus != closed) { + if (closed) { + _commentService.CloseCommentsForCommentedContent(context.ContentItem.Id); + } + else { + _commentService.EnableCommentsForCommentedContent(context.ContentItem.Id); + } + } + context.AddEditor(new TemplateViewModel(context.ContentItem.Get())); } @@ -48,5 +64,9 @@ namespace Orchard.Comments.Models { comments.Closed = true; } } + + public class CommentsViewModel { + public String Closed { get; set; } + } } } diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/EditorTemplates/HasComments.ascx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/EditorTemplates/HasComments.ascx index d187e1171..7732e4c46 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/EditorTemplates/HasComments.ascx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/EditorTemplates/HasComments.ascx @@ -8,25 +8,13 @@ new { Area = "Orchard.Comments", Controller = "Admin", id = Model.ContentItem.Id, returnUrl = Context.Request.Url } ) %> - 0 pending<% } %> - + -<%-- -todo: (heskew) would be better to have a ↑ checkbox ↑ instead of a ↓ button ↓ -
- <% if (Model.Closed) { - %><%=Html.ActionLink("Enable Comments", "Enable", new { commentedItemId = Model.Closed }, new { @class = "button" })%><% - } else { - %><%=Html.ActionLink("Close Comments", "Close", new { commentedItemId = Model.Closed }, new { @class = "button remove" })%><% - } %> -
---%><%-- -todo: (heskew) shouldn't have comments when editing a content item. besides being noisy/distracting it throw other issues like paging into the mix -
    - <% foreach (var comment in Model.Comments) {%> -
  1. -

    <%= comment.CommentText %>
    - Posted by <%= comment.UserName %> on <%= comment.CommentDate.ToLocalTime() %>
    - <%=Html.ActionLink("Delete", "Delete", new { Area = "Orchard.Comments", Controller = "Admin", id = comment.Id, returnUrl = Context.Request.Url }, new { @class = "ibutton remove" })%>

    -
  2. - <% } %> -
--%> +