diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 547bd0093..f9a721ec0 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -114,7 +114,7 @@ namespace Orchard.ContentTypes.Controllers { Type = typeViewModel, PartSelections = _contentDefinitionService.GetParts() .Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name)) - .Select(cpd => new PartSelectionViewModel { PartName = cpd.Name }) + .Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName }) }; return View(viewModel); @@ -131,10 +131,8 @@ namespace Orchard.ContentTypes.Controllers { return new NotFoundResult(); var viewModel = new AddPartsViewModel(); - if (!TryUpdateModel(viewModel)) { - viewModel.Type = typeViewModel; - return View(viewModel); - } + if (!TryUpdateModel(viewModel)) + return AddPartsTo(id); var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName); foreach (var partToAdd in partsToAdd) { @@ -144,8 +142,7 @@ namespace Orchard.ContentTypes.Controllers { if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); ; - viewModel.Type = typeViewModel; - return View(viewModel); + return AddPartsTo(id); } return RedirectToAction("Edit", new {id}); diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Extensions/StringExtensions.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Extensions/StringExtensions.cs new file mode 100644 index 000000000..e5880afb7 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Extensions/StringExtensions.cs @@ -0,0 +1,22 @@ +using System.Linq; +using System.Text.RegularExpressions; + +namespace Orchard.ContentTypes.Extensions { + public static class StrinExtensions { + private static readonly Regex humps = new Regex("[A-Z][^A-Z]*"); + public static string CamelFriendly(this string camel) { + return camel != null + ? humps.Matches(camel).OfType().Select(m => m.Value).Aggregate((a, b) => a + " " + b).TrimStart(' ') + : null; + } + + public static string TrimEnd(this string rough, string trim = "") { + if (rough == null) + return null; + + return rough.EndsWith(trim) + ? rough.Substring(0, rough.Length - 4) + : rough; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index 7f8f7b6e6..c712b3cad 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -70,6 +70,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index c92fdf363..3304d4dac 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -6,6 +6,7 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentTypes.Extensions; using Orchard.ContentTypes.ViewModels; using Orchard.Core.Contents.Extensions; using Orchard.Core.Contents.Settings; @@ -149,7 +150,8 @@ namespace Orchard.ContentTypes.Services { public IEnumerable GetParts() { var typeNames = GetTypes().Select(ctd => ctd.Name); // code-defined parts - var codeDefinedParts = _contentPartDrivers.SelectMany(d => d.GetPartInfo().Select(cpi => new EditPartViewModel {Name = cpi.PartName})); + var codeDefinedParts = _contentPartDrivers + .SelectMany(d => d.GetPartInfo().Select(cpi => new EditPartViewModel { Name = cpi.PartName })); // user-defined parts var contentParts = _contentDefinitionManager.ListPartDefinitions().Where(cpd => !codeDefinedParts.Any(m => m.Name == cpd.Name)).Select(cpd => new EditPartViewModel(cpd)); // all together now, except for those parts with the same name as a type (implicit type's part or a mistake) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/AddPartsViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/AddPartsViewModel.cs index cf4e4e945..91d1b7e03 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/AddPartsViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/AddPartsViewModel.cs @@ -13,6 +13,7 @@ namespace Orchard.ContentTypes.ViewModels { public class PartSelectionViewModel { public string PartName { get; set; } + public string PartDisplayName { get; set; } public bool IsSelected { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index dd465633f..28e548d61 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -2,6 +2,7 @@ using System.Linq; using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.ViewModels; +using Orchard.ContentTypes.Extensions; using Orchard.Mvc.ViewModels; namespace Orchard.ContentTypes.ViewModels { @@ -80,6 +81,11 @@ namespace Orchard.ContentTypes.ViewModels { public string Prefix { get { return "PartDefinition"; } } public string Name { get; set; } + private string _displayName; + public string DisplayName { + get { return !string.IsNullOrWhiteSpace(_displayName) ? _displayName : Name.TrimEnd("Part").CamelFriendly(); } + set { _displayName = value; } + } public IEnumerable Templates { get; set; } public IEnumerable Fields { get; set; } public SettingsDictionary Settings { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddFieldTo.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddFieldTo.ascx index 8436c27fd..3e0bfa40a 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddFieldTo.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddFieldTo.ascx @@ -1,7 +1,7 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> <% Html.RegisterStyle("admin.css"); %> -

<%:Html.TitleForPage(T("Add a new field to \"{0}\"", Model.Part.Name).ToString())%>

<% +

<%:Html.TitleForPage(T("Add a new field to \"{0}\"", Model.Part.DisplayName).ToString())%>

<% using (Html.BeginFormAntiForgeryPost()) { %> <%:Html.ValidationSummary() %>
diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx index b9055c5fd..66f3ce05b 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx @@ -14,7 +14,7 @@ using (Html.BeginFormAntiForgeryPost()) { %> "{0} {3}", Html.CheckBox(fieldNameStart + "IsSelected"), ViewData.TemplateInfo.GetFullHtmlFieldId(fieldNameStart + "IsSelected"), - partSelection.PartName, + partSelection.PartDisplayName, Html.Hidden(fieldNameStart + "PartName", partSelection.PartName))); }, "available-parts")%> diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx index 1ca02dc09..681d08142 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx @@ -1,7 +1,7 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> <% Html.RegisterStyle("admin.css"); %> -

<%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Part.Name).ToString())%>

<% +

<%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Part.DisplayName).ToString())%>

<% using (Html.BeginFormAntiForgeryPost()) { %>

<%:T("Looks like you couldn't use the fancy way to remove the field. Try hitting the button below to force the issue.") %>

diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx index 5cb9a042e..963d97b01 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx @@ -1,9 +1,9 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
-

<%:Model.Name%>

+

<%:Model.DisplayName %>

\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx index a92a2f547..b73de83f4 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx @@ -1,6 +1,6 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
-

<%:Model.PartDefinition.Name %>

+

<%:Model.PartDefinition.DisplayName %>

<%:Html.ActionLink(T("Remove").Text, "RemovePartFrom", new { area = "Orchard.ContentTypes", id = Model.Type.Name, Model.PartDefinition.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
<%