mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Saving ThreadedComments defaul value in CommentsPart settings
--HG-- branch : 1.x extra : rebase_source : a0d016c2ee5b9420a95dfe24f5a07870ed78b68e
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Comments.Services;
|
||||
using Orchard.Comments.Settings;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using System.Collections.Generic;
|
||||
@@ -72,7 +73,14 @@ namespace Orchard.Comments.Drivers {
|
||||
|
||||
protected override DriverResult Editor(CommentsPart part, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_Comments_Enable",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Comments.Comments", Model: part, Prefix: Prefix));
|
||||
() => {
|
||||
// if the part is new, then apply threaded comments defaults
|
||||
if(!part.ContentItem.HasDraft() && !part.ContentItem.HasPublished()) {
|
||||
var settings = part.TypePartDefinition.Settings.GetModel<CommentsPartSettings>();
|
||||
part.ThreadedComments = settings.DefaultThreadedComments;
|
||||
}
|
||||
return shapeHelper.EditorTemplate(TemplateName: "Parts.Comments.Comments", Model: part, Prefix: Prefix);
|
||||
});
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommentsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
|
@@ -20,7 +20,6 @@ namespace Orchard.Comments.Handlers {
|
||||
OnInitializing<CommentsPart>((ctx, part) => {
|
||||
part.CommentsActive = true;
|
||||
part.CommentsShown = true;
|
||||
part.ThreadedComments = true;
|
||||
part.Comments = new List<CommentPart>();
|
||||
});
|
||||
|
||||
|
@@ -75,6 +75,8 @@
|
||||
<Compile Include="Rules\CommentsForms.cs" />
|
||||
<Compile Include="Services\CommentValidator.cs" />
|
||||
<Compile Include="Services\ICheckSpamEventHandler.cs" />
|
||||
<Compile Include="Settings\CommentsPartSettings.cs" />
|
||||
<Compile Include="Settings\CommentsPartSettingsEvents.cs" />
|
||||
<Compile Include="Shapes.cs" />
|
||||
<Compile Include="Models\CommentPart.cs" />
|
||||
<Compile Include="Handlers\CommentPartHandler.cs" />
|
||||
@@ -160,6 +162,7 @@
|
||||
<Content Include="Views\Content-Comment.SummaryAdmin.cshtml" />
|
||||
<Content Include="Views\ListOfComments.cshtml" />
|
||||
<Content Include="Views\CommentReplyButton.cshtml" />
|
||||
<Content Include="Views\DefinitionTemplates\CommentsPartSettings.cshtml" />
|
||||
<None Include="Views\Parts.Comment.SummaryAdmin.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
|
@@ -0,0 +1,5 @@
|
||||
namespace Orchard.Comments.Settings {
|
||||
public class CommentsPartSettings {
|
||||
public bool DefaultThreadedComments { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Comments.Settings {
|
||||
public class CommentsPartSettingsEvents : ContentDefinitionEditorEventsBase {
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) {
|
||||
if (definition.PartDefinition.Name != "CommentsPart")
|
||||
yield break;
|
||||
|
||||
var settings = definition.Settings.GetModel<CommentsPartSettings>();
|
||||
|
||||
yield return DefinitionTemplate(settings);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
if (builder.Name != "CommentsPart")
|
||||
yield break;
|
||||
|
||||
var settings = new CommentsPartSettings {
|
||||
};
|
||||
|
||||
if (updateModel.TryUpdateModel(settings, "CommentsPartSettings", null, null)) {
|
||||
builder.WithSetting("CommentsPartSettings.DefaultThreadedComments", settings.DefaultThreadedComments.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
yield return DefinitionTemplate(settings);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
@model Orchard.Comments.Settings.CommentsPartSettings
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.EditorFor(m => m.DefaultThreadedComments)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.DefaultThreadedComments)">@T("Use threaded comments by default")</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
Reference in New Issue
Block a user