Make Comments cound display a shape

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-10-18 16:36:30 -07:00
parent be86c89eb2
commit 4ecb6ed588
3 changed files with 18 additions and 10 deletions

View File

@@ -1,42 +1,50 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.Html;
using Orchard.Utility.Extensions;
namespace Orchard.Comments.Extensions {
public static class HtmlHelperExtensions {
public static MvcHtmlString CommentSummaryLinks(this HtmlHelper html, Localizer T, ContentItem item, int commentCount, int pendingCount) {
public class CommentsSummary : IDependency {
public CommentsSummary() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
[Shape]
public MvcHtmlString CommentSummaryLinks(dynamic Display, HtmlHelper Html, ContentItem item, int count, int pendingCount) {
var commentText = "";
if (item.Id != 0) {
var totalCommentCount = commentCount + pendingCount;
var totalCommentCount = count + pendingCount;
var totalCommentText = T.Plural("1 comment", "{0} comments", totalCommentCount);
if (totalCommentCount == 0) {
commentText += totalCommentText.ToString();
}
else {
commentText +=
html.ActionLink(
Html.ActionLink(
totalCommentText.ToString(),
"Details",
new {
Area = "Orchard.Comments",
Controller = "Admin",
id = item.Id,
returnUrl = html.ViewContext.HttpContext.Request.ToUrlString()
returnUrl = Html.ViewContext.HttpContext.Request.ToUrlString()
});
}
if (pendingCount > 0) {
commentText += " " + html.ActionLink(T("({0} pending)", pendingCount).ToString(),
commentText += " " + Html.ActionLink(T("({0} pending)", pendingCount).ToString(),
"Details",
new {
Area = "Orchard.Comments",
Controller = "Admin",
id = item.Id,
returnUrl = html.ViewContext.HttpContext.Request.Url
returnUrl = Html.ViewContext.HttpContext.Request.Url
});
}
}
@@ -44,4 +52,4 @@ namespace Orchard.Comments.Extensions {
return MvcHtmlString.Create(commentText);
}
}
}
}

View File

@@ -6,7 +6,7 @@
<fieldset>
<legend>@T("Comments")
@if (Model.Comments.Count > 0) {
<span>&#150; @Html.CommentSummaryLinks(T, Model.ContentItem, Model.Comments.Count, Model.PendingComments.Count)</span>
<span>&#150; @Display.CommentSummaryLinks(item: Model.ContentItem, count: Model.Comments.Count, pendingCount: Model.PendingComments.Count)</span>
}
</legend>
@Html.EditorFor(m => m.CommentsActive)

View File

@@ -2,4 +2,4 @@
@using Orchard.Comments.Extensions;
@using Orchard.Comments.ViewModels;
@using Orchard.ContentManagement;
<span class="commentcount">@Html.CommentSummaryLinks(T, (ContentItem)Model.ContentPart.ContentItem, (int)Model.CommentCount, (int)Model.PendingCount)</span>
<span class="commentcount">@Display.CommentSummaryLinks(item: Model.ContentPart.ContentItem, count: Model.CommentCount, pendingCount: Model.PendingCount)</span>