--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-23 15:00:05 -07:00
18 changed files with 77 additions and 107 deletions

View File

@@ -1,6 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<CreateItemViewModel>" %>
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
<% Html.AddTitleParts(T("Create Content").ToString()); %>
<h1><%:Html.TitleForPage((string.IsNullOrEmpty(Model.Content.Item.TypeDefinition.DisplayName) ? T("Create Content") : T("Create {0}", Model.Content.Item.TypeDefinition.DisplayName)).ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %>
<%:Html.EditorForItem(m=>m.Content) %>

View File

@@ -1,6 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<EditItemViewModel>" %>
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
<h1><%:Html.TitleForPage(T("Edit Content").ToString())%></h1>
<h1><%:Html.TitleForPage((string.IsNullOrEmpty(Model.Content.Item.TypeDefinition.DisplayName) ? T("Edit Content") : T("Edit {0}", Model.Content.Item.TypeDefinition.DisplayName)).ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %>
<%:Html.EditorForItem(m=>m.Content) %>

View File

@@ -1,4 +1,7 @@
using Orchard.ContentManagement;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.ContentsLocation.Models;
@@ -6,22 +9,27 @@ using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.Services;
using Orchard.Core.Routable.ViewModels;
using Orchard.Localization;
using Orchard.Services;
using Orchard.Settings;
using Orchard.UI.Notify;
namespace Orchard.Core.Routable.Drivers {
public class RoutePartDriver : ContentPartDriver<RoutePart> {
private readonly IOrchardServices _services;
private readonly IRoutableService _routableService;
private readonly IHomePageProvider _routableHomePageProvider;
public RoutePartDriver(IOrchardServices services, IRoutableService routableService) {
public RoutePartDriver(IOrchardServices services, IRoutableService routableService, IEnumerable<IHomePageProvider> homePageProviders) {
_services = services;
_routableService = routableService;
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name); ;
T = NullLocalizer.Instance;
}
private const string TemplateName = "Parts/Routable.RoutePart";
public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
protected override string Prefix {
get { return "Routable"; }
@@ -68,6 +76,7 @@ namespace Orchard.Core.Routable.Drivers {
}
var location = part.GetLocation("Editor");
model.PromoteToHomePage = model.Id != 0 && _routableHomePageProvider != null && CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
return ContentPartTemplate(model, TemplateName, Prefix).Location(location);
}
@@ -97,8 +106,11 @@ namespace Orchard.Core.Routable.Drivers {
originalSlug, part.Slug, part.ContentItem.ContentType));
}
if (part.ContentItem.Id != 0 && model.PromoteToHomePage && _routableHomePageProvider != null) {
CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);
}
return Editor(part);
}
}
}

View File

@@ -12,6 +12,7 @@ namespace Orchard.Core.Routable.Services {
[UsedImplicitly]
public class RoutableHomePageProvider : IHomePageProvider {
private readonly IContentManager _contentManager;
public const string Name = "RoutableHomePageProvider";
public RoutableHomePageProvider(IOrchardServices services, IContentManager contentManager) {
_contentManager = contentManager;
@@ -23,7 +24,11 @@ namespace Orchard.Core.Routable.Services {
public Localizer T { get; set; }
public string GetProviderName() {
return "RoutableHomePageProvider";
return Name;
}
public string GetSettingValue(int id) {
return GetProviderName() + ";" + id;
}
public ActionResult GetHomePage(int itemId) {

View File

@@ -11,6 +11,7 @@ namespace Orchard.Core.Routable.ViewModels {
public string Title { get; set; }
public string Slug { get; set; }
public int? ContainerId { get; set; }
public bool PromoteToHomePage { get; set; }
public string DisplayLeadingPath { get; set; }
}

View File

@@ -9,9 +9,9 @@
<fieldset class="permalink">
<label class="sub" for="Slug"><%: T("Permalink")%><br /><span><%: Request.ToRootUrlString()%>/<%: Model.DisplayLeadingPath %></span></label>
<span><%: Html.TextBoxFor(m => m.Slug, new { @class = "text" })%></span>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="<%:ViewData.TemplateInfo.GetFullHtmlFieldId("PromoteToHomePage") %>" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset>
<% using (this.Capture("end-of-page-scripts")) { %>
<script type="text/javascript">
$(function(){
@@ -27,4 +27,4 @@
})
})
})</script>
<% } %>
<% } %>

View File

@@ -4,9 +4,11 @@ using JetBrains.Annotations;
using Orchard.Blogs.Drivers;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.Routing;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Localization;
using Orchard.Mvc.Results;
using Orchard.Settings;
@@ -18,16 +20,26 @@ namespace Orchard.Blogs.Controllers {
public class BlogAdminController : Controller, IUpdateModel {
private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService;
private readonly IContentManager _contentManager;
private readonly ITransactionManager _transactionManager;
private readonly IBlogSlugConstraint _blogSlugConstraint;
public BlogAdminController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService) {
public BlogAdminController(IOrchardServices services,
IBlogService blogService,
IBlogPostService blogPostService,
IContentManager contentManager,
ITransactionManager transactionManager,
IBlogSlugConstraint blogSlugConstraint) {
Services = services;
_blogService = blogService;
_blogPostService = blogPostService;
_contentManager = contentManager;
_transactionManager = transactionManager;
_blogSlugConstraint = blogSlugConstraint;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public IOrchardServices Services { get; set; }
public ActionResult Create() {
@@ -47,20 +59,20 @@ namespace Orchard.Blogs.Controllers {
}
[HttpPost]
public ActionResult Create(CreateBlogViewModel model, bool PromoteToHomePage) {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
public ActionResult Create(CreateBlogViewModel model) {
var blog = Services.ContentManager.New<BlogPart>(BlogPartDriver.ContentType.Name);
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
return new HttpUnauthorizedResult();
model.Blog = Services.ContentManager.UpdateEditorModel(Services.ContentManager.New<BlogPart>(BlogPartDriver.ContentType.Name), this);
_blogService.Create(blog);
model.Blog = _contentManager.UpdateEditorModel(blog, this);
_blogSlugConstraint.AddSlug(model.Blog.Item.Slug);
if (!ModelState.IsValid)
if (!ModelState.IsValid) {
_transactionManager.Cancel();
return View(model);
_blogService.Create(model.Blog.Item);
if (PromoteToHomePage)
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
}
return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug));
}
@@ -77,14 +89,14 @@ namespace Orchard.Blogs.Controllers {
var model = new BlogEditViewModel {
Blog = Services.ContentManager.BuildEditorModel(blog),
PromoteToHomePage = CurrentSite.HomePage == "BlogHomePageProvider;" + blog.Id
//PromoteToHomePage = CurrentSite.HomePage == "BlogHomePageProvider;" + blog.Id
};
return View(model);
}
[HttpPost]
public ActionResult Edit(string blogSlug, bool PromoteToHomePage) {
[HttpPost, ActionName("Edit")]
public ActionResult EditPOST(string blogSlug) {
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog")))
return new HttpUnauthorizedResult();
@@ -100,8 +112,8 @@ namespace Orchard.Blogs.Controllers {
if (!ModelState.IsValid)
return View(model);
if (PromoteToHomePage)
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
//if (PromoteToHomePage)
// CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
_blogService.Edit(model.Blog.Item);

View File

@@ -84,7 +84,6 @@
<Compile Include="Routing\IsArchiveConstraint.cs" />
<Compile Include="Routing\BlogSlugConstraint.cs" />
<Compile Include="Routing\BlogSlugConstraintUpdator.cs" />
<Compile Include="Services\BlogHomePageProvider.cs" />
<Compile Include="Services\BlogService.cs" />
<Compile Include="Controllers\BlogController.cs" />
<Compile Include="Models\BlogPart.cs" />

View File

@@ -1,56 +0,0 @@
using System.Linq;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Routing;
using Orchard.Blogs.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Services;
using Orchard.Core.Feeds;
namespace Orchard.Blogs.Services {
[UsedImplicitly]
public class BlogHomePageProvider : IHomePageProvider {
private readonly IBlogService _blogService;
private readonly IBlogSlugConstraint _blogSlugConstraint;
private readonly IFeedManager _feedManager;
public BlogHomePageProvider(IOrchardServices services, IBlogService blogService, IBlogSlugConstraint blogSlugConstraint, IFeedManager feedManager) {
Services = services;
_blogService = blogService;
_blogSlugConstraint = blogSlugConstraint;
_feedManager = feedManager;
}
public IOrchardServices Services { get; private set; }
public string GetProviderName() {
return "BlogHomePageProvider";
}
public ActionResult GetHomePage(int itemId) {
var blog = _blogService.Get().Where(x => x.Id == itemId).FirstOrDefault();
if (blog == null)
return new NotFoundResult();
var correctedSlug = _blogSlugConstraint.FindSlug(blog.Slug);
if (correctedSlug == null)
return new NotFoundResult();
blog = _blogService.Get(correctedSlug);
if (blog == null)
return new NotFoundResult();
var model = new BlogViewModel {
Blog = Services.ContentManager.BuildDisplayModel(blog, "Detail")
};
_feedManager.Register(blog);
return new ViewResult {
ViewName = "~/Modules/Orchard.Blogs/Views/Blog/Item.ascx",
ViewData = new ViewDataDictionary<BlogViewModel>(model)
};
}
}
}

View File

@@ -33,7 +33,6 @@ namespace Orchard.Blogs.Services {
public void Create(BlogPart blogPart) {
_contentManager.Create(blogPart.ContentItem);
_blogSlugConstraint.AddSlug(blogPart.Slug);
}
public void Edit(BlogPart blogPart) {

View File

@@ -4,6 +4,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
public class CreateBlogViewModel : BaseViewModel {
public ContentItemViewModel<BlogPart> Blog { get; set; }
public bool PromoteToHomePage { get; set; }
//public bool PromoteToHomePage { get; set; }
}
}

View File

@@ -1,12 +1,7 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<CreateBlogViewModel>" %>
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<h1><%: Html.TitleForPage(T("Add Blog").ToString()) %></h1>
<h1><%: Html.TitleForPage(T("Create Blog").ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %>
<%: Html.EditorForItem(vm => vm.Blog) %>
<fieldset>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Add") %>" /></fieldset><%
<%: Html.EditorForItem(vm => vm.Blog) %><%
} %>

View File

@@ -3,10 +3,5 @@
<h1><%: Html.TitleForPage(T("Edit Blog").ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %>
<%: Html.EditorForItem(m => m.Blog) %>
<fieldset>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Save") %>" /></fieldset><%
<%: Html.EditorForItem(m => m.Blog) %><%
} %>

View File

@@ -1,6 +1,7 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ContentItemViewModel<BlogPart>>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPart>>" %>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<% Html.AddTitleParts(Model.Item.Name); %>
<% Html.Zone("primary"); %>
<% Html.ZonesAny(); %>
<% Html.ZonesAny(); %>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Add") %>" /></fieldset>

View File

@@ -1,11 +1,17 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypeViewModel>" %>
<%@ Import Namespace="Orchard.Core.Contents.Settings" %>
<div class="summary">
<div class="properties">
<h3><%:Model.DisplayName%></h3>
<p class="pageStatus"><%:Html.ActionLink(T("Create a new {0}", Model.DisplayName).Text, "Create", new {area = "Contents", id = Model.Name}) %></p>
<h3><%:Model.DisplayName%></h3><%
var creatable = Model.Settings.GetModel<ContentTypeSettings>().Creatable;
if (creatable) { %>
<p class="pageStatus"><%:Html.ActionLink(T("Create a new {0}", Model.DisplayName).Text, "Create", new {area = "Contents", id = Model.Name}) %></p><%
} %>
</div>
<div class="related">
<%:Html.ActionLink(T("List Items").ToString(), "List", new {area = "Contents", id = Model.Name})%><%:T(" | ")%>
<div class="related"><%
if (creatable) { %>
<%:Html.ActionLink(T("List Items").ToString(), "List", new {area = "Contents", id = Model.Name})%><%:T(" | ")%><%
} %>
<%:Html.ActionLink(T("Edit").ToString(), "Edit", new {area = "Orchard.ContentTypes", id = Model.Name})%>
</div>
</div>

View File

@@ -176,7 +176,7 @@ namespace Orchard.Setup.Services {
// set site theme
var themeService = environment.Resolve<IThemeService>();
themeService.SetSiteTheme("Classic");
themeService.SetSiteTheme("Contoso");
// add default culture
var cultureManager = environment.Resolve<ICultureManager>();
@@ -196,7 +196,6 @@ namespace Orchard.Setup.Services {
.WithPart("CommentsPart")
.WithPart("TagsPart")
.WithPart("LocalizationPart")
.Creatable()
.Indexed());
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg
.DisplayedAs("Page")

View File

@@ -763,14 +763,15 @@ table .button {
/* Core Modules
----------------------------------------------------------*/
/* Routable */
.permalink input {
.permalink input.text {
background:transparent;
border-color:#EAE9D9;
border-style:dashed;
margin-left:0;
margin-right:2em;
width:350px;
}
.permalink input:focus {
.permalink input.text:focus {
background:#FFF;
border-color:#666d51;
border-style:solid;

View File

@@ -3,6 +3,7 @@
namespace Orchard.Services {
public interface IHomePageProvider : IDependency {
string GetProviderName();
string GetSettingValue(int itemId);
ActionResult GetHomePage(int itemId);
}
}