mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Hooked up field removal from a content part
--HG-- branch : dev
This commit is contained in:
@@ -283,7 +283,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
#region Parts
|
||||
|
||||
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 content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
@@ -300,7 +300,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
|
||||
[HttpPost, ActionName("EditPart")]
|
||||
public ActionResult EditPartPOST(EditPartViewModel viewModel) {
|
||||
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 content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name);
|
||||
@@ -323,7 +323,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult AddFieldTo(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 content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
@@ -347,7 +347,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
|
||||
[HttpPost, ActionName("AddFieldTo")]
|
||||
public ActionResult AddFieldToPOST(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 content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new AddFieldViewModel();
|
||||
@@ -391,6 +391,50 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
return RedirectToAction("EditPart", new { id });
|
||||
}
|
||||
|
||||
|
||||
public ActionResult RemoveFieldFrom(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
|
||||
var viewModel = new RemoveFieldViewModel();
|
||||
if (contentPartDefinition == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name };
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("RemoveFieldFrom")]
|
||||
public ActionResult RemoveFieldFromPOST(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
|
||||
var viewModel = new RemoveFieldViewModel();
|
||||
if (contentPartDefinition == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name };
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterPartDefinition(id, typeBuilder => typeBuilder.RemoveField(viewModel.Name));
|
||||
Services.Notifier.Information(T("The \"{0}\" field has been removed.", viewModel.Name));
|
||||
|
||||
if (_contentDefinitionService.GetTypeDefinition(id) != null)
|
||||
return RedirectToAction("Edit", new { id });
|
||||
|
||||
return RedirectToAction("EditPart", new { id });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
class Updater : IUpdateModel {
|
||||
|
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Services\ContentDefinitionService.cs" />
|
||||
<Compile Include="Services\IContentDefinitionService.cs" />
|
||||
<Compile Include="ViewModels\AddFieldViewModel.cs" />
|
||||
<Compile Include="ViewModels\RemoveFieldViewModel.cs" />
|
||||
<Compile Include="ViewModels\RemovePartViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreateTypeViewModel.cs" />
|
||||
<Compile Include="ViewModels\EditTypeViewModel.cs" />
|
||||
@@ -88,6 +89,7 @@
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\AddFieldTo.ascx" />
|
||||
<Content Include="Views\Admin\AddPartsTo.ascx" />
|
||||
<Content Include="Views\Admin\RemoveFieldFrom.ascx" />
|
||||
<Content Include="Views\Admin\RemovePartFrom.ascx" />
|
||||
<Content Include="Views\Admin\Create.ascx" />
|
||||
<Content Include="Views\Admin\EditPart.ascx" />
|
||||
|
@@ -0,0 +1,8 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class RemoveFieldViewModel : BaseViewModel {
|
||||
public string Name { get; set; }
|
||||
public EditPartViewModel Part { get; set; }
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<h2><%:T("Fields") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div>
|
||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<fieldset>
|
||||
<fieldset class="action">
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
||||
|
@@ -0,0 +1,11 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.RemoveFieldViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Part.Name).ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<p><%:T("Looks like you couldn't use the fancy way to remove the field. Try hitting the button below to force the issue.") %></p>
|
||||
<fieldset>
|
||||
<%=Html.HiddenFor(m => m.Name) %>
|
||||
<button class="primaryAction" type="submit"><%:T("Remove") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -2,7 +2,7 @@
|
||||
<fieldset class="manage-field">
|
||||
<h3><%:Model.Name %> <span>(<%:Model.FieldDefinition.Name %>)</span></h3>
|
||||
<div class="manage">
|
||||
<%:Html.Link("[remove]", "#forshowonlyandnotintendedtowork!") %>
|
||||
<%:Html.ActionLink(T("Remove").Text, "RemoveFieldFrom", new { area = "Orchard.ContentTypes", id = Model.Part.Name, Model.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
|
||||
</div><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
|
Reference in New Issue
Block a user