diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 087d62988..29c7cb4b0 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -283,7 +283,7 @@ namespace Orchard.ContentTypes.Controllers { #region Parts public ActionResult EditPart(string id) { - if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) return new HttpUnauthorizedResult(); var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); @@ -300,7 +300,7 @@ namespace Orchard.ContentTypes.Controllers { [HttpPost, ActionName("EditPart")] public ActionResult EditPartPOST(EditPartViewModel viewModel) { - if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) return new HttpUnauthorizedResult(); var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name); @@ -323,7 +323,7 @@ namespace Orchard.ContentTypes.Controllers { } public ActionResult AddFieldTo(string id) { - if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) return new HttpUnauthorizedResult(); var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); @@ -347,7 +347,7 @@ namespace Orchard.ContentTypes.Controllers { [HttpPost, ActionName("AddFieldTo")] public ActionResult AddFieldToPOST(string id) { - if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) return new HttpUnauthorizedResult(); var viewModel = new AddFieldViewModel(); @@ -391,6 +391,50 @@ namespace Orchard.ContentTypes.Controllers { return RedirectToAction("EditPart", new { id }); } + + public ActionResult RemoveFieldFrom(string id) { + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) + return new HttpUnauthorizedResult(); + + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + + var viewModel = new RemoveFieldViewModel(); + if (contentPartDefinition == null + || !TryUpdateModel(viewModel) + || !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name)) + return new NotFoundResult(); + + viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name }; + return View(viewModel); + } + + [HttpPost, ActionName("RemoveFieldFrom")] + public ActionResult RemoveFieldFromPOST(string id) { + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) + return new HttpUnauthorizedResult(); + + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + + var viewModel = new RemoveFieldViewModel(); + if (contentPartDefinition == null + || !TryUpdateModel(viewModel) + || !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name)) + return new NotFoundResult(); + + if (!ModelState.IsValid) { + viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name }; + return View(viewModel); + } + + _contentDefinitionManager.AlterPartDefinition(id, typeBuilder => typeBuilder.RemoveField(viewModel.Name)); + Services.Notifier.Information(T("The \"{0}\" field has been removed.", viewModel.Name)); + + if (_contentDefinitionService.GetTypeDefinition(id) != null) + return RedirectToAction("Edit", new { id }); + + return RedirectToAction("EditPart", new { id }); + } + #endregion class Updater : IUpdateModel { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index 02c48efba..1d05c5039 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -77,6 +77,7 @@ + @@ -88,6 +89,7 @@ + @@ -97,10 +99,12 @@ + + - - + + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css b/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css index ba113a16e..45f1a6104 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css @@ -1,13 +1,24 @@ -.contents #main h2 { - margin:1.5em 0 .5em; +.orchard-contenttypes #main h2 { + margin:1.5em 0 0; } .manage.add-to-type { - margin-top:-4em; + margin-top:-3.1em; } +.manage-part { + margin-bottom:2em; +} .manage-part h3, .manage-field h3 { border-bottom:1px solid #EAEAEA; + padding-top:0; +} +.manage-part h3, +.manage-field h3, +.manage-part .manage-field, +.manage-field fieldset, +.manage-part .settings { + padding-left:20px; } .manage-part .manage, .manage-field .manage { @@ -15,12 +26,27 @@ margin-top:-2.4em; } .manage-part .manage.minor { - margin-top:-1.7em; + margin:0 0 -1.2em; } .manage-part label, .manage-field label { font-weight:normal; } +.manage-part fieldset { + margin:1.5em 0 0; + padding:0; +} +.manage-field .settings { + margin:-1.5em 0 0 1em; + padding-left:0; +} +.manage-part .settings fieldset { + padding-left:0; +} + +fieldset.action { + margin-top:2em; +} /* should pull this back into the base admin theme css, w/out the .manage-part of course */ .manage-part dl { @@ -28,8 +54,16 @@ overflow:auto; padding:6px 0 0; } -.manage-part dt { - font-weight:bold; +.manage-part dt, +.manage-part dd { + display:inline; +} +.manage-part dt::after { + content:":"; +} +.manage-part dd { + font-style:italic; + padding-left:.5em; } .manage-part dl dl { font-size:1em; diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/RemoveFieldViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/RemoveFieldViewModel.cs new file mode 100644 index 000000000..08ba7a1fd --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/RemoveFieldViewModel.cs @@ -0,0 +1,8 @@ +using Orchard.Mvc.ViewModels; + +namespace Orchard.ContentTypes.ViewModels { + public class RemoveFieldViewModel : BaseViewModel { + public string Name { get; set; } + public EditPartViewModel Part { get; set; } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx index f9cd5f5f2..96458cbdc 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx @@ -3,7 +3,7 @@ %>

<%:Html.TitleForPage(T("Edit Content Type").ToString())%>

<% using (Html.BeginFormAntiForgeryPost()) { %> - <%--//todo: come up with real itemtype definitions and locations for said definitions--%> + <%--// todo: come up with real itemtype definitions and locations for said definitions--%>
<%:Html.ValidationSummary() %>
@@ -19,11 +19,11 @@ using (Html.BeginFormAntiForgeryPost()) { %> Html.RenderTemplates(Model.Templates); %>

<%:T("Parts") %>

<%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%>
<%: - Html.EditorFor(m => m.Parts, "Parts", "") %> + Html.EditorFor(m => m.Parts, "TypeParts", "") %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %>
<%: Html.EditorFor(m => m.Fields, "Fields", "") %> -
+
<% diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx index c79f8fc14..070df8709 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx @@ -1,7 +1,8 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> <% Html.RegisterStyle("admin.css"); %> -

<%:Html.TitleForPage(T("Edit Part").ToString()) %>

<% +

<%:Html.TitleForPage(T("Edit Part").ToString()) %>

+<% using (Html.BeginFormAntiForgeryPost()) { %> <%:Html.ValidationSummary() %>
@@ -13,7 +14,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %>
<%:Html.EditorFor(m => m.Fields, "Fields", "") %> -
+
<% } %> diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx new file mode 100644 index 000000000..1ca02dc09 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/RemoveFieldFrom.ascx @@ -0,0 +1,11 @@ +<%@ 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())%>

<% +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.") %>

+
+ <%=Html.HiddenFor(m => m.Name) %> + +
<% +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Settings.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Settings.ascx index 47687cbe1..a539ce5b1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Settings.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Settings.ascx @@ -2,7 +2,7 @@ <%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %> <% if (Model.Any()) { %> -
<% +
<% foreach (var setting in Model) { %>
<%:setting.Key %>
<%:setting.Value %>
<% diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx index d59fbfc65..ddfe0a09e 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx @@ -2,7 +2,7 @@

<%:Model.Name %> (<%:Model.FieldDefinition.Name %>)

- <%:Html.Link("[remove]", "#forshowonlyandnotintendedtowork!") %> + <%:Html.ActionLink(T("Remove").Text, "RemoveFieldFrom", new { area = "Orchard.ContentTypes", id = Model.Part.Name, Model.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
<% Html.RenderTemplates(Model.Templates); %> <%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %> diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx similarity index 68% rename from src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx rename to src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx index 6743e1adf..d2382be7d 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx @@ -4,10 +4,13 @@
<%:Html.ActionLink(T("Remove").Text, "RemovePartFrom", new { area = "Orchard.ContentTypes", id = Model.Type.Name, Model.PartDefinition.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
<% + if (Model.Templates.Any()) { %> +
<% Html.RenderTemplates(Model.Templates); %> -

<%:T("Global configuration") %>

-
<%:Html.ActionLink(T("Edit").Text, "EditPart", new { area = "Orchard.ContentTypes", id = Model.PartDefinition.Name }) %>
+
<% + } %> +
<%:Html.ActionLink(T("Edit global part config").Text, "EditPart", new { area = "Orchard.ContentTypes", id = Model.PartDefinition.Name })%>
<%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition") - %><%:Html.EditorFor(m => m.PartDefinition.Fields, "Fields", "PartDefinition") + %><%:Html.EditorFor(m => m.PartDefinition.Fields, "TypePartFields", "PartDefinition") %><%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx new file mode 100644 index 000000000..f7f933c7d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx @@ -0,0 +1,10 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +
+

<%:Model.Name %> (<%:Model.FieldDefinition.Name %>)

<% + if (Model.Templates.Any()) { %> +
<% + Html.RenderTemplates(Model.Templates); %> +
<% + } %> + <%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %> +
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx new file mode 100644 index 000000000..5c270aa45 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx @@ -0,0 +1,10 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<% +if (Model.Any()) { + var fi = 0; + foreach (var field in Model) { + var f = field; + var htmlFieldName = string.Format("Fields[{0}]", fi++); %> + <%:Html.EditorFor(m => f, "TypePartField", htmlFieldName) %><% + } +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx similarity index 82% rename from src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx rename to src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx index 8f6e4b0ff..cc41743b0 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx @@ -6,7 +6,7 @@ if (Model.Any()) { %> foreach (var part in Model) { var p = part; var htmlFieldName = string.Format("Parts[{0}]", pi++); %> - <%:Html.EditorFor(m => p, "Part", htmlFieldName) %><% + <%:Html.EditorFor(m => p, "TypePart", htmlFieldName) %><% } %>
<% } %> \ No newline at end of file