diff --git a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs index c2756d441..305ca0a7c 100644 --- a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs @@ -136,6 +136,55 @@ namespace Orchard.Core.Contents.Controllers { return RedirectToAction("Index"); } + public ActionResult EditPart(string id) { + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + return new HttpUnauthorizedResult(); + + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + + if (contentPartDefinition == null) + return new NotFoundResult(); + + return View(new EditPartViewModel(contentPartDefinition)); + } + + [HttpPost, ActionName("EditPart")] + public ActionResult EditPartPOST(string id) { + if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) + return new HttpUnauthorizedResult(); + + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + + if (contentPartDefinition == null) + return new NotFoundResult(); + + var viewModel = new EditPartViewModel(); + TryUpdateModel(viewModel); + + if (!ModelState.IsValid) { + return EditPart(id); + } + + //todo: apply the changes along the lines of but definately not resembling + // for now this _might_ just get a little messy -> + _contentDefinitionService.AlterPartDefinition( + new ContentPartDefinition( + viewModel.Name, + viewModel.Fields.Select( + f => new ContentPartDefinition.Field( + new ContentFieldDefinition(f.FieldDefinition.Name), + f.Name, + f.Settings + ) + ), + viewModel.Settings + ) + ); + // little == lot + + return RedirectToAction("Index"); + } + #endregion #region Content diff --git a/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs b/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs index 16052287d..e1a5b40dd 100644 --- a/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs @@ -55,6 +55,22 @@ namespace Orchard.Core.Contents.Services { throw new NotImplementedException(); } + public ContentPartDefinition GetPartDefinition(string name) { + return _contentDefinitionManager.GetPartDefinition(name); + } + + public void AddPartDefinition(ContentPartDefinition contentPartDefinition) { + throw new NotImplementedException(); + } + + public void AlterPartDefinition(ContentPartDefinition contentPartDefinition) { + _contentDefinitionManager.StorePartDefinition(contentPartDefinition); + } + + public void RemovePartDefinition(string name) { + throw new NotImplementedException(); + } + //gratuitously stolen from the RoutableService private static string GenerateTypeName(string displayName) { if (string.IsNullOrWhiteSpace(displayName)) diff --git a/src/Orchard.Web/Core/Contents/Services/IContentDefinitionService.cs b/src/Orchard.Web/Core/Contents/Services/IContentDefinitionService.cs index 157e53f3a..8840ee23c 100644 --- a/src/Orchard.Web/Core/Contents/Services/IContentDefinitionService.cs +++ b/src/Orchard.Web/Core/Contents/Services/IContentDefinitionService.cs @@ -8,5 +8,10 @@ namespace Orchard.Core.Contents.Services { void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition); void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition); void RemoveTypeDefinition(string name); + + ContentPartDefinition GetPartDefinition(string name); + void AddPartDefinition(ContentPartDefinition contentPartDefinition); + void AlterPartDefinition(ContentPartDefinition contentPartDefinition); + void RemovePartDefinition(string name); } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs index b43cc113b..c8b5413ce 100644 --- a/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs @@ -35,7 +35,7 @@ namespace Orchard.Core.Contents.ViewModels { public SettingsDictionary Settings { get; set; } } - public class EditPartViewModel { + public class EditPartViewModel : BaseViewModel { public EditPartViewModel() { Fields = new List(); Settings = new SettingsDictionary(); diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx new file mode 100644 index 000000000..4ec4efcf3 --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx @@ -0,0 +1,19 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><% +Html.RegisterStyle("admin.css"); %> +

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

<% +using (Html.BeginFormAntiForgeryPost()) { %> + <%:Html.ValidationSummary() %> + <%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%> +
+ + <%--<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>--%> +
+ <%:Html.EditorFor(m => m.Settings, "Settings", "")%> +

<%:T("Fields") %>

+
<%: Html.ActionLink(T("Add").Text, "AddField", new { }, new { @class = "button" })%>
+ <%--<%:Html.EditorFor(m => m.Fields, "ContentTypeFields")%>--%> +
+ +
<% +} %> diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx index ffce68bcf..530787ca5 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx +++ b/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx @@ -7,13 +7,14 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium"}) %> + <%--// has unintended consequences (renamging the type) - changing the name creates a new type of that name--%> <%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>
<%:Html.EditorFor(m => m.Settings) %>

<%:T("Parts") %>

<%: Html.ActionLink(T("Add").Text, "AddPart", new { }, new { @class = "button" })%>
- <%:Html.EditorFor(m => m.Parts, "Parts", "") %> + <%:Html.EditorFor(m => m.Parts, "Type.Parts", "") %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddField", new { }, new { @class = "button" })%>
<%--<%:Html.EditorFor(m => m.Fields, "ContentTypeFields")%>--%> diff --git a/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/Settings.ascx b/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/Settings.ascx new file mode 100644 index 000000000..24d4536cd --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/Settings.ascx @@ -0,0 +1,8 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %> +
<% + foreach (var setting in Model) { %> +
<%:setting.Key %>
+
<%:setting.Value %>
<% + } %> +
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx index 75432c61a..0aba302a7 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx @@ -1,6 +1,8 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %><% if (Model.Any()) { %> -
<% +
+ <%:T("Settings for this content type") %><% var si = 0; foreach (var setting in Model) { var s = setting; diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx similarity index 72% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx index b282d485e..2da7a4363 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx @@ -11,11 +11,12 @@ <% } %> --%> - <%-- - what is this settings for? - <%:Html.EditorFor(m => m.PartDefinition.Settings, "Settings") %>--%> - <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <%:Html.EditorFor(m => m.Settings, "Settings", "") %><% + if (Model.PartDefinition.Settings.Any()) { %> +

<%:T("Tenant-wide settings") %>

+
<%:Html.ActionLink(T("Edit part settings").Text, "EditPart", new { area = "Contents", id = Model.PartDefinition.Name }) %>
+ <%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition") %><% + } %> <%:Html.EditorFor(m => m.PartDefinition.Fields, "FieldsOnPart") %> <%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %> - <%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Parts.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.ascx similarity index 82% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/Parts.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.ascx index 13d0904af..9c39fd426 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Parts.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.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, "Type.Part", htmlFieldName) %><% } %>
<% } %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 4b986156e..8e68cca3c 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -215,6 +215,7 @@ + @@ -224,11 +225,12 @@ + - - + +