Adding "set as homepage" functionality to the RoutePart

- Orchard.Pages was already gone and Orchard.Blogs is now gone (made redundant and less functional in a way)

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-07-23 14:30:22 -07:00
parent 877d49779e
commit 2077ab964b
14 changed files with 64 additions and 99 deletions

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>
<% } %>
<% } %>