From 5612e1e0c8e9720012e7bb924ee87ee2c1f23238 Mon Sep 17 00:00:00 2001 From: skewed Date: Wed, 27 Jan 2010 01:38:43 +0000 Subject: [PATCH] Fixing a bug in the client-side routable slugifier to not suggest a new slug for an existing content item. Near term solution that should be a little more smart about knowing if the content item is published and perhaps always offer up the generated slug as an option to clobber the existing (for published pages redirects would need to be put in place to not break the web :P) --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4046000 --- .../Core/Common/Controllers/RoutableController.cs | 9 +++++++-- src/Orchard.Web/Core/Common/Scripts/jquery.slugify.js | 1 + .../Views/EditorTemplates/Parts/Common.Routable.ascx | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Core/Common/Controllers/RoutableController.cs b/src/Orchard.Web/Core/Common/Controllers/RoutableController.cs index b0ec8e2b1..7129698a4 100644 --- a/src/Orchard.Web/Core/Common/Controllers/RoutableController.cs +++ b/src/Orchard.Web/Core/Common/Controllers/RoutableController.cs @@ -13,13 +13,18 @@ namespace Orchard.Core.Common.Controllers { } [HttpPost] - public ActionResult Slugify(string contentType, int? containerId) { + public ActionResult Slugify(string contentType, int? id, int? containerId) { var slug = ""; + ContentItem contentItem = null; if (string.IsNullOrEmpty(contentType)) return Json(slug); - var contentItem = _contentManager.New(contentType); + if (id != null) + contentItem = _contentManager.Get((int) id); + + if (contentItem == null) + contentItem = _contentManager.New(contentType); if (containerId != null) { var containerItem = _contentManager.Get((int)containerId); diff --git a/src/Orchard.Web/Core/Common/Scripts/jquery.slugify.js b/src/Orchard.Web/Core/Common/Scripts/jquery.slugify.js index ac3e01214..070202125 100644 --- a/src/Orchard.Web/Core/Common/Scripts/jquery.slugify.js +++ b/src/Orchard.Web/Core/Common/Scripts/jquery.slugify.js @@ -6,6 +6,7 @@ var args = { "contentType": options.contentType, + "id": options.id, "containerId": options.containerId, __RequestVerificationToken: $("input[name=__RequestVerificationToken]").val() }; diff --git a/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx b/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx index b901e4a8c..5b835f8ed 100644 --- a/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx +++ b/src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts/Common.Routable.ascx @@ -22,7 +22,8 @@ $(this).slugify({ target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"), url:"<%=Url.Slugify() %>", - contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>",<% + contentType:"<%=Model.RoutableAspect.ContentItem.ContentType %>", + id:"<%=Model.RoutableAspect.ContentItem.Id %>",<% var container = Model.RoutableAspect.ContentItem.As().Container; if (container != null) { %> containerId:<%=container.ContentItem.Id %><%