mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Extending Core/Navigation/Controllers/AdminController to be able to publish/unpublish menuitems
This commit is contained in:
parent
7b503709a5
commit
bf028e0316
@ -249,6 +249,44 @@ namespace Orchard.Core.Navigation.Controllers {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
// Copy of Contents/AdminController/Publish, but with different permission check and redirect.
|
||||||
|
public ActionResult Publish(int id) {
|
||||||
|
var menuPart = _contentManager.GetLatest<MenuPart>(id);
|
||||||
|
if (menuPart == null)
|
||||||
|
return HttpNotFound();
|
||||||
|
|
||||||
|
if (!_authorizer.Authorize(Permissions.ManageMenus, menuPart.Menu, T("Couldn't manage the menu")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
_contentManager.Publish(menuPart.ContentItem);
|
||||||
|
|
||||||
|
_notifier.Information(string.IsNullOrWhiteSpace(menuPart.TypeDefinition.DisplayName)
|
||||||
|
? T("Your content has been published.")
|
||||||
|
: T("Your {0} has been published.", menuPart.TypeDefinition.DisplayName));
|
||||||
|
|
||||||
|
return RedirectToAction("Index", new { menuId = menuPart.Menu.Id });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
// Copy of Contents/AdminController/Unpublish, but with different permission check and redirect.
|
||||||
|
public ActionResult Unpublish(int id) {
|
||||||
|
var menuPart = _contentManager.GetLatest<MenuPart>(id);
|
||||||
|
if (menuPart == null)
|
||||||
|
return HttpNotFound();
|
||||||
|
|
||||||
|
if (!_authorizer.Authorize(Permissions.ManageMenus, menuPart.Menu, T("Couldn't manage the menu")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
_contentManager.Unpublish(menuPart.ContentItem);
|
||||||
|
|
||||||
|
_notifier.Information(string.IsNullOrWhiteSpace(menuPart.TypeDefinition.DisplayName)
|
||||||
|
? T("Your content has been unpublished.")
|
||||||
|
: T("Your {0} has been unpublished.", menuPart.TypeDefinition.DisplayName));
|
||||||
|
|
||||||
|
return RedirectToAction("Index", new { menuId = menuPart.Menu.Id });
|
||||||
|
}
|
||||||
|
|
||||||
private MenuItemEntry CreateMenuItemEntries(MenuPart menuPart) {
|
private MenuItemEntry CreateMenuItemEntries(MenuPart menuPart) {
|
||||||
return new MenuItemEntry {
|
return new MenuItemEntry {
|
||||||
MenuItemId = menuPart.Id,
|
MenuItemId = menuPart.Id,
|
||||||
|
@ -19,8 +19,8 @@ namespace Orchard.Core.Navigation.Services {
|
|||||||
|
|
||||||
public IEnumerable<MenuPart> GetMenuParts(int menuId) {
|
public IEnumerable<MenuPart> GetMenuParts(int menuId) {
|
||||||
return _contentManager
|
return _contentManager
|
||||||
.Query<MenuPart, MenuPartRecord>()
|
.Query<MenuPart, MenuPartRecord>(VersionOptions.Latest)
|
||||||
.Where( x => x.MenuId == menuId)
|
.Where(x => x.MenuId == menuId)
|
||||||
.List();
|
.List();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
@model NavigationManagementViewModel
|
@model NavigationManagementViewModel
|
||||||
|
|
||||||
|
@using Orchard.ContentManagement;
|
||||||
@using Orchard.Core.Navigation.ViewModels;
|
@using Orchard.Core.Navigation.ViewModels;
|
||||||
@using Orchard.Utility.Extensions;
|
@using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@ -115,8 +117,21 @@
|
|||||||
<span class="navigation-position"><input type="text" class="text" name="@Html.NameOf(m => m.MenuItemEntries[i].Position)" value="@menuPartEntry.Position" /></span>
|
<span class="navigation-position"><input type="text" class="text" name="@Html.NameOf(m => m.MenuItemEntries[i].Position)" value="@menuPartEntry.Position" /></span>
|
||||||
<span class="navigation-actions">
|
<span class="navigation-actions">
|
||||||
<input type="hidden" name="@Html.NameOf(m => m.MenuItemEntries[i].MenuItemId)" value="@menuPartEntry.MenuItemId" />
|
<input type="hidden" name="@Html.NameOf(m => m.MenuItemEntries[i].MenuItemId)" value="@menuPartEntry.MenuItemId" />
|
||||||
@Html.ItemEditLink(T("Edit").Text, menuPartEntry.ContentItem, new { returnUrl = Request.RawUrl })@T(" | ")
|
@{
|
||||||
@Html.Link(T("Delete").Text, Url.ItemRemoveUrl(menuPartEntry.ContentItem,null), new { itemprop = "RemoveUrl UnsafeUrl" })
|
var menuItemHasPublished = menuPartEntry.ContentItem.HasPublished();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Html.Link(
|
||||||
|
menuItemHasPublished ? T("Unpublish").Text : T("Publish").Text,
|
||||||
|
Url.Action(
|
||||||
|
menuItemHasPublished ? "Unpublish": "Publish",
|
||||||
|
"Admin",
|
||||||
|
new { area = "Navigation", id = menuPartEntry.ContentItem.Id }),
|
||||||
|
new { itemprop = "UnsafeUrl" })
|
||||||
|
@T(" | ")
|
||||||
|
@Html.ItemEditLink(T("Edit").Text, menuPartEntry.ContentItem, new { returnUrl = Request.RawUrl })
|
||||||
|
@T(" | ")
|
||||||
|
@Html.Link(T("Delete").Text, Url.ItemRemoveUrl(menuPartEntry.ContentItem, null), new { itemprop = "RemoveUrl UnsafeUrl" })
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user