mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 02:37:55 +08:00
Some work on "Manage Main Menu". Some controller actions stubbed out and create hooked up (validation lacking).
--HG-- branch : dev rename : src/Orchard.Web/Core/Navigation/Models/MenuItemDriver.cs => src/Orchard.Web/Core/Navigation/Drivers/MenuItemDriver.cs rename : src/Orchard.Web/Core/Navigation/Models/MenuPartDriver.cs => src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs rename : src/Orchard.Web/Core/Navigation/Models/MenuItemHandler.cs => src/Orchard.Web/Core/Navigation/Handlers/MenuItemHandler.cs rename : src/Orchard.Web/Core/Navigation/Models/MenuPartHandler.cs => src/Orchard.Web/Core/Navigation/Handlers/MenuPartHandler.cs
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
||||
|
||||
namespace Orchard.Core.Navigation.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller {
|
||||
public class AdminController : Controller, IUpdateModel {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly INavigationManager _navigationManager;
|
||||
|
||||
@@ -15,12 +18,62 @@ namespace Orchard.Core.Navigation.Controllers {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
private Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new NavigationManagementViewModel {Menu = _navigationManager.BuildMenu("main")};
|
||||
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Not allowed to manage the main menu")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var model = new ViewModels.NavigationManagementViewModel { Menu = _navigationManager.BuildMenu("main") };
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Index")]
|
||||
public ActionResult IndexPOST() {
|
||||
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(CreateMenuItemViewModel model) {
|
||||
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var menuItem = _services.ContentManager.New<MenuItem>(MenuItemDriver.ContentType.Name);
|
||||
model.MenuItem = _services.ContentManager.UpdateEditorModel(menuItem, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
_services.TransactionManager.Cancel();
|
||||
return Index();
|
||||
}
|
||||
|
||||
menuItem.As<MenuPart>().OnMainMenu = true;
|
||||
_services.ContentManager.Create(model.MenuItem.Item.ContentItem);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
//[ValidateAntiForgeryTokenOrchard, ActionName("Delete")]
|
||||
[HttpPost, ActionName("Delete")]
|
||||
public ActionResult DeletePOST(int menuItemId)
|
||||
{
|
||||
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//todo -> delete
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
}
|
||||
|
||||
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
||||
ModelState.AddModelError(key, errorMessage.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,26 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
[UsedImplicitly]
|
||||
public class MenuItemDriver : ContentItemDriver<MenuItem> {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "menuitem",
|
||||
DisplayName = "Menu Item"
|
||||
};
|
||||
|
||||
public MenuItemDriver(IOrchardServices orchardServices) {
|
||||
public MenuItemDriver(IOrchardServices orchardServices, IAuthorizationService authorizationService) {
|
||||
_orchardServices = orchardServices;
|
||||
_authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
public virtual IUser CurrentUser { get; set; }
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
@@ -25,5 +30,14 @@ namespace Orchard.Core.Navigation.Models {
|
||||
protected override string GetDisplayText(MenuItem item) {
|
||||
return item.Url;
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(MenuItem item, IUpdateModel updater) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, item))
|
||||
return null;
|
||||
|
||||
updater.TryUpdateModel(item, Prefix, null, null);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Navigation.ViewModels {
|
||||
public class CreateMenuItemViewModel : AdminViewModel {
|
||||
public ContentItemViewModel<MenuItem> MenuItem { get; set; }
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<NavigationManagementViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Navigation.ViewModels"%><%
|
||||
var menu = Model.Menu.FirstOrDefault(); %>
|
||||
<h1><%=Html.TitleForPage(T("Edit Main Menu").ToString())%></h1><%
|
||||
<h1><%=Html.TitleForPage(T("Manage Main Menu").ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<table class="items">
|
||||
<colgroup>
|
||||
@@ -31,14 +31,29 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
</table>
|
||||
<fieldset class="actions"><button type="submit"><%=_Encoded("Update All") %></button></fieldset><%
|
||||
}
|
||||
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<table class="items">
|
||||
%><h2><%=_Encoded("Add New Item") %></h2><%
|
||||
using (Html.BeginFormAntiForgeryPost("/admin/navigation/create", FormMethod.Post)) { %>
|
||||
<table class="menu items">
|
||||
<colgroup>
|
||||
<col id="AddText" />
|
||||
<col id="AddPosition" />
|
||||
<col id="AddUrl" />
|
||||
<col id="AddActions" />
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><input type="text" name="addtext" id="addtext" /></td>
|
||||
<td><input type="text" name="addposition" id="addposition" /></td>
|
||||
<td><input type="text" name="addurl" id="addurl" /></td>
|
||||
<td>
|
||||
<label for="addtext"><%=_Encoded("Text") %></label>
|
||||
<input type="text" name="MenuText" id="addtext" />
|
||||
</td>
|
||||
<td>
|
||||
<label for="addposition"><%=_Encoded("Position")%></label>
|
||||
<input type="text" name="MenuPosition" id="addposition" />
|
||||
</td>
|
||||
<td>
|
||||
<label for="addurl"><%=_Encoded("Url")%></label>
|
||||
<input type="text" name="Url" id="addurl" />
|
||||
</td>
|
||||
<td><button class="add" type="submit"><%=_Encoded("Add") %></button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@@ -107,16 +107,17 @@
|
||||
<Compile Include="Navigation\AdminMenu.cs" />
|
||||
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
||||
<Compile Include="Navigation\Models\MenuItem.cs" />
|
||||
<Compile Include="Navigation\Models\MenuItemDriver.cs" />
|
||||
<Compile Include="Navigation\Models\MenuItemHandler.cs" />
|
||||
<Compile Include="Navigation\Drivers\MenuItemDriver.cs" />
|
||||
<Compile Include="Navigation\Handlers\MenuItemHandler.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPart.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPartDriver.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPartHandler.cs" />
|
||||
<Compile Include="Navigation\Drivers\MenuPartDriver.cs" />
|
||||
<Compile Include="Navigation\Handlers\MenuPartHandler.cs" />
|
||||
<Compile Include="Navigation\Permissions.cs" />
|
||||
<Compile Include="Navigation\Records\MenuItemRecord.cs" />
|
||||
<Compile Include="Navigation\Records\MenuPartRecord.cs" />
|
||||
<Compile Include="Navigation\Services\MainMenu.cs" />
|
||||
<Compile Include="Navigation\Filters\MainMenuFilter.cs" />
|
||||
<Compile Include="Navigation\ViewModels\CreateMenuItemViewModel.cs" />
|
||||
<Compile Include="Navigation\ViewModels\NavigationManagementViewModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scheduling\Records\ScheduledTaskRecord.cs" />
|
||||
|
@@ -641,10 +641,6 @@ table.items thead, table.items th {
|
||||
overflow:hidden;
|
||||
text-align:left;
|
||||
}
|
||||
/* todo: (heskew) hook back up */
|
||||
table.items tr.hover {
|
||||
background-color:#f0f3d6;
|
||||
}
|
||||
table.items tr.critical {background:#e68585; border:inherit;}
|
||||
table.items tr.warning {background:#fdf5bc; border:inherit;}
|
||||
table.items th, table.items td {
|
||||
|
Reference in New Issue
Block a user