- 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
This commit is contained in:
skewed
2010-01-20 09:26:33 +00:00
parent 1ae1770b0d
commit 5285b24733
11 changed files with 54 additions and 13 deletions

View File

@@ -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");
}

View File

@@ -3,6 +3,8 @@ using Orchard.ContentManagement;
namespace Orchard.Core.Common.Models {
public class RoutableAspect : ContentPart<RoutableRecord> {
public string ContainerPath { get; set; }
public string Title {
get { return Record.Title; }
set { Record.Title = value; }

View File

@@ -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<RoutableAspect>((context, routable) => {
var containerPathBuilder = new StringBuilder();
var container = context.ContentItem.As<ICommonAspect>().Container;
while (container != null) {
if (container.Is<RoutableAspect>())
containerPathBuilder.Insert(0, string.Format("{0}/", container.As<RoutableAspect>().Slug));
container = container.ContentItem.As<ICommonAspect>().Container;
}
routable.ContainerPath = containerPathBuilder.ToString();
});
}
}
}

View File

@@ -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]

View File

@@ -1,4 +1,5 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<RoutableEditorViewModel>" %>
<%@ Import Namespace="Orchard.Extensions"%>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<% Html.RegisterFootScript("jquery.slugify.js"); %>
<fieldset>
@@ -6,15 +7,15 @@
<%=Html.TextBoxFor(m => m.Title, new { @class = "large text" }) %>
</fieldset>
<fieldset class="permalink">
<label class="sub" for="Slug"><%=_Encoded("Permalink")%><br /><span>[todo: (heskew) need path to here]/</span></label>
<label class="sub" for="Slug"><%=_Encoded("Permalink")%><br /><span><%=Html.Encode(Request.Url.ToRootString()) %>/<%=Html.Encode(Model.RoutableAspect.ContainerPath) %></span></label>
<span><%=Html.TextBoxFor(m => m.Slug, new { @class = "text" })%></span>
</fieldset>
<% using (this.Capture("end-of-page-scripts")) { %>
<script type="text/javascript">
$(function(){
$("input#Routable_Title").blur(function(){
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
$(this).slugify({
target:$("input#Routable_Slug"),
target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"),
url:"<%=Url.Action("Slugify", "Routable", new {area = "Common"}) %>",
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>"
})

View File

@@ -64,6 +64,7 @@
<Compile Include="Common\Controllers\BodyDriver.cs" />
<Compile Include="Common\Controllers\RoutableDriver.cs" />
<Compile Include="Common\Controllers\RoutableController.cs" />
<Compile Include="Common\Models\RoutableAspectHandler.cs" />
<Compile Include="Common\Permissions.cs" />
<Compile Include="Common\Records\CommonVersionRecord.cs" />
<Compile Include="Common\Routes.cs" />