diff --git a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs index 305ca0a7c..ef872853b 100644 --- a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs @@ -106,28 +106,48 @@ namespace Orchard.Core.Contents.Controllers { return EditType(id); } + var contentTypeDefinitionParts = viewModel.Parts.Select( + p => new ContentTypeDefinition.Part( + new ContentPartDefinition( + p.PartDefinition.Name, + p.PartDefinition.Fields.Select( + f => new ContentPartDefinition.Field( + new ContentFieldDefinition(f.FieldDefinition.Name), + f.Name, + f.Settings + ) + ), + p.PartDefinition.Settings + ), + p.Settings + ) + ).ToList(); + + if (viewModel.Fields.Any()) { + var implicitContentTypeDefinitionPart = new ContentTypeDefinition.Part( + new ContentPartDefinition( + viewModel.Name, + viewModel.Fields.Select( + f => new ContentPartDefinition.Field( + new ContentFieldDefinition(f.FieldDefinition.Name), + f.Name, + f.Settings + ) + ), + null + ), + null + ); + contentTypeDefinitionParts.Add(implicitContentTypeDefinitionPart); + } + //todo: apply the changes along the lines of but definately not resembling // for now this _might_ just get a little messy -> _contentDefinitionService.AlterTypeDefinition( new ContentTypeDefinition( viewModel.Name, viewModel.DisplayName, - viewModel.Parts.Select( - p => new ContentTypeDefinition.Part( - new ContentPartDefinition( - p.PartDefinition.Name, - p.PartDefinition.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - p.PartDefinition.Settings - ), - p.Settings - ) - ), + contentTypeDefinitionParts, viewModel.Settings ) ); diff --git a/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs b/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs index e1a5b40dd..b0a78fe48 100644 --- a/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Core/Contents/Services/ContentDefinitionService.cs @@ -49,6 +49,11 @@ namespace Orchard.Core.Contents.Services { public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) { _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition); + + var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == contentTypeDefinition.Name); + if (implicitTypePart != null) { + AlterPartDefinition(implicitTypePart.PartDefinition); + } } public void RemoveTypeDefinition(string name) { diff --git a/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs index c8b5413ce..20bbb4772 100644 --- a/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Core/Contents/ViewModels/EditTypeViewModel.cs @@ -13,13 +13,27 @@ namespace Orchard.Core.Contents.ViewModels { Name = contentTypeDefinition.Name; DisplayName = contentTypeDefinition.DisplayName; Settings = contentTypeDefinition.Settings; - Parts = contentTypeDefinition.Parts.Select(p => new EditTypePartViewModel(p)); + Fields = GetTypeFields(contentTypeDefinition); + Parts = GetTypeParts(contentTypeDefinition); } public string Name { get; set; } public string DisplayName { get; set; } public SettingsDictionary Settings { get; set; } + public IEnumerable Fields { get; set; } public IEnumerable Parts { get; set; } + + private IEnumerable GetTypeFields(ContentTypeDefinition contentTypeDefinition) { + var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == Name); + + return implicitTypePart == null + ? Enumerable.Empty() + : implicitTypePart.PartDefinition.Fields.Select(f => new EditPartFieldViewModel(f)); + } + + private IEnumerable GetTypeParts(ContentTypeDefinition contentTypeDefinition) { + return contentTypeDefinition.Parts.Where(p => p.PartDefinition.Name != Name).Select(p => new EditTypePartViewModel(p)); + } } public class EditTypePartViewModel { @@ -69,7 +83,7 @@ namespace Orchard.Core.Contents.ViewModels { public class EditFieldViewModel { public EditFieldViewModel() { } public EditFieldViewModel(ContentFieldDefinition contentFieldDefinition) { - Name = Name; + Name = contentFieldDefinition.Name; } public string Name { get; set; } diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx index 4ec4efcf3..78589bdc0 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx +++ b/src/Orchard.Web/Core/Contents/Views/Admin/EditPart.ascx @@ -4,15 +4,15 @@ 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"}) %>--%> + <%--// 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")%>--%> + <%:Html.EditorFor(m => m.Fields, "Fields", "") %>
<% diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx index 530787ca5..86c390021 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx +++ b/src/Orchard.Web/Core/Contents/Views/Admin/EditType.ascx @@ -9,15 +9,16 @@ 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.TextBoxFor(m => m.Name, new {@class = "textMedium", disabled = "disabled"}) %> + <%:Html.HiddenFor(m => m.Name) %> <%:Html.EditorFor(m => m.Settings) %>

<%:T("Parts") %>

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

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddField", new { }, new { @class = "button" })%>
- <%--<%:Html.EditorFor(m => m.Fields, "ContentTypeFields")%>--%> + <%:Html.EditorFor(m => m.Fields, "Fields", "")%>
<% diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/Types.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/Types.ascx index 027fa19ee..c6fe6cc60 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/Types.ascx +++ b/src/Orchard.Web/Core/Contents/Views/Admin/Types.ascx @@ -2,7 +2,7 @@ <%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>

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

<%: Html.ActionLink(T("Create new type").ToString(), "CreateType", null, new { @class = "button primaryAction" })%>
-<%=Html.UnorderedList( +<%:Html.UnorderedList( Model.Types, (t,i) => Html.DisplayFor(m => t), "contentItems" diff --git a/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/ContentTypeDefinition.ascx b/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/ContentTypeDefinition.ascx index 7e6b634ae..15dfd2ca4 100644 --- a/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/ContentTypeDefinition.ascx +++ b/src/Orchard.Web/Core/Contents/Views/DisplayTemplates/ContentTypeDefinition.ascx @@ -1,4 +1,5 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import namespace="Orchard.ContentManagement.MetaData.Models" %>

<%:Model.DisplayName%>

diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Field.ascx new file mode 100644 index 000000000..522d9ee91 --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Field.ascx @@ -0,0 +1,18 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %> +
+

<%:Model.Name %>

+

<%:Model.FieldDefinition.Name %>

+
+ <%--// these inline forms can't be here. should probably have some JavaScript in here to build up the forms and add the "remove" link. + // get the antiforgery token from the edit type form and mark up the part in a semantic way so I can get some info from the DOM --%> + <%:Html.Link("[remove]", "#forshowonlyandnotintendedtowork!") %> +<%-- <% using (Html.BeginFormAntiForgeryPost(Url.Action("RemovePart", new { area = "Contents" }), FormMethod.Post, new {@class = "inline link"})) { %> + <%:Html.Hidden("name", Model.PartDefinition.Name, new { id = "" }) %> + + <% } %> --%> +
+ <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <%:Html.HiddenFor(m => m.Name) %> + <%:Html.HiddenFor(m => m.FieldDefinition.Name) %> +
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Fields.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Fields.ascx new file mode 100644 index 000000000..c22a4f3bb --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Fields.ascx @@ -0,0 +1,12 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><% +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, "Field", htmlFieldName) %><% + } %> +
<% +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/FieldOnPart.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.Field.ascx similarity index 100% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/FieldOnPart.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.Field.ascx diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/FieldsOnPart.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.Fields.ascx similarity index 82% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/FieldsOnPart.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.Fields.ascx index 8b45f2edc..131951c4f 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/FieldsOnPart.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.Fields.ascx @@ -4,7 +4,7 @@ if (Model.Any()) { %>
<% foreach (var field in Model) { var f = field; %> - <%:Html.EditorFor(m => f, "FieldOnPart") %><% + <%:Html.EditorFor(m => f, "Part.Fields") %><% } %>
<% } %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx similarity index 93% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx index 2da7a4363..7a8587215 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Part.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Part.ascx @@ -17,6 +17,6 @@
<%: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.EditorFor(m => m.PartDefinition.Fields, "Part.Fields") %> <%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.ascx b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Parts.ascx similarity index 82% rename from src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.ascx rename to src/Orchard.Web/Core/Contents/Views/EditorTemplates/Parts.ascx index 9c39fd426..13d0904af 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Type.Parts.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/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, "Type.Part", htmlFieldName) %><% + <%:Html.EditorFor(m => p, "Part", htmlFieldName) %><% } %> <% } %> \ 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 0aba302a7..240add0b6 100644 --- a/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx +++ b/src/Orchard.Web/Core/Contents/Views/EditorTemplates/Settings.ascx @@ -2,7 +2,7 @@ <%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %><% if (Model.Any()) { %>
- <%:T("Settings for this content type") %><% + <%:T("[Settings]") %><% var si = 0; foreach (var setting in Model) { var s = setting; diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 8e68cca3c..566bc1913 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -63,18 +63,13 @@ - - - - - @@ -208,11 +203,9 @@ - - - + @@ -226,11 +219,13 @@ + + - - - - + + + +