mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 21:32:14 +08:00
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044851
35 lines
1.8 KiB
C#
35 lines
1.8 KiB
C#
using Orchard.Core.Common.Models;
|
|
using Orchard.Core.Common.Records;
|
|
using Orchard.Core.Common.ViewModels;
|
|
using Orchard.Data;
|
|
using Orchard.ContentManagement.Handlers;
|
|
using Orchard.ContentManagement.ViewModels;
|
|
|
|
namespace Orchard.Core.Common.Providers {
|
|
public class BodyAspectHandler : ContentHandler {
|
|
private const string TemplatePrefix = "Body";
|
|
private const string TemplateName = "Parts/Common.Body";
|
|
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
|
|
|
public BodyAspectHandler(IRepository<BodyRecord> bodyRepository) {
|
|
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true });
|
|
|
|
OnGetDisplayViewModel<BodyAspect>((context, body) => {
|
|
var model = new BodyDisplayViewModel { BodyAspect = body };
|
|
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary" });
|
|
});
|
|
|
|
OnGetEditorViewModel<BodyAspect>((context, body) => {
|
|
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
|
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary" });
|
|
});
|
|
|
|
OnUpdateEditorViewModel<BodyAspect>((context, body) => {
|
|
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
|
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
|
|
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary" });
|
|
});
|
|
}
|
|
}
|
|
}
|