mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
- 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:
@@ -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");
|
||||
}
|
||||
|
@@ -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; }
|
||||
|
26
src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs
Normal file
26
src/Orchard.Web/Core/Common/Models/RoutableAspectHandler.cs
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -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]
|
||||
|
@@ -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 %>"
|
||||
})
|
||||
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user