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) {
|
||||
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" />
|
||||
|
@@ -34,19 +34,19 @@ namespace Orchard.Blogs.Controllers {
|
||||
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
|
||||
if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
Blog blog = _blogService.Get(blogSlug);
|
||||
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var blogPost = _services.ContentManager.BuildEditorModel(_services.ContentManager.New<BlogPost>("blogpost"));
|
||||
blogPost.Item.Blog = blog;
|
||||
|
||||
var blogPost = _services.ContentManager.New<BlogPost>("blogpost");
|
||||
blogPost.Blog = blog;
|
||||
|
||||
var model = new CreateBlogPostViewModel {
|
||||
BlogPost = blogPost
|
||||
};
|
||||
BlogPost = _services.ContentManager.BuildEditorModel(blogPost)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
//todo: (heskew) need better messages
|
||||
_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;
|
||||
//todo: (heskew) make auto-uniqueness optional
|
||||
post.Slug = _routableService.GenerateUniqueSlug(post.Slug, slugsLikeThis);
|
||||
|
@@ -22,7 +22,7 @@ namespace Orchard.Blogs.Models {
|
||||
OnRemoved<BlogPost>((context, bp) => bp.Blog.PostCount--);
|
||||
|
||||
OnRemoved<Blog>(
|
||||
(context, bp) =>
|
||||
(context, b) =>
|
||||
blogPostService.Get(context.ContentItem.As<Blog>()).ToList().ForEach(
|
||||
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\ExtensionFolders.cs" />
|
||||
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
||||
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
||||
<Compile Include="ContentManagement\ContentItem.cs" />
|
||||
|
Reference in New Issue
Block a user