mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding Approve, Moderate and Delete buttons in comments editor
--HG-- branch : 1.x
This commit is contained in:
@@ -9,9 +9,11 @@ using Orchard.Comments.Settings;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Security;
|
||||
using Orchard.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Comments.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Comments.Drivers {
|
||||
[UsedImplicitly]
|
||||
@@ -19,7 +21,9 @@ namespace Orchard.Comments.Drivers {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IClock _clock;
|
||||
private readonly ICommentService _commentService;
|
||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
protected override string Prefix { get { return "Comments"; } }
|
||||
|
||||
@@ -30,11 +34,14 @@ namespace Orchard.Comments.Drivers {
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IClock clock,
|
||||
ICommentService commentService,
|
||||
IEnumerable<IHtmlFilter> htmlFilters) {
|
||||
IEnumerable<IHtmlFilter> htmlFilters,
|
||||
IOrchardServices orchardServices) {
|
||||
_contentManager = contentManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_clock = clock;
|
||||
_commentService = commentService;
|
||||
_htmlFilters = htmlFilters;
|
||||
_orchardServices = orchardServices;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -69,6 +76,34 @@ namespace Orchard.Comments.Drivers {
|
||||
updater.TryUpdateModel(part, Prefix, null, null);
|
||||
var workContext = _workContextAccessor.GetContext();
|
||||
|
||||
|
||||
// applying moderate/approve actions
|
||||
var httpContext = workContext.HttpContext;
|
||||
var name = httpContext.Request.Form["submit.Save"];
|
||||
if (!string.IsNullOrEmpty(name) && String.Equals(name, "moderate", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) {
|
||||
_commentService.UnapproveComment(part.Id);
|
||||
_orchardServices.Notifier.Information(T("Comment successfully moderated."));
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(name) && String.Equals(name, "approve", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't approve comment"))) {
|
||||
_commentService.ApproveComment(part.Id);
|
||||
_orchardServices.Notifier.Information(T("Comment approved."));
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(name) && String.Equals(name, "delete", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment"))) {
|
||||
_commentService.DeleteComment(part.Id);
|
||||
_orchardServices.Notifier.Information(T("Comment successfully deleted."));
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
part.CommentDateUtc = _clock.UtcNow;
|
||||
|
||||
if (!String.IsNullOrEmpty(part.SiteName) && !part.SiteName.StartsWith("http://") && !part.SiteName.StartsWith("https://")) {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
@model Orchard.Comments.Models.CommentPart
|
||||
@model CommentPart
|
||||
|
||||
@using Orchard.Comments.Models;
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
<ol>
|
||||
<li>
|
||||
@Html.LabelFor(m => m.Author, T("Name"))
|
||||
@Html.TextBoxFor(m => m.Author)
|
||||
@Html.TextBoxFor(m => m.Author, new { @class = "textMedium"})
|
||||
<span class="hint">@T("The author's name.")</span>
|
||||
</li>
|
||||
<li>
|
||||
@Html.LabelFor(m => m.Email, T("Email"))
|
||||
@Html.TextBoxFor(m => m.Email)
|
||||
@Html.TextBoxFor(m => m.Email, new { @class = "textMedium"})
|
||||
<span class="hint">@T("The email address the author has provided with the comment.")</span>
|
||||
</li>
|
||||
<li>
|
||||
@Html.LabelFor(m => m.SiteName, T("Url"))
|
||||
@Html.TextBoxFor(m => m.SiteName)
|
||||
@Html.TextBoxFor(m => m.SiteName, new { @class = "text large"})
|
||||
<span class="hint">@T("The website url the author has provided with the comment.")</span>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
@@ -22,20 +25,20 @@
|
||||
<div>
|
||||
@Html.LabelFor(m => m.CommentText, T("Comment"))
|
||||
@Html.TextAreaFor(m => m.CommentText, new { rows = 10, cols = 30, @class = "comment-text" })
|
||||
<span class="hint">@T("The body of the comment.")</span>
|
||||
@Html.HiddenFor(m => m.RepliedOn)
|
||||
@Html.HiddenFor(m => m.Id)
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.RadioButtonFor(m => m.Status, CommentStatus.Pending)
|
||||
<label class="forcheckbox" for="Status_Pending">@T("Pending")</label>
|
||||
</div>
|
||||
<div>
|
||||
@Html.RadioButtonFor(m => m.Status, CommentStatus.Approved)
|
||||
<label class="forcheckbox" for="Status_Approved">@T("Approved")</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit">@T("Save")</button>
|
||||
<button class="primaryAction" type="submit" name="submit.Save" >@T("Save")</button>
|
||||
<button class="primaryAction" type="submit" name="submit.Save" value="delete" itemprop="RemoveUrl">@T("Delete")</button>
|
||||
@if (Model.Status == CommentStatus.Approved) {
|
||||
<button class="primaryAction" type="submit" name="submit.Save" value="moderate">@T("Moderate")</button>
|
||||
}
|
||||
|
||||
@if (Model.Status == CommentStatus.Pending) {
|
||||
<button class="primaryAction" type="submit" name="submit.Save" value="approve">@T("Approve")</button>
|
||||
}
|
||||
</fieldset>
|
@@ -61,7 +61,7 @@
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit" name="submit.Save" value="@T("Save")">@T("Save")</button>
|
||||
@if (Model.Name != "Administrator") {
|
||||
<button type="submit" name="submit.Delete" value="@T("Delete")" itemprop="RemoveUrl" itemprop="RemoveUrl">@T("Delete")</button>
|
||||
<button type="submit" name="submit.Delete" value="@T("Delete")" itemprop="RemoveUrl">@T("Delete")</button>
|
||||
}
|
||||
</fieldset>
|
||||
}
|
Reference in New Issue
Block a user