mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 18:27:55 +08:00
Beginning of the "add field" UI for parts
--HG-- branch : dev
This commit is contained in:
@@ -102,29 +102,46 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
var viewModel = new EditTypeViewModel();
|
||||
TryUpdateModel(viewModel);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
if (!ModelState.IsValid)
|
||||
return EditType(id);
|
||||
|
||||
var contentTypeDefinitionParts = viewModel.Parts.Select(GenerateTypePart).ToList();
|
||||
if (viewModel.Fields.Any())
|
||||
contentTypeDefinitionParts.Add(GenerateTypePart(viewModel));
|
||||
|
||||
//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,
|
||||
contentTypeDefinitionParts,
|
||||
viewModel.Settings
|
||||
)
|
||||
);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var contentTypeDefinitionParts = viewModel.Parts.Select(
|
||||
p => new ContentTypeDefinition.Part(
|
||||
private static ContentTypeDefinition.Part GenerateTypePart(EditTypePartViewModel viewModel) {
|
||||
return new ContentTypeDefinition.Part(
|
||||
new ContentPartDefinition(
|
||||
p.PartDefinition.Name,
|
||||
p.PartDefinition.Fields.Select(
|
||||
viewModel.PartDefinition.Name,
|
||||
viewModel.PartDefinition.Fields.Select(
|
||||
f => new ContentPartDefinition.Field(
|
||||
new ContentFieldDefinition(f.FieldDefinition.Name),
|
||||
f.Name,
|
||||
f.Settings
|
||||
)
|
||||
),
|
||||
p.PartDefinition.Settings
|
||||
viewModel.PartDefinition.Settings
|
||||
),
|
||||
p.Settings
|
||||
)
|
||||
).ToList();
|
||||
viewModel.Settings
|
||||
);
|
||||
}
|
||||
|
||||
if (viewModel.Fields.Any()) {
|
||||
var implicitContentTypeDefinitionPart = new ContentTypeDefinition.Part(
|
||||
private static ContentTypeDefinition.Part GenerateTypePart(EditTypeViewModel viewModel) {
|
||||
return new ContentTypeDefinition.Part(
|
||||
new ContentPartDefinition(
|
||||
viewModel.Name,
|
||||
viewModel.Fields.Select(
|
||||
@@ -138,23 +155,11 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
),
|
||||
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,
|
||||
contentTypeDefinitionParts,
|
||||
viewModel.Settings
|
||||
)
|
||||
);
|
||||
// little == lot
|
||||
#endregion
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
#region Parts
|
||||
|
||||
public ActionResult EditPart(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part.")))
|
||||
@@ -187,8 +192,50 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
|
||||
//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(
|
||||
_contentDefinitionService.AlterPartDefinition(GeneratePart(viewModel));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult AddFieldTo(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) {
|
||||
//id passed in might be that of a type w/ no implicit field
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
if (contentTypeDefinition != null)
|
||||
contentPartDefinition = new ContentPartDefinition(id);
|
||||
else
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
||||
//get all of the field types
|
||||
|
||||
|
||||
var viewModel = new AddFieldViewModel(contentPartDefinition);
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("AddFieldTo")]
|
||||
public ActionResult AddFieldToPOST(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
|
||||
if (contentTypeDefinition != null)
|
||||
return RedirectToAction("EditType", new { id });
|
||||
|
||||
return RedirectToAction("EditPart", new {id});
|
||||
}
|
||||
|
||||
private static ContentPartDefinition GeneratePart(EditPartViewModel viewModel) {
|
||||
return new ContentPartDefinition(
|
||||
viewModel.Name,
|
||||
viewModel.Fields.Select(
|
||||
f => new ContentPartDefinition.Field(
|
||||
@@ -198,19 +245,13 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
)
|
||||
),
|
||||
viewModel.Settings
|
||||
)
|
||||
);
|
||||
// little == lot
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Content
|
||||
|
||||
#endregion
|
||||
|
||||
public ActionResult List(ListContentsViewModel model) {
|
||||
const int pageSize = 20;
|
||||
var skip = (Math.Max(model.Page ?? 0, 1) - 1) * pageSize;
|
||||
@@ -328,5 +369,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
||||
ModelState.AddModelError(key, errorMessage.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Contents.ViewModels {
|
||||
public class AddFieldViewModel : BaseViewModel {
|
||||
public AddFieldViewModel(ContentPartDefinition part) {
|
||||
Part = part;
|
||||
}
|
||||
|
||||
public ContentPartDefinition Part { get; private set; }
|
||||
}
|
||||
}
|
10
src/Orchard.Web/Core/Contents/Views/Admin/AddFieldTo.ascx
Normal file
10
src/Orchard.Web/Core/Contents/Views/Admin/AddFieldTo.ascx
Normal file
@@ -0,0 +1,10 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<AddFieldViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Add a new field to {0}", Model.Part.Name).ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -11,7 +11,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
</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>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Contents", id = Model.Name }, new { @class = "button" }) %></div>
|
||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<EditTypeViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Edit Content Type").ToString())%></h1><%
|
||||
<h1><%:Html.TitleForPage(T("Edit Content Type").ToString())%></h1>
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" > ") %><%:T("Edit Content Type") %></p><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
@@ -17,7 +18,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPart", new { }, new { @class = "button" }) %></div>
|
||||
<%: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>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Contents", id = Model.Name }, new { @class = "button" }) %></div>
|
||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
|
@@ -11,12 +11,10 @@
|
||||
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
||||
<% } %> --%>
|
||||
</div>
|
||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %><%
|
||||
if (Model.PartDefinition.Settings.Any() || Model.PartDefinition.Fields.Any()) { %>
|
||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
||||
<h4><%:T("Global configuration") %></h4>
|
||||
<div class="manage minor"><%:Html.ActionLink(T("Edit").Text, "EditPart", new { area = "Contents", id = Model.PartDefinition.Name }) %></div>
|
||||
<%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition") %>
|
||||
<%:Html.EditorFor(m => m.PartDefinition.Fields, "Part.Fields") %><%
|
||||
} %>
|
||||
<%:Html.EditorFor(m => m.PartDefinition.Fields, "Part.Fields") %>
|
||||
<%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
|
||||
</fieldset>
|
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Contents\Permissions.cs" />
|
||||
<Compile Include="Contents\Services\ContentDefinitionService.cs" />
|
||||
<Compile Include="Contents\Services\IContentDefinitionService.cs" />
|
||||
<Compile Include="Contents\ViewModels\AddFieldViewModel.cs" />
|
||||
<Compile Include="Contents\ViewModels\EditTypeViewModel.cs" />
|
||||
<Compile Include="Contents\ViewModels\CreateTypeViewModel.cs" />
|
||||
<Compile Include="Contents\ViewModels\ListContentsViewModel.cs" />
|
||||
@@ -208,6 +209,7 @@
|
||||
<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\AddFieldTo.ascx" />
|
||||
<Content Include="Contents\Views\Admin\EditPart.ascx" />
|
||||
<Content Include="Contents\Views\Admin\EditType.ascx" />
|
||||
<Content Include="Contents\Views\Admin\CreateType.ascx" />
|
||||
|
Reference in New Issue
Block a user