mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 12:09:41 +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) {
|
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");
|
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "before.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(RoutableAspect part, IUpdateModel updater) {
|
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);
|
updater.TryUpdateModel(model, Prefix, null, null);
|
||||||
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "before.5");
|
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "before.5");
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@ using Orchard.ContentManagement;
|
|||||||
|
|
||||||
namespace Orchard.Core.Common.Models {
|
namespace Orchard.Core.Common.Models {
|
||||||
public class RoutableAspect : ContentPart<RoutableRecord> {
|
public class RoutableAspect : ContentPart<RoutableRecord> {
|
||||||
|
public string ContainerPath { get; set; }
|
||||||
|
|
||||||
public string Title {
|
public string Title {
|
||||||
get { return Record.Title; }
|
get { return Record.Title; }
|
||||||
set { Record.Title = value; }
|
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 {
|
namespace Orchard.Core.Common.ViewModels {
|
||||||
public class RoutableEditorViewModel {
|
public class RoutableEditorViewModel {
|
||||||
|
public string Prefix { get; set; }
|
||||||
public RoutableAspect RoutableAspect { get; set; }
|
public RoutableAspect RoutableAspect { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<RoutableEditorViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<RoutableEditorViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Extensions"%>
|
||||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||||
<% Html.RegisterFootScript("jquery.slugify.js"); %>
|
<% Html.RegisterFootScript("jquery.slugify.js"); %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@@ -6,15 +7,15 @@
|
|||||||
<%=Html.TextBoxFor(m => m.Title, new { @class = "large text" }) %>
|
<%=Html.TextBoxFor(m => m.Title, new { @class = "large text" }) %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="permalink">
|
<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>
|
<span><%=Html.TextBoxFor(m => m.Slug, new { @class = "text" })%></span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% using (this.Capture("end-of-page-scripts")) { %>
|
<% using (this.Capture("end-of-page-scripts")) { %>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){
|
$(function(){
|
||||||
$("input#Routable_Title").blur(function(){
|
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
||||||
$(this).slugify({
|
$(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"}) %>",
|
url:"<%=Url.Action("Slugify", "Routable", new {area = "Common"}) %>",
|
||||||
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>"
|
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>"
|
||||||
})
|
})
|
||||||
|
@@ -64,6 +64,7 @@
|
|||||||
<Compile Include="Common\Controllers\BodyDriver.cs" />
|
<Compile Include="Common\Controllers\BodyDriver.cs" />
|
||||||
<Compile Include="Common\Controllers\RoutableDriver.cs" />
|
<Compile Include="Common\Controllers\RoutableDriver.cs" />
|
||||||
<Compile Include="Common\Controllers\RoutableController.cs" />
|
<Compile Include="Common\Controllers\RoutableController.cs" />
|
||||||
|
<Compile Include="Common\Models\RoutableAspectHandler.cs" />
|
||||||
<Compile Include="Common\Permissions.cs" />
|
<Compile Include="Common\Permissions.cs" />
|
||||||
<Compile Include="Common\Records\CommonVersionRecord.cs" />
|
<Compile Include="Common\Records\CommonVersionRecord.cs" />
|
||||||
<Compile Include="Common\Routes.cs" />
|
<Compile Include="Common\Routes.cs" />
|
||||||
|
@@ -41,12 +41,12 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (blog == null)
|
if (blog == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var blogPost = _services.ContentManager.BuildEditorModel(_services.ContentManager.New<BlogPost>("blogpost"));
|
var blogPost = _services.ContentManager.New<BlogPost>("blogpost");
|
||||||
blogPost.Item.Blog = blog;
|
blogPost.Blog = blog;
|
||||||
|
|
||||||
var model = new CreateBlogPostViewModel {
|
var model = new CreateBlogPostViewModel {
|
||||||
BlogPost = blogPost
|
BlogPost = _services.ContentManager.BuildEditorModel(blogPost)
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
//todo: (heskew) need better messages
|
//todo: (heskew) need better messages
|
||||||
_orchardServices.Notifier.Warning(T("A different blog post is already published with this same slug."));
|
_orchardServices.Notifier.Warning(T("A different blog post is already published with this same slug."));
|
||||||
|
|
||||||
if (post.ContentItem.VersionRecord.Published) {
|
if (post.ContentItem.VersionRecord == null || post.ContentItem.VersionRecord.Published) {
|
||||||
var originalSlug = post.Slug;
|
var originalSlug = post.Slug;
|
||||||
//todo: (heskew) make auto-uniqueness optional
|
//todo: (heskew) make auto-uniqueness optional
|
||||||
post.Slug = _routableService.GenerateUniqueSlug(post.Slug, slugsLikeThis);
|
post.Slug = _routableService.GenerateUniqueSlug(post.Slug, slugsLikeThis);
|
||||||
|
@@ -22,7 +22,7 @@ namespace Orchard.Blogs.Models {
|
|||||||
OnRemoved<BlogPost>((context, bp) => bp.Blog.PostCount--);
|
OnRemoved<BlogPost>((context, bp) => bp.Blog.PostCount--);
|
||||||
|
|
||||||
OnRemoved<Blog>(
|
OnRemoved<Blog>(
|
||||||
(context, bp) =>
|
(context, b) =>
|
||||||
blogPostService.Get(context.ContentItem.As<Blog>()).ToList().ForEach(
|
blogPostService.Get(context.ContentItem.As<Blog>()).ToList().ForEach(
|
||||||
blogPost => context.ContentManager.Remove(blogPost.ContentItem)));
|
blogPost => context.ContentManager.Remove(blogPost.ContentItem)));
|
||||||
}
|
}
|
||||||
|
9
src/Orchard/Extensions/UriExtensions.cs
Normal file
9
src/Orchard/Extensions/UriExtensions.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Orchard.Extensions {
|
||||||
|
public static class UriExtensions {
|
||||||
|
public static string ToRootString(this Uri uri) {
|
||||||
|
return string.Format("{0}://{1}{2}", uri.Scheme, uri.Host, uri.Port != 80 ? ":" + uri.Port : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -134,6 +134,7 @@
|
|||||||
<Compile Include="Extensions\AreaFolders.cs" />
|
<Compile Include="Extensions\AreaFolders.cs" />
|
||||||
<Compile Include="Extensions\ExtensionFolders.cs" />
|
<Compile Include="Extensions\ExtensionFolders.cs" />
|
||||||
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||||
|
<Compile Include="Extensions\UriExtensions.cs" />
|
||||||
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
||||||
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
||||||
<Compile Include="ContentManagement\ContentItem.cs" />
|
<Compile Include="ContentManagement\ContentItem.cs" />
|
||||||
|
Reference in New Issue
Block a user