From 5285b24733bff920a5e53fec4ee0a4ff4e61d731 Mon Sep 17 00:00:00 2001 From: skewed Date: Wed, 20 Jan 2010 09:26:33 +0000 Subject: [PATCH] - Adding the RoutableAspect editor template's permalink slug prefix display based on container slugs - Got the rest of the hard coded prefix usage out of the RoutableAspect's editor template --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045731 --- .../Core/Common/Controllers/RoutableDriver.cs | 4 +-- .../Core/Common/Models/RoutableAspect.cs | 2 ++ .../Common/Models/RoutableAspectHandler.cs | 26 +++++++++++++++++++ .../ViewModels/RoutableEditorViewModel.cs | 1 + .../Parts/Common.Routable.ascx | 7 ++--- src/Orchard.Web/Core/Orchard.Core.csproj | 1 + .../Controllers/BlogPostAdminController.cs | 12 ++++----- .../Controllers/BlogPostDriver.cs | 2 +- .../Orchard.Blogs/Models/BlogPostHandler.cs | 2 +- src/Orchard/Extensions/UriExtensions.cs | 9 +++++++ src/Orchard/Orchard.csproj | 1 + 11 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs create mode 100644 src/Orchard/Extensions/UriExtensions.cs diff --git a/src/Orchard.Web/Core/Common/Controllers/RoutableDriver.cs b/src/Orchard.Web/Core/Common/Controllers/RoutableDriver.cs index 9c2066b64..b5ae8ef03 100644 --- a/src/Orchard.Web/Core/Common/Controllers/RoutableDriver.cs +++ b/src/Orchard.Web/Core/Common/Controllers/RoutableDriver.cs @@ -12,12 +12,12 @@ namespace Orchard.Core.Common.Controllers { } protected override DriverResult Editor(RoutableAspect part) { - var model = new RoutableEditorViewModel {RoutableAspect = part}; + var model = new RoutableEditorViewModel { Prefix = Prefix, RoutableAspect = part }; return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "before.5"); } protected override DriverResult Editor(RoutableAspect part, IUpdateModel updater) { - var model = new RoutableEditorViewModel {RoutableAspect = part}; + var model = new RoutableEditorViewModel { Prefix = Prefix, RoutableAspect = part }; updater.TryUpdateModel(model, Prefix, null, null); return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "before.5"); } diff --git a/src/Orchard.Web/Core/Common/Models/RoutableAspect.cs b/src/Orchard.Web/Core/Common/Models/RoutableAspect.cs index 6a67c90b5..07a459030 100644 --- a/src/Orchard.Web/Core/Common/Models/RoutableAspect.cs +++ b/src/Orchard.Web/Core/Common/Models/RoutableAspect.cs @@ -3,6 +3,8 @@ using Orchard.ContentManagement; namespace Orchard.Core.Common.Models { public class RoutableAspect : ContentPart { + public string ContainerPath { get; set; } + public string Title { get { return Record.Title; } set { Record.Title = value; } diff --git a/src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs b/src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs new file mode 100644 index 000000000..07dd5f081 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs @@ -0,0 +1,26 @@ +using System.Text; +using JetBrains.Annotations; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; +using Orchard.ContentManagement.Handlers; + +namespace Orchard.Core.Common.Models { + [UsedImplicitly] + public class RoutableAspectHandler : ContentHandler + { + public RoutableAspectHandler() { + OnGetEditorViewModel((context, routable) => { + var containerPathBuilder = new StringBuilder(); + var container = context.ContentItem.As().Container; + + while (container != null) { + if (container.Is()) + containerPathBuilder.Insert(0, string.Format("{0}/", container.As().Slug)); + container = container.ContentItem.As().Container; + } + + routable.ContainerPath = containerPathBuilder.ToString(); + }); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Common/ViewModels/RoutableEditorViewModel.cs b/src/Orchard.Web/Core/Common/ViewModels/RoutableEditorViewModel.cs index ed8e5c635..970caa58d 100644 --- a/src/Orchard.Web/Core/Common/ViewModels/RoutableEditorViewModel.cs +++ b/src/Orchard.Web/Core/Common/ViewModels/RoutableEditorViewModel.cs @@ -3,6 +3,7 @@ using Orchard.Core.Common.Models; namespace Orchard.Core.Common.ViewModels { public class RoutableEditorViewModel { + public string Prefix { get; set; } public RoutableAspect RoutableAspect { get; set; } [Required] diff --git a/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx b/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx index 5e1b4899a..e9c2502cb 100644 --- a/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx +++ b/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx @@ -1,4 +1,5 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Extensions"%> <%@ Import Namespace="Orchard.Core.Common.ViewModels"%> <% Html.RegisterFootScript("jquery.slugify.js"); %>
@@ -6,15 +7,15 @@ <%=Html.TextBoxFor(m => m.Title, new { @class = "large text" }) %>
<% using (this.Capture("end-of-page-scripts")) { %>