- Blogs: Go for checkbox for closing comments and enabling them in the comment editors (was links previously).

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043226
This commit is contained in:
suhacan
2009-12-04 21:37:22 +00:00
parent 2917d86c0c
commit e2a21f6cf6
2 changed files with 31 additions and 23 deletions

View File

@@ -1,17 +1,20 @@
using System.Collections.Generic; using System;
using Orchard.Data; using Orchard.Data;
using Orchard.Models; using Orchard.Models;
using Orchard.Models.Driver; using Orchard.Models.Driver;
using Orchard.Models.ViewModels; using Orchard.Models.ViewModels;
using Orchard.Comments.Services;
namespace Orchard.Comments.Models { namespace Orchard.Comments.Models {
public class HasCommentsProvider : ContentProvider { public class HasCommentsProvider : ContentProvider {
private readonly IRepository<Comment> _commentsRepository; private readonly IRepository<Comment> _commentsRepository;
private readonly IRepository<ClosedComments> _closedCommentsRepository; private readonly IRepository<ClosedComments> _closedCommentsRepository;
private readonly ICommentService _commentService;
public HasCommentsProvider(IRepository<Comment> commentsRepository, IRepository<ClosedComments> closedCommentsRepository) { public HasCommentsProvider(IRepository<Comment> commentsRepository, IRepository<ClosedComments> closedCommentsRepository, ICommentService commentService) {
_commentsRepository = commentsRepository; _commentsRepository = commentsRepository;
_closedCommentsRepository = closedCommentsRepository; _closedCommentsRepository = closedCommentsRepository;
_commentService = commentService;
Filters.Add(new ActivatingFilter<HasComments>("sandboxpage")); Filters.Add(new ActivatingFilter<HasComments>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasComments>("blogpost")); Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
} }
@@ -34,6 +37,19 @@ namespace Orchard.Comments.Models {
if (context.ContentItem.Has<HasComments>() == false) { if (context.ContentItem.Has<HasComments>() == false) {
return; 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<HasComments>())); context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
} }
@@ -48,5 +64,9 @@ namespace Orchard.Comments.Models {
comments.Closed = true; comments.Closed = true;
} }
} }
public class CommentsViewModel {
public String Closed { get; set; }
}
} }
} }

View File

@@ -8,25 +8,13 @@
new { Area = "Orchard.Comments", Controller = "Admin", id = Model.ContentItem.Id, returnUrl = Context.Request.Url } new { Area = "Orchard.Comments", Controller = "Admin", id = Model.ContentItem.Id, returnUrl = Context.Request.Url }
) %> ) %>
- <a href="#">0 pending</a><% } %></legend> - <a href="#">0 pending</a><% } %></legend>
<label for="Closed"><%=Html.EditorFor(hc => hc.Closed) %> Close comments</label> <label for="Closed">
<% if (Model.Closed) {%>
<input id="Closed" name="Closed" type="checkbox" checked="checked" />
<% } else { %>
<input id="Closed" name="Closed" type="checkbox" />
<% } %>
Comments are disabled for this post
</label>
</fieldset> </fieldset>
<%--
todo: (heskew) would be better to have a ↑ checkbox ↑ instead of a ↓ button ↓
<div class="actions">
<% 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" })%><%
} %>
</div>
--%><%--
todo: (heskew) shouldn't have comments when editing a content item. besides being noisy/distracting it throw other issues like paging into the mix
<ol class="contentItems">
<% foreach (var comment in Model.Comments) {%>
<li>
<p><%= comment.CommentText %><br />
Posted by <%= comment.UserName %> on <%= comment.CommentDate.ToLocalTime() %><br />
<%=Html.ActionLink("Delete", "Delete", new { Area = "Orchard.Comments", Controller = "Admin", id = comment.Id, returnUrl = Context.Request.Url }, new { @class = "ibutton remove" })%></p>
</li>
<% } %>
</ol>--%>