2010-02-10 16:22:15 -08:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
using Orchard.Core.Navigation.Models;
|
2010-02-11 11:10:14 -08:00
|
|
|
|
using Orchard.Security;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
using Orchard.UI.Navigation;
|
|
|
|
|
using Orchard.Utility;
|
2010-02-10 16:22:15 -08:00
|
|
|
|
|
2010-02-15 14:01:13 -08:00
|
|
|
|
namespace Orchard.Core.Navigation.Drivers {
|
2010-02-10 16:22:15 -08:00
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class MenuPartDriver : ContentPartDriver<MenuPart> {
|
2010-02-11 11:10:14 -08:00
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
private readonly INavigationManager _navigationManager;
|
2010-02-11 11:10:14 -08:00
|
|
|
|
|
2010-02-15 14:01:13 -08:00
|
|
|
|
public MenuPartDriver(IAuthorizationService authorizationService, INavigationManager navigationManager) {
|
2010-02-11 11:10:14 -08:00
|
|
|
|
_authorizationService = authorizationService;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
_navigationManager = navigationManager;
|
2010-02-11 11:10:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual IUser CurrentUser { get; set; }
|
|
|
|
|
|
2010-02-10 16:22:15 -08:00
|
|
|
|
protected override DriverResult Editor(MenuPart part) {
|
2010-02-11 11:10:14 -08:00
|
|
|
|
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
|
|
|
|
|
return null;
|
|
|
|
|
|
2010-02-10 16:22:15 -08:00
|
|
|
|
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(MenuPart part, IUpdateModel updater) {
|
2010-02-11 11:10:14 -08:00
|
|
|
|
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
|
|
|
|
|
return null;
|
|
|
|
|
|
2010-02-15 14:01:13 -08:00
|
|
|
|
if (string.IsNullOrEmpty(part.MenuPosition))
|
|
|
|
|
part.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main"));
|
|
|
|
|
|
2010-02-10 16:22:15 -08:00
|
|
|
|
updater.TryUpdateModel(part, Prefix, null, null);
|
|
|
|
|
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-15 14:01:13 -08:00
|
|
|
|
}
|