mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
- Making client slug generation (via POST) container aware to aid in unique slug generation
- Changing Slugify URL (from /common/routable/slugify) to /admin/common/routable/slugify --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045745
This commit is contained in:
@@ -1,29 +1,31 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Services;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Common.Controllers {
|
||||
public class RoutableController : Controller, IUpdateModel {
|
||||
private readonly IRoutableService _routableService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public RoutableController(IRoutableService routableService, IContentManager contentManager, IOrchardServices orchardServices) {
|
||||
_routableService = routableService;
|
||||
public RoutableController(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Slugify(FormCollection formCollection, string contentType) {
|
||||
public ActionResult Slugify(string contentType, int? containerId) {
|
||||
var slug = "";
|
||||
|
||||
if (string.IsNullOrEmpty(contentType))
|
||||
return Json(slug);
|
||||
|
||||
var contentItem = _contentManager.New(contentType);
|
||||
|
||||
if (containerId != null) {
|
||||
var containerItem = _contentManager.Get((int)containerId);
|
||||
contentItem.As<ICommonAspect>().Container = containerItem;
|
||||
}
|
||||
|
||||
_contentManager.UpdateEditorModel(contentItem, this);
|
||||
|
||||
return Json(contentItem.As<RoutableAspect>().Slug);
|
||||
|
||||
@@ -11,15 +11,15 @@ namespace Orchard.Core.Common {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs/Slugify",
|
||||
"Admin/Common/Routable/Slugify",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "BlogPost"},
|
||||
{"area", "Common"},
|
||||
{"controller", "Routable"},
|
||||
{"action", "Slugify"}
|
||||
},
|
||||
new RouteValueDictionary(),
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
{"area", "Common"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
var args = {
|
||||
"contentType": options.contentType,
|
||||
"containerId": options.containerId,
|
||||
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
|
||||
};
|
||||
args[$(this).attr("name")] = $(this).val();
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<RoutableEditorViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement.Extenstions"%>
|
||||
<%@ Import Namespace="Orchard.ContentManagement"%>
|
||||
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
|
||||
<%@ Import Namespace="Orchard.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<% Html.RegisterFootScript("jquery.slugify.js"); %>
|
||||
@@ -16,8 +19,12 @@
|
||||
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
||||
$(this).slugify({
|
||||
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 %>"
|
||||
url:"<%=Url.Slugify() %>",
|
||||
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>",<%
|
||||
var container = Model.RoutableAspect.ContentItem.As<ICommonAspect>().Container;
|
||||
if (container != null) { %>
|
||||
containerId:<%=container.ContentItem.Id %><%
|
||||
} %>
|
||||
})
|
||||
})
|
||||
})</script>
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Publish(string blogSlug, string postSlug) {
|
||||
if (!_services.Authorizer.Authorize(Permissions.PublishPost, T("Couldn't publish blog post")))
|
||||
if (!_services.Authorizer.Authorize(Permissions.PublishBlogPost, T("Couldn't publish blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
<Compile Include="Controllers\BlogPostDriver.cs" />
|
||||
<Compile Include="Controllers\FeedExtensions.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="Filters\ArchivesFilter.cs" />
|
||||
<Compile Include="Models\ArchiveData.cs" />
|
||||
|
||||
@@ -21,20 +21,6 @@ namespace Orchard.Blogs {
|
||||
|
||||
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs/Slugify",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "BlogPost"},
|
||||
{"action", "Slugify"}
|
||||
},
|
||||
new RouteValueDictionary(),
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs/Create",
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\PageController.cs" />
|
||||
<Compile Include="Controllers\PageDriver.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Models\Page.cs" />
|
||||
<Compile Include="Models\PageHandler.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.ContentManagement.Extenstions {
|
||||
public static class UrlHelperExtensions {
|
||||
public static string Slugify(this UrlHelper urlHelper) {
|
||||
return urlHelper.Action("Slugify", "Routable", new { area = "Common" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ContentManagement\Aspects\ICommonAspect.cs" />
|
||||
<Compile Include="ContentManagement\Extenstions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\ContentContextBase.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\PublishContentContext.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs" />
|
||||
|
||||
Reference in New Issue
Block a user