mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Adding a filter for editor templates
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041360
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.Wikis.Models {
|
||||
public class WikiSettingsRecord : ContentPartRecord {
|
||||
public virtual bool AllowAnonymousEdits { get; set; }
|
||||
|
||||
[Required]
|
||||
public virtual string WikiEditTheme { get; set; }
|
||||
}
|
||||
|
||||
public class WikiSettingsHandler : ContentHandler {
|
||||
public WikiSettingsHandler(IRepository<WikiSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<ContentPartForRecord<WikiSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilterForRecord<WikiSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new TemplateFilterForRecord<WikiSettingsRecord>("WikiSettings"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Wikis.Models {
|
||||
public class WikiSettingsHandler : ContentHandler {
|
||||
public WikiSettingsHandler(IRepository<WikiSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<ContentPartForRecord<WikiSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilterForRecord<WikiSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetContentEditorsContext context) {
|
||||
var part = context.ContentItem.As<ContentPartForRecord<WikiSettingsRecord>>();
|
||||
if (part == null)
|
||||
return;
|
||||
|
||||
context.Editors.Add(ModelTemplate.For(part.Record, "WikiSettings"));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context) {
|
||||
var part = context.ContentItem.As<ContentPartForRecord<WikiSettingsRecord>>();
|
||||
if (part == null)
|
||||
return;
|
||||
|
||||
context.Updater.TryUpdateModel(part.Record, "WikiSettings", null, null);
|
||||
context.Editors.Add(ModelTemplate.For(part.Record, "WikiSettings"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.Wikis.Models {
|
||||
public class WikiSettingsRecord : ContentPartRecord {
|
||||
public virtual bool AllowAnonymousEdits { get; set; }
|
||||
|
||||
[Required]
|
||||
public virtual string WikiEditTheme { get; set; }
|
||||
}
|
||||
}
|
@@ -64,8 +64,7 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Models\WikiPageHandler.cs" />
|
||||
<Compile Include="Models\WikiSettingsHandler.cs" />
|
||||
<Compile Include="Models\WikiSettingsRecord.cs" />
|
||||
<Compile Include="Models\WikiSettings.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@@ -70,8 +70,16 @@ namespace Orchard.Models.Driver {
|
||||
Loaded(context);
|
||||
}
|
||||
|
||||
void IContentHandler.GetEditors(GetContentEditorsContext context) { GetEditors(context); }
|
||||
void IContentHandler.UpdateEditors(UpdateContentContext context) { UpdateEditors(context); }
|
||||
void IContentHandler.GetEditors(GetContentEditorsContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.GetEditors(context);
|
||||
GetEditors(context);
|
||||
}
|
||||
void IContentHandler.UpdateEditors(UpdateContentContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.UpdateEditors(context);
|
||||
UpdateEditors(context);
|
||||
}
|
||||
|
||||
protected virtual void Activating(ActivatingContentContext context) { }
|
||||
protected virtual void Activated(ActivatedContentContext context) { }
|
||||
|
11
src/Orchard/Models/Driver/IContentTemplateFilter.cs
Normal file
11
src/Orchard/Models/Driver/IContentTemplateFilter.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
interface IContentTemplateFilter : IContentFilter {
|
||||
void GetEditors(GetContentEditorsContext context);
|
||||
void UpdateEditors(UpdateContentContext context);
|
||||
}
|
||||
}
|
23
src/Orchard/Models/Driver/TemplateFilterBase.cs
Normal file
23
src/Orchard/Models/Driver/TemplateFilterBase.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public abstract class TemplateFilterBase<TPart> : IContentTemplateFilter where TPart : class, IContentItemPart {
|
||||
|
||||
protected virtual void GetEditors(GetContentEditorsContext context, TPart instance) { }
|
||||
protected virtual void UpdateEditors(UpdateContentContext context, TPart instance) { }
|
||||
|
||||
void IContentTemplateFilter.GetEditors(GetContentEditorsContext context) {
|
||||
if (context.ContentItem.Is<TPart>())
|
||||
GetEditors(context, context.ContentItem.As<TPart>());
|
||||
}
|
||||
|
||||
void IContentTemplateFilter.UpdateEditors(UpdateContentContext context) {
|
||||
if (context.ContentItem.Is<TPart>())
|
||||
UpdateEditors(context, context.ContentItem.As<TPart>());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
25
src/Orchard/Models/Driver/TemplateFilterForRecord.cs
Normal file
25
src/Orchard/Models/Driver/TemplateFilterForRecord.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPartForRecord<TRecord>> where TRecord : ContentPartRecord, new() {
|
||||
private readonly string _prefix;
|
||||
|
||||
public TemplateFilterForRecord(string prefix) {
|
||||
_prefix = prefix;
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetContentEditorsContext context, ContentPartForRecord<TRecord> part) {
|
||||
context.Editors.Add(ModelTemplate.For(part.Record, _prefix));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context, ContentPartForRecord<TRecord> part) {
|
||||
context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
|
||||
context.Editors.Add(ModelTemplate.For(part.Record, _prefix));
|
||||
}
|
||||
}
|
||||
}
|
@@ -130,6 +130,7 @@
|
||||
<Compile Include="Models\Driver\IContentActivatingFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentStorageFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentTemplateFilter.cs" />
|
||||
<Compile Include="Models\Driver\IUpdateModel.cs" />
|
||||
<Compile Include="Environment\ServiceLocator.cs" />
|
||||
<Compile Include="Logging\CastleLogger.cs" />
|
||||
@@ -149,6 +150,8 @@
|
||||
<Compile Include="Models\Driver\GetContentEditorsContext.cs" />
|
||||
<Compile Include="Models\Driver\StorageFilterForRecord.cs" />
|
||||
<Compile Include="Models\Driver\StorageFilterBase.cs" />
|
||||
<Compile Include="Models\Driver\TemplateFilterBase.cs" />
|
||||
<Compile Include="Models\Driver\TemplateFilterForRecord.cs" />
|
||||
<Compile Include="Models\IContentManager.cs" />
|
||||
<Compile Include="Models\Driver\IContentHandler.cs" />
|
||||
<Compile Include="Models\ContentExtensions.cs" />
|
||||
|
Reference in New Issue
Block a user