mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 02:37: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();
|
var viewModel = new EditTypeViewModel();
|
||||||
TryUpdateModel(viewModel);
|
TryUpdateModel(viewModel);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid)
|
||||||
return EditType(id);
|
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(
|
private static ContentTypeDefinition.Part GenerateTypePart(EditTypePartViewModel viewModel) {
|
||||||
p => new ContentTypeDefinition.Part(
|
return new ContentTypeDefinition.Part(
|
||||||
new ContentPartDefinition(
|
new ContentPartDefinition(
|
||||||
p.PartDefinition.Name,
|
viewModel.PartDefinition.Name,
|
||||||
p.PartDefinition.Fields.Select(
|
viewModel.PartDefinition.Fields.Select(
|
||||||
f => new ContentPartDefinition.Field(
|
f => new ContentPartDefinition.Field(
|
||||||
new ContentFieldDefinition(f.FieldDefinition.Name),
|
new ContentFieldDefinition(f.FieldDefinition.Name),
|
||||||
f.Name,
|
f.Name,
|
||||||
f.Settings
|
f.Settings
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
p.PartDefinition.Settings
|
viewModel.PartDefinition.Settings
|
||||||
),
|
),
|
||||||
p.Settings
|
viewModel.Settings
|
||||||
)
|
);
|
||||||
).ToList();
|
}
|
||||||
|
|
||||||
if (viewModel.Fields.Any()) {
|
private static ContentTypeDefinition.Part GenerateTypePart(EditTypeViewModel viewModel) {
|
||||||
var implicitContentTypeDefinitionPart = new ContentTypeDefinition.Part(
|
return new ContentTypeDefinition.Part(
|
||||||
new ContentPartDefinition(
|
new ContentPartDefinition(
|
||||||
viewModel.Name,
|
viewModel.Name,
|
||||||
viewModel.Fields.Select(
|
viewModel.Fields.Select(
|
||||||
@@ -138,23 +155,11 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
),
|
),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
contentTypeDefinitionParts.Add(implicitContentTypeDefinitionPart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: apply the changes along the lines of but definately not resembling
|
#endregion
|
||||||
// for now this _might_ just get a little messy ->
|
|
||||||
_contentDefinitionService.AlterTypeDefinition(
|
|
||||||
new ContentTypeDefinition(
|
|
||||||
viewModel.Name,
|
|
||||||
viewModel.DisplayName,
|
|
||||||
contentTypeDefinitionParts,
|
|
||||||
viewModel.Settings
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// little == lot
|
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
#region Parts
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult EditPart(string id) {
|
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 part.")))
|
||||||
@@ -187,8 +192,50 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
|
|
||||||
//todo: apply the changes along the lines of but definately not resembling
|
//todo: apply the changes along the lines of but definately not resembling
|
||||||
// for now this _might_ just get a little messy ->
|
// for now this _might_ just get a little messy ->
|
||||||
_contentDefinitionService.AlterPartDefinition(
|
_contentDefinitionService.AlterPartDefinition(GeneratePart(viewModel));
|
||||||
new ContentPartDefinition(
|
|
||||||
|
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.Name,
|
||||||
viewModel.Fields.Select(
|
viewModel.Fields.Select(
|
||||||
f => new ContentPartDefinition.Field(
|
f => new ContentPartDefinition.Field(
|
||||||
@@ -198,19 +245,13 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
viewModel.Settings
|
viewModel.Settings
|
||||||
)
|
|
||||||
);
|
);
|
||||||
// little == lot
|
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Content
|
#region Content
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public ActionResult List(ListContentsViewModel model) {
|
public ActionResult List(ListContentsViewModel model) {
|
||||||
const int pageSize = 20;
|
const int pageSize = 20;
|
||||||
var skip = (Math.Max(model.Page ?? 0, 1) - 1) * pageSize;
|
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) {
|
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
||||||
ModelState.AddModelError(key, errorMessage.ToString());
|
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>
|
</fieldset>
|
||||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
||||||
<h2><%:T("Fields") %></h2>
|
<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", "") %>
|
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<EditTypeViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<EditTypeViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||||
Html.RegisterStyle("admin.css"); %>
|
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()) { %>
|
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||||
<%:Html.ValidationSummary() %>
|
<%:Html.ValidationSummary() %>
|
||||||
<fieldset>
|
<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>
|
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPart", new { }, new { @class = "button" }) %></div>
|
||||||
<%:Html.EditorFor(m => m.Parts, "Parts", "") %>
|
<%:Html.EditorFor(m => m.Parts, "Parts", "") %>
|
||||||
<h2><%:T("Fields") %></h2>
|
<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", "") %>
|
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||||
|
@@ -11,12 +11,10 @@
|
|||||||
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
||||||
<% } %> --%>
|
<% } %> --%>
|
||||||
</div>
|
</div>
|
||||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %><%
|
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
||||||
if (Model.PartDefinition.Settings.Any() || Model.PartDefinition.Fields.Any()) { %>
|
|
||||||
<h4><%:T("Global configuration") %></h4>
|
<h4><%:T("Global configuration") %></h4>
|
||||||
<div class="manage minor"><%:Html.ActionLink(T("Edit").Text, "EditPart", new { area = "Contents", id = Model.PartDefinition.Name }) %></div>
|
<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.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) %>
|
<%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
|
||||||
</fieldset>
|
</fieldset>
|
@@ -77,6 +77,7 @@
|
|||||||
<Compile Include="Contents\Permissions.cs" />
|
<Compile Include="Contents\Permissions.cs" />
|
||||||
<Compile Include="Contents\Services\ContentDefinitionService.cs" />
|
<Compile Include="Contents\Services\ContentDefinitionService.cs" />
|
||||||
<Compile Include="Contents\Services\IContentDefinitionService.cs" />
|
<Compile Include="Contents\Services\IContentDefinitionService.cs" />
|
||||||
|
<Compile Include="Contents\ViewModels\AddFieldViewModel.cs" />
|
||||||
<Compile Include="Contents\ViewModels\EditTypeViewModel.cs" />
|
<Compile Include="Contents\ViewModels\EditTypeViewModel.cs" />
|
||||||
<Compile Include="Contents\ViewModels\CreateTypeViewModel.cs" />
|
<Compile Include="Contents\ViewModels\CreateTypeViewModel.cs" />
|
||||||
<Compile Include="Contents\ViewModels\ListContentsViewModel.cs" />
|
<Compile Include="Contents\ViewModels\ListContentsViewModel.cs" />
|
||||||
@@ -208,6 +209,7 @@
|
|||||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
|
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
|
||||||
<Content Include="Contents\Module.txt" />
|
<Content Include="Contents\Module.txt" />
|
||||||
<Content Include="Contents\Styles\admin.css" />
|
<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\EditPart.ascx" />
|
||||||
<Content Include="Contents\Views\Admin\EditType.ascx" />
|
<Content Include="Contents\Views\Admin\EditType.ascx" />
|
||||||
<Content Include="Contents\Views\Admin\CreateType.ascx" />
|
<Content Include="Contents\Views\Admin\CreateType.ascx" />
|
||||||
|
Reference in New Issue
Block a user