Getting some editing for fields hooked up

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-06-22 15:30:15 -07:00
parent 70e12c2ff8
commit 99cd97e080
15 changed files with 108 additions and 42 deletions

View File

@@ -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
)
);

View File

@@ -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) {

View File

@@ -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<EditPartFieldViewModel> Fields { get; set; }
public IEnumerable<EditTypePartViewModel> Parts { get; set; }
private IEnumerable<EditPartFieldViewModel> GetTypeFields(ContentTypeDefinition contentTypeDefinition) {
var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == Name);
return implicitTypePart == null
? Enumerable.Empty<EditPartFieldViewModel>()
: implicitTypePart.PartDefinition.Fields.Select(f => new EditPartFieldViewModel(f));
}
private IEnumerable<EditTypePartViewModel> 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; }

View File

@@ -4,15 +4,15 @@ Html.RegisterStyle("admin.css"); %>
<h1><%:Html.TitleForPage(T("Edit Part").ToString())%></h1><%
using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %>
<%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%>
<fieldset>
<label for="Name"><%:T("Name") %></label>
<%--<%: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"}) %>
</fieldset>
<%:Html.EditorFor(m => m.Settings, "Settings", "")%>
<h2><%:T("Fields") %></h2>
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddField", new { }, new { @class = "button" })%></div>
<%--<%:Html.EditorFor(m => m.Fields, "ContentTypeFields")%>--%>
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
<fieldset>
<button class="primaryAction" type="submit"><%:T("Save") %></button>
</fieldset><%

View File

@@ -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--%>
<label for="Name"><%:T("Name") %></label>
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium", disabled = "disabled"}) %>
<%:Html.HiddenFor(m => m.Name) %>
</fieldset>
<%:Html.EditorFor(m => m.Settings) %>
<h2><%:T("Parts") %></h2>
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPart", new { }, new { @class = "button" })%></div>
<%:Html.EditorFor(m => m.Parts, "Type.Parts", "") %>
<%:Html.EditorFor(m => m.Parts, "Parts", "") %>
<h2><%:T("Fields") %></h2>
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddField", new { }, new { @class = "button" })%></div>
<%--<%:Html.EditorFor(m => m.Fields, "ContentTypeFields")%>--%>
<%:Html.EditorFor(m => m.Fields, "Fields", "")%>
<fieldset>
<button class="primaryAction" type="submit"><%:T("Save") %></button>
</fieldset><%

View File

@@ -2,7 +2,7 @@
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
<h1><%:Html.TitleForPage(T("Content Types").ToString())%></h1>
<div class="manage"><%: Html.ActionLink(T("Create new type").ToString(), "CreateType", null, new { @class = "button primaryAction" })%></div>
<%=Html.UnorderedList(
<%:Html.UnorderedList(
Model.Types,
(t,i) => Html.DisplayFor(m => t),
"contentItems"

View File

@@ -1,4 +1,5 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentManagement.MetaData.Models.ContentTypeDefinition>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentTypeDefinition>" %>
<%@ Import namespace="Orchard.ContentManagement.MetaData.Models" %>
<div class="summary">
<div class="properties">
<h3><%:Model.DisplayName%></h3>

View File

@@ -0,0 +1,18 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<EditPartFieldViewModel>" %>
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
<fieldset>
<h3><%:Model.Name %></h3>
<h4><%:Model.FieldDefinition.Name %></h4>
<div class="manage add-to-type">
<%--// 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 = "" }) %>
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
<% } %> --%>
</div>
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
<%:Html.HiddenFor(m => m.Name) %>
<%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
</fieldset>

View File

@@ -0,0 +1,12 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<EditPartFieldViewModel>>" %>
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
if (Model.Any()) { %>
<fieldset><%
var fi = 0;
foreach (var field in Model) {
var f = field;
var htmlFieldName = string.Format("Fields[{0}]", fi++); %>
<%:Html.EditorFor(m => f, "Field", htmlFieldName) %><%
} %>
</fieldset><%
} %>

View File

@@ -4,7 +4,7 @@ if (Model.Any()) { %>
<fieldset><%
foreach (var field in Model) {
var f = field; %>
<%:Html.EditorFor(m => f, "FieldOnPart") %><%
<%:Html.EditorFor(m => f, "Part.Fields") %><%
} %>
</fieldset><%
} %>

View File

@@ -17,6 +17,6 @@
<div class="manage"><%:Html.ActionLink(T("Edit part settings").Text, "EditPart", new { area = "Contents", id = Model.PartDefinition.Name }) %></div>
<%: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) %>
</fieldset>

View File

@@ -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) %><%
} %>
</fieldset><%
} %>

View File

@@ -2,7 +2,7 @@
<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %><%
if (Model.Any()) { %>
<fieldset>
<legend><%:T("Settings for this content type") %></legend><%
<legend><%:T("[Settings]") %></legend><%
var si = 0;
foreach (var setting in Model) {
var s = setting;

View File

@@ -63,18 +63,13 @@
<ItemGroup>
<Compile Include="Common\Drivers\BodyDriver.cs" />
<Compile Include="Common\Drivers\CommonDriver.cs" />
<Compile Include="Common\Drivers\ItemReferenceContentFieldDriver.cs" />
<Compile Include="Common\Drivers\RoutableDriver.cs" />
<Compile Include="Common\Controllers\RoutableController.cs" />
<Compile Include="Common\Drivers\TextContentFieldDriver.cs" />
<Compile Include="Common\Fields\ItemReferenceContentField.cs" />
<Compile Include="Common\Fields\TextContentField.cs" />
<Compile Include="Common\Handlers\ItemReferenceContentFieldHandler.cs" />
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
<Compile Include="Common\Handlers\TextContentFieldHandler.cs" />
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
<Compile Include="Common\ViewModels\ItemReferenceContentFieldDisplayModel.cs" />
<Compile Include="Common\ViewModels\ItemReferenceContentFieldEditorViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
<Compile Include="Contents\Controllers\ItemController.cs" />
@@ -208,11 +203,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="Common\Module.txt" />
<Content Include="Common\Views\DisplayTemplates\Fields\Common.ItemReferenceContentField.ascx" />
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.ItemReferenceContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
<Content Include="Contents\Module.txt" />
<Content Include="Contents\Styles\admin.css" />
<Content Include="Contents\Views\Admin\EditPart.ascx" />
@@ -226,11 +219,13 @@
<Content Include="Contents\Views\DisplayTemplates\ContentTypeDefinition.ascx" />
<Content Include="Contents\Views\DisplayTemplates\Items\Contents.Item.ascx" />
<Content Include="Contents\Views\DisplayTemplates\Settings.ascx" />
<Content Include="Contents\Views\EditorTemplates\Field.ascx" />
<Content Include="Contents\Views\EditorTemplates\Fields.ascx" />
<Content Include="Contents\Views\EditorTemplates\Settings.ascx" />
<Content Include="Contents\Views\EditorTemplates\FieldsOnPart.ascx" />
<Content Include="Contents\Views\EditorTemplates\FieldOnPart.ascx" />
<Content Include="Contents\Views\EditorTemplates\Type.Parts.ascx" />
<Content Include="Contents\Views\EditorTemplates\Type.Part.ascx" />
<Content Include="Contents\Views\EditorTemplates\Part.Fields.ascx" />
<Content Include="Contents\Views\EditorTemplates\Part.Field.ascx" />
<Content Include="Contents\Views\EditorTemplates\Parts.ascx" />
<Content Include="Contents\Views\EditorTemplates\Part.ascx" />
<Content Include="Contents\Views\EditorTemplates\Items\Contents.Item.ascx" />
<Content Include="Contents\Views\Item\Preview.aspx" />
<Content Include="Contents\Views\Item\Display.aspx" />