mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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 System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Common.Services;
|
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Controllers {
|
namespace Orchard.Core.Common.Controllers {
|
||||||
public class RoutableController : Controller, IUpdateModel {
|
public class RoutableController : Controller, IUpdateModel {
|
||||||
private readonly IRoutableService _routableService;
|
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly IOrchardServices _orchardServices;
|
|
||||||
|
|
||||||
public RoutableController(IRoutableService routableService, IContentManager contentManager, IOrchardServices orchardServices) {
|
public RoutableController(IContentManager contentManager) {
|
||||||
_routableService = routableService;
|
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_orchardServices = orchardServices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Slugify(FormCollection formCollection, string contentType) {
|
public ActionResult Slugify(string contentType, int? containerId) {
|
||||||
var slug = "";
|
var slug = "";
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(contentType))
|
if (string.IsNullOrEmpty(contentType))
|
||||||
return Json(slug);
|
return Json(slug);
|
||||||
|
|
||||||
var contentItem = _contentManager.New(contentType);
|
var contentItem = _contentManager.New(contentType);
|
||||||
|
|
||||||
|
if (containerId != null) {
|
||||||
|
var containerItem = _contentManager.Get((int)containerId);
|
||||||
|
contentItem.As<ICommonAspect>().Container = containerItem;
|
||||||
|
}
|
||||||
|
|
||||||
_contentManager.UpdateEditorModel(contentItem, this);
|
_contentManager.UpdateEditorModel(contentItem, this);
|
||||||
|
|
||||||
return Json(contentItem.As<RoutableAspect>().Slug);
|
return Json(contentItem.As<RoutableAspect>().Slug);
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ namespace Orchard.Core.Common {
|
|||||||
return new[] {
|
return new[] {
|
||||||
new RouteDescriptor {
|
new RouteDescriptor {
|
||||||
Route = new Route(
|
Route = new Route(
|
||||||
"Admin/Blogs/Slugify",
|
"Admin/Common/Routable/Slugify",
|
||||||
new RouteValueDictionary {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"},
|
{"area", "Common"},
|
||||||
{"controller", "BlogPost"},
|
{"controller", "Routable"},
|
||||||
{"action", "Slugify"}
|
{"action", "Slugify"}
|
||||||
},
|
},
|
||||||
new RouteValueDictionary(),
|
new RouteValueDictionary(),
|
||||||
new RouteValueDictionary {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"}
|
{"area", "Common"}
|
||||||
},
|
},
|
||||||
new MvcRouteHandler())
|
new MvcRouteHandler())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
var args = {
|
var args = {
|
||||||
"contentType": options.contentType,
|
"contentType": options.contentType,
|
||||||
|
"containerId": options.containerId,
|
||||||
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
|
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
|
||||||
};
|
};
|
||||||
args[$(this).attr("name")] = $(this).val();
|
args[$(this).attr("name")] = $(this).val();
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<RoutableEditorViewModel>" %>
|
<%@ 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.Extensions"%>
|
||||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||||
<% Html.RegisterFootScript("jquery.slugify.js"); %>
|
<% Html.RegisterFootScript("jquery.slugify.js"); %>
|
||||||
@@ -16,8 +19,12 @@
|
|||||||
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
||||||
$(this).slugify({
|
$(this).slugify({
|
||||||
target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"),
|
target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"),
|
||||||
url:"<%=Url.Action("Slugify", "Routable", new {area = "Common"}) %>",
|
url:"<%=Url.Slugify() %>",
|
||||||
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>"
|
contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>",<%
|
||||||
|
var container = Model.RoutableAspect.ContentItem.As<ICommonAspect>().Container;
|
||||||
|
if (container != null) { %>
|
||||||
|
containerId:<%=container.ContentItem.Id %><%
|
||||||
|
} %>
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})</script>
|
})</script>
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Publish(string blogSlug, string postSlug) {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||||
|
|||||||
@@ -81,7 +81,6 @@
|
|||||||
<Compile Include="Controllers\BlogPostDriver.cs" />
|
<Compile Include="Controllers\BlogPostDriver.cs" />
|
||||||
<Compile Include="Controllers\FeedExtensions.cs" />
|
<Compile Include="Controllers\FeedExtensions.cs" />
|
||||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||||
<Compile Include="Extensions\UriExtensions.cs" />
|
|
||||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||||
<Compile Include="Filters\ArchivesFilter.cs" />
|
<Compile Include="Filters\ArchivesFilter.cs" />
|
||||||
<Compile Include="Models\ArchiveData.cs" />
|
<Compile Include="Models\ArchiveData.cs" />
|
||||||
|
|||||||
@@ -21,20 +21,6 @@ namespace Orchard.Blogs {
|
|||||||
|
|
||||||
public IEnumerable<RouteDescriptor> GetRoutes() {
|
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||||
return new[] {
|
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 {
|
new RouteDescriptor {
|
||||||
Route = new Route(
|
Route = new Route(
|
||||||
"Admin/Blogs/Create",
|
"Admin/Blogs/Create",
|
||||||
|
|||||||
@@ -77,7 +77,6 @@
|
|||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Controllers\PageController.cs" />
|
<Compile Include="Controllers\PageController.cs" />
|
||||||
<Compile Include="Controllers\PageDriver.cs" />
|
<Compile Include="Controllers\PageDriver.cs" />
|
||||||
<Compile Include="Extensions\UriExtensions.cs" />
|
|
||||||
<Compile Include="Models\Page.cs" />
|
<Compile Include="Models\Page.cs" />
|
||||||
<Compile Include="Models\PageHandler.cs" />
|
<Compile Include="Models\PageHandler.cs" />
|
||||||
<Compile Include="Permissions.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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ContentManagement\Aspects\ICommonAspect.cs" />
|
<Compile Include="ContentManagement\Aspects\ICommonAspect.cs" />
|
||||||
|
<Compile Include="ContentManagement\Extenstions\UrlHelperExtensions.cs" />
|
||||||
<Compile Include="ContentManagement\Handlers\ContentContextBase.cs" />
|
<Compile Include="ContentManagement\Handlers\ContentContextBase.cs" />
|
||||||
<Compile Include="ContentManagement\Handlers\PublishContentContext.cs" />
|
<Compile Include="ContentManagement\Handlers\PublishContentContext.cs" />
|
||||||
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs" />
|
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user