2009-11-29 06:08:46 +00:00
|
|
|
using System.Collections.Generic;
|
2009-12-08 04:40:38 +00:00
|
|
|
using System.Linq;
|
2009-12-02 02:24:39 +00:00
|
|
|
using System.Web.Routing;
|
2009-12-08 04:40:38 +00:00
|
|
|
using Orchard.Blogs.Services;
|
2009-11-24 02:03:13 +00:00
|
|
|
using Orchard.Core.Common.Models;
|
2009-11-20 23:31:49 +00:00
|
|
|
using Orchard.Data;
|
2009-11-24 02:03:13 +00:00
|
|
|
using Orchard.Models;
|
2009-11-20 23:31:49 +00:00
|
|
|
using Orchard.Models.Driver;
|
2009-12-08 04:40:38 +00:00
|
|
|
using Orchard.Models.ViewModels;
|
2009-11-20 23:31:49 +00:00
|
|
|
|
|
|
|
|
namespace Orchard.Blogs.Models {
|
2009-12-08 10:34:03 +00:00
|
|
|
public class BlogPostHandler : ContentHandler {
|
2009-11-29 06:08:46 +00:00
|
|
|
public override IEnumerable<ContentType> GetContentTypes() {
|
|
|
|
|
return new[] { BlogPost.ContentType };
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-08 10:34:03 +00:00
|
|
|
public BlogPostHandler(
|
2009-12-08 04:40:38 +00:00
|
|
|
IRepository<BlogPostRecord> repository,
|
|
|
|
|
IContentManager contentManager,
|
|
|
|
|
IBlogPostService blogPostService) {
|
|
|
|
|
|
2009-11-20 23:31:49 +00:00
|
|
|
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
2009-11-24 02:03:13 +00:00
|
|
|
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
|
|
|
|
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
|
|
|
|
|
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
|
2009-11-21 09:47:18 +00:00
|
|
|
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
2009-12-08 09:21:13 +00:00
|
|
|
Filters.Add(new ContentItemTemplates<BlogPost>("BlogPost", "Detail", "Summary", "SummaryAdmin"));
|
2009-12-07 09:39:09 +00:00
|
|
|
|
2009-12-02 02:24:39 +00:00
|
|
|
OnGetItemMetadata<BlogPost>((context, bp) => {
|
|
|
|
|
context.Metadata.DisplayText = bp.Title;
|
|
|
|
|
context.Metadata.DisplayRouteValues =
|
|
|
|
|
new RouteValueDictionary(
|
|
|
|
|
new {
|
|
|
|
|
area = "Orchard.Blogs",
|
|
|
|
|
controller = "BlogPost",
|
|
|
|
|
action = "Item",
|
|
|
|
|
blogSlug = bp.Blog.Slug,
|
|
|
|
|
postSlug = bp.Slug
|
|
|
|
|
});
|
|
|
|
|
context.Metadata.EditorRouteValues =
|
|
|
|
|
new RouteValueDictionary(
|
|
|
|
|
new {
|
|
|
|
|
area = "Orchard.Blogs",
|
|
|
|
|
controller = "BlogPost",
|
|
|
|
|
action = "Edit",
|
|
|
|
|
blogSlug = bp.Blog.Slug,
|
|
|
|
|
postSlug = bp.Slug
|
|
|
|
|
});
|
|
|
|
|
});
|
2009-12-08 04:40:38 +00:00
|
|
|
|
|
|
|
|
OnGetDisplayViewModel<Blog>((context, blog) => {
|
2009-12-08 09:21:13 +00:00
|
|
|
if (!context.DisplayType.StartsWith("Detail"))
|
2009-12-08 04:40:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var posts = blogPostService.Get(blog);
|
2009-12-08 09:21:13 +00:00
|
|
|
|
|
|
|
|
switch(context.DisplayType) {
|
|
|
|
|
case "Detail":
|
|
|
|
|
context.AddDisplay(
|
|
|
|
|
new TemplateViewModel(posts.Select(bp => contentManager.GetDisplayViewModel(bp, null, "Summary"))) {
|
|
|
|
|
TemplateName = "BlogPostList",
|
|
|
|
|
ZoneName = "body"
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "DetailAdmin":
|
|
|
|
|
context.AddDisplay(
|
|
|
|
|
new TemplateViewModel(posts.Select(bp => contentManager.GetDisplayViewModel(bp, null, "SummaryAdmin"))) {
|
|
|
|
|
TemplateName = "BlogPostListAdmin",
|
|
|
|
|
ZoneName = "body"
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-12-08 04:40:38 +00:00
|
|
|
});
|
|
|
|
|
|
2009-12-09 23:07:00 +00:00
|
|
|
OnGetEditorViewModel<BlogPost>((context, blogPost) =>
|
|
|
|
|
context.AddEditor(new TemplateViewModel(blogPost) {TemplateName = "BlogPostFields"})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
OnUpdateEditorViewModel<BlogPost>((context, blogPost) => {
|
|
|
|
|
context.AddEditor(new TemplateViewModel(blogPost) { TemplateName = "BlogPostFields" });
|
|
|
|
|
context.Updater.TryUpdateModel(blogPost, "", null, null);
|
|
|
|
|
});
|
|
|
|
|
}
|
2009-12-08 04:40:38 +00:00
|
|
|
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
|
}
|