Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8565: Delete and Unpublish buttons in backoffice content edit #8566

Open
wants to merge 15 commits into
base: 1.10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Orchard.Web/Core/Contents/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,32 @@ public ActionResult EditAndPublishPOST(int id, string returnUrl) {
return EditPOST(id, returnUrl, contentItem => _contentManager.Publish(contentItem));
}

/// <summary>
/// This action is specific to the submit button of the edit form.
/// Unpublish logic is the same of the Unpublish action, which is called by the content list.
/// </summary>
/// <param name="id"></param>
/// <param name="returnUrl"></param>
/// <returns></returns>
[HttpPost, ActionName("Edit")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different that the other unpublish/delete actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added delete and unpublish actions referencing specific submits to the controller. There already were unpublish and delete actions (the ones called from the lists), so I called those inside the new actions, specific to the edit form.

[Mvc.FormValueRequired("submit.Unpublish")]
public ActionResult EditUnpublishPOST(int id, string returnUrl) {
return Unpublish(id, returnUrl);
}

/// <summary>
/// This action is specific to the submit button of the edit form.
/// Delete logic is the same of the Remove action, which is called by the content list.
/// </summary>
/// <param name="id"></param>
/// <param name="returnUrl"></param>
/// <returns></returns>
[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Delete")]
public ActionResult EditDeletePOST(int id, string returnUrl) {
return Remove(id, returnUrl);
}

private ActionResult EditPOST(int id, string returnUrl, Action<ContentItem> conditionallyPublish) {
var contentItem = _contentManager.Get(id, VersionOptions.DraftRequired);

Expand Down
8 changes: 7 additions & 1 deletion src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ protected override DriverResult Display(ContentPart part, string displayType, dy
protected override DriverResult Editor(ContentPart part, dynamic shapeHelper) {
var results = new List<DriverResult> { ContentShape("Content_SaveButton", saveButton => saveButton) };

if (part.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
if (part.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable) {
results.Add(ContentShape("Content_PublishButton", publishButton => publishButton));
results.Add(ContentShape("Content_UnpublishButton", unpublishButton => unpublishButton));
AndreaPiovanelli marked this conversation as resolved.
Show resolved Hide resolved
}

if (part.Id > 0) {
results.Add(ContentShape("Content_DeleteButton", deleteButton => deleteButton));
}

return Combined(results.ToArray());
}
Expand Down
4 changes: 3 additions & 1 deletion src/Orchard.Web/Core/Contents/Placement.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
Parts_Contents_Publish_SummaryAdmin
-->
<!-- edit "shape" -->
<Place Content_PublishButton="Sidebar:24"/>
<Place Content_SaveButton="Sidebar:23"/>
<Place Content_PublishButton="Sidebar:24"/>
<Place Content_UnpublishButton="Sidebar:25"/>
<Place Content_DeleteButton="Sidebar:26"/>
<Match DisplayType="Detail">
<Place Parts_Contents_Publish="Content:5"/>
</Match>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@using Orchard.ContentManagement;
@using Orchard.Core.Contents;

@if (Authorizer.Authorize(Permissions.DeleteContent, (IContent)Model.ContentItem)) {
<fieldset class="delete-button">
<button type="submit" name="submit.Delete" value="submit.Delete" itemprop="RemoveUrl">@T("Delete")</button>
</fieldset>
}
12 changes: 12 additions & 0 deletions src/Orchard.Web/Core/Contents/Views/Content.UnpublishButton.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@using Orchard.ContentManagement;
@using Orchard.Core.Contents;

@{
var contentItem = Model.ContentItem as IContent;
}
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty lines around this block. I pointed this out earlier too and it would be easier if you just accepted my change suggestions in bulk, so that I don't have to go through all of them again to figure out what's fixed and what isn't.

Suggested change
@{
var contentItem = Model.ContentItem as IContent;
}
@{
var contentItem = Model.ContentItem as IContent;
}


@if (Authorizer.Authorize(Permissions.PublishContent, contentItem) && contentItem.IsPublished()) {
<fieldset class="unpublish-button">
<button type="submit" name="submit.Unpublish" value="submit.Unpublish">@T("Unpublish")</button>
</fieldset>
}
8 changes: 6 additions & 2 deletions src/Orchard.Web/Core/Orchard.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,16 @@
<ItemGroup>
<Content Include="Navigation\Views\Admin\Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Contents\Views\Content.UnpublishButton.cshtml" />
<Content Include="Contents\Views\Content.DeleteButton.cshtml" />
<None Include="packages.config" />
<Content Include="Title\Views\DefinitionTemplates\TitlePartSettings.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Containers\Styles\Web.config">
<SubType>Designer</SubType>
</Content>
<None Include="packages.config" />
<Content Include="Title\Views\DefinitionTemplates\TitlePartSettings.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use remove and sort usings and auto-formatting.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
Expand Down Expand Up @@ -138,6 +137,12 @@ public ActionResult EditPOST(int blogId, int postId, string returnUrl) {
});
}

[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Delete")]
public ActionResult EditDeletePOST(int blogId, int postId, string returnUrl) {
return Delete(blogId, postId);
}

[HttpPost, ActionName("Edit")]
[FormValueRequired("submit.Publish")]
public ActionResult EditAndPublishPOST(int blogId, int postId, string returnUrl) {
Expand All @@ -156,6 +161,12 @@ public ActionResult EditAndPublishPOST(int blogId, int postId, string returnUrl)
return EditPOST(blogId, postId, returnUrl, contentItem => Services.ContentManager.Publish(contentItem));
}

[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Unpublish")]
public ActionResult EditUnpublishPOST(int blogId, int postId, string returnUrl) {
return Unpublish(blogId, postId);
}

public ActionResult EditPOST(int blogId, int postId, string returnUrl, Action<ContentItem> conditionallyPublish) {
var blog = _blogService.Get(blogId, VersionOptions.Latest);
if (blog == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,17 +1101,17 @@ html.dyn #submit-pager, html.dyn .apply-bulk-actions-auto { display:none; }
padding:0;
}

fieldset.publish-button, fieldset.delete-button, fieldset.save-button {
fieldset.publish-button, fieldset.delete-button, fieldset.save-button, fieldset.unpublish-button {
clear:none;
float:left;
}
fieldset.save-button {
clear:left;
}
fieldset.publish-button {
fieldset.publish-button, fieldset.unpublish-button {
margin: 0 12px 0 0;
padding: 0 12px;
border-right:1px solid #ccc;
border-right: 1px solid #ccc;
}
fieldset.delete-button {
margin: 0 0 0 12px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ protected override DriverResult Editor(LayerPart layerPart, dynamic shapeHelper)
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.LayerPart", Model: layerPart, Prefix: Prefix))
};

if (layerPart.Id > 0)
results.Add(ContentShape("Widget_DeleteButton",
deleteButton => deleteButton));

return Combined(results.ToArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,22 @@ protected override DriverResult Editor(WidgetPart widgetPart, dynamic shapeHelpe
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.WidgetPart", Model: widgetPart, Prefix: Prefix))
};

if (widgetPart.Id > 0)
results.Add(ContentShape("Widget_DeleteButton",
deleteButton => deleteButton));

return Combined(results.ToArray());
}

protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(widgetPart, Prefix, null, null);

if(string.IsNullOrWhiteSpace(widgetPart.Title)) {
if (string.IsNullOrWhiteSpace(widgetPart.Title)) {
updater.AddModelError("Title", T("Title can't be empty."));
}

// if there is a name, ensure it's unique
if(!string.IsNullOrWhiteSpace(widgetPart.Name)) {
if (!string.IsNullOrWhiteSpace(widgetPart.Name)) {
widgetPart.Name = widgetPart.Name.ToHtmlName();

var widgets = _contentManager.Query<WidgetPart, WidgetPartRecord>().Where(x => x.Name == widgetPart.Name && x.Id != widgetPart.Id).Count();
if(widgets > 0) {
if (widgets > 0) {
updater.AddModelError("Name", T("A Widget with the same Name already exists."));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@
<Content Include="Views\EditorTemplates\Parts.Widgets.LayerPart.cshtml" />
<Content Include="Views\EditorTemplates\Parts.Widgets.WidgetPart.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Widget.DeleteButton.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Web.config" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Orchard.Web/Modules/Orchard.Widgets/Placement.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Placement>
<Place Widget_DeleteButton="Sidebar:25"/>
<Place Parts_Widgets_LayerPart="Content:1"/>
<Place Parts_Widgets_WidgetPart="Content:1"/>
<Place Parts_Widgets_WidegetBagPart="Content:5"/>
Expand Down

This file was deleted.

53 changes: 34 additions & 19 deletions src/Orchard.Web/Themes/TheAdmin/Styles/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1126,24 +1126,27 @@ html.dyn #submit-pager, html.dyn .apply-bulk-actions-auto { display:none; }
/* Core Contents and Orchard.PublishLater */

.edit-item-sidebar fieldset {
margin:0;
padding:0;
margin: 0;
padding: 0;
clear: none;
float: left;
}

fieldset.publish-button, fieldset.delete-button, fieldset.save-button {
clear:none;
float:left;
.edit-item-sidebar fieldset:not(:first-child) {
margin-left: 12px;
}
fieldset.save-button {
clear:left;

.edit-item-sidebar fieldset:first-child {
clear: left;
}
fieldset.publish-button {
margin: 0 12px 0 0;
padding: 0 12px;
border-right:1px solid #ccc;

fieldset.publish-button, fieldset.unpublish-button {
padding-right: 12px;
border-right: 1px solid #ccc;
}

fieldset.delete-button {
margin: 0 0 0 12px;
float: right;
}

/* Dashboard */
Expand Down Expand Up @@ -1495,17 +1498,29 @@ html.dir-rtl {
margin-left:inherit;
margin-right:10px;
}
.dir-rtl fieldset.publish-button, fieldset.delete-button, .dir-rtl fieldset.save-button {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, RTL version for lines 1498-1509:

.dir-rtl .edit-item-sidebar fieldset {
    float: right;
}
.dir-rtl .edit-item-sidebar fieldset:first-child {
    clear: right;
}
.dir-rtl .edit-item-sidebar fieldset:not(:first-child) {
    margin-left: 0;
    margin-right: 12px;
}
.dir-rtl fieldset.publish-button, fieldset.unpublish-button {
    padding-right: 0;
    border-right: none;
    padding-left: 12px;
    border-left: 1px solid #ccc;
}
.dir-rtl fieldset.delete-button {
    float: left;
}

float:right;

.dir-rtl .edit-item-sidebar fieldset {
float: right;
}
.dir-rtl fieldset.save-button {
clear:right;

.dir-rtl .edit-item-sidebar fieldset:first-child {
clear: right;
}
.dir-rtl fieldset.publish-button {
margin: 0 0 0 12px ;

.dir-rtl .edit-item-sidebar fieldset:not(:first-child) {
margin-left: 0;
margin-right: 12px;
}

.dir-rtl fieldset.publish-button, fieldset.unpublish-button {
padding-right: 0;
border-right: none;
padding-left: 12px;
border-left: 1px solid #ccc;
}

.dir-rtl fieldset.delete-button {
margin: 0 12px 0 0;
float: left;
}

.content-rtl .permalink input.text {
Expand Down