Files
Orchard/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPostDriver.cs
Nathan Heskew 6e756f54ff Starting to get a UI around content type management
- added a DisplayName to the ContentTypeDefinition
- added a CreateRouteValues rvd to go along with the existing display and edit
- set default display, edit and create route values for ContentItemMetadata (* should get fallback route values in a different manner. probably not good to refer to an area, even by string, in core from the fwk)
- starting to shape up the content type list into a more consistent UI
- added create type action, view, etc. for creating new content types
 - supporting service has a few default parts hard-coded for now

--HG--
branch : dev
2010-06-16 04:22:51 -07:00

102 lines
4.7 KiB
C#

using System;
using System.Web.Routing;
using JetBrains.Annotations;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Services;
using Orchard.Localization;
namespace Orchard.Blogs.Drivers {
[UsedImplicitly]
public class BlogPostDriver : ContentItemDriver<BlogPost> {
public IOrchardServices Services { get; set; }
private readonly IBlogPostService _blogPostService;
private readonly IRoutableService _routableService;
public readonly static ContentType ContentType = new ContentType {
Name = "blogpost",
DisplayName = "Blog Post"
};
public BlogPostDriver(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, IRoutableService routableService) {
Services = services;
_blogPostService = blogPostService;
_routableService = routableService;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override ContentType GetContentType() {
return ContentType;
}
protected override string Prefix { get { return ""; } }
protected override string GetDisplayText(BlogPost post) {
return post.Title;
}
public override RouteValueDictionary GetDisplayRouteValues(BlogPost post) {
if (post.Blog == null)
return new RouteValueDictionary();
return new RouteValueDictionary {
{"Area", "Orchard.Blogs"},
{"Controller", "BlogPost"},
{"Action", "Item"},
{"blogSlug", post.Blog.Slug},
{"postSlug", post.Slug},
};
}
public override RouteValueDictionary GetEditorRouteValues(BlogPost post) {
if (post.Blog == null)
return new RouteValueDictionary();
return new RouteValueDictionary {
{"Area", "Orchard.Blogs"},
{"Controller", "BlogPostAdmin"},
{"Action", "Edit"},
{"blogSlug", post.Blog.Slug},
{"postId", post.Id},
};
}
public override RouteValueDictionary GetCreateRouteValues(BlogPost post) {
if (post.Blog == null)
return new RouteValueDictionary();
return new RouteValueDictionary {
{"Area", "Orchard.Blogs"},
{"Controller", "BlogPostAdmin"},
{"Action", "Create"},
{"blogSlug", post.Blog.Slug},
};
}
protected override DriverResult Display(BlogPost post, string displayType) {
return Combined(
ContentItemTemplate("Items/Blogs.BlogPost").LongestMatch(displayType, "Summary", "SummaryAdmin"),
ContentPartTemplate(post, "Parts/Blogs.BlogPost.Metadata").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("meta", "1"));
}
protected override DriverResult Editor(BlogPost post) {
return Combined(
ContentItemTemplate("Items/Blogs.BlogPost"),
ContentPartTemplate(post, "Parts/Blogs.BlogPost.Publish").Location("secondary", "1"));
}
protected override DriverResult Editor(BlogPost post, IUpdateModel updater) {
updater.TryUpdateModel(post, Prefix, null, null);
DateTime scheduled;
if (DateTime.TryParse(string.Format("{0} {1}", post.ScheduledPublishUtcDate, post.ScheduledPublishUtcTime), out scheduled))
post.ScheduledPublishUtc = scheduled;
return Editor(post);
}
}
}