mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
A little work on new menu item (in main menu management) validation
--HG-- branch : dev
This commit is contained in:
@@ -23,13 +23,17 @@ namespace Orchard.Core.Navigation.Controllers {
|
||||
|
||||
private Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
public ActionResult Index(NavigationManagementViewModel model) {
|
||||
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Not allowed to manage the main menu")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var model = new NavigationManagementViewModel { Menu = _navigationManager.BuildMenu("main") };
|
||||
if (model == null)
|
||||
model = new NavigationManagementViewModel();
|
||||
|
||||
return View(model);
|
||||
if (model.Menu == null || model.Menu.Count() < 1)
|
||||
model.Menu = _navigationManager.BuildMenu("main");
|
||||
|
||||
return View("Index", model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Index")]
|
||||
@@ -50,7 +54,7 @@ namespace Orchard.Core.Navigation.Controllers {
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
_services.TransactionManager.Cancel();
|
||||
return Index();
|
||||
return Index(new NavigationManagementViewModel {NewMenuItem = model});
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(menuItem.As<MenuPart>().MenuPosition))
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Web.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Records;
|
||||
|
||||
@@ -12,6 +13,7 @@ namespace Orchard.Core.Navigation.Models {
|
||||
set { Record.OnMainMenu = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string MenuText {
|
||||
get { return Record.MenuText; }
|
||||
set { Record.MenuText = value; }
|
||||
@@ -21,7 +23,5 @@ namespace Orchard.Core.Navigation.Models {
|
||||
get { return Record.MenuPosition; }
|
||||
set { Record.MenuPosition = value; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -2,5 +2,6 @@
|
||||
|
||||
namespace Orchard.Core.Navigation.ViewModels {
|
||||
public class NavigationManagementViewModel : AdminViewModel {
|
||||
public CreateMenuItemViewModel NewMenuItem { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<NavigationManagementViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement"%>
|
||||
<%@ Import Namespace="Orchard.Core.Navigation.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Navigation.ViewModels"%><%
|
||||
var menu = Model.Menu.FirstOrDefault(); %>
|
||||
<h1><%=Html.TitleForPage(T("Manage Main Menu").ToString())%></h1><%
|
||||
@@ -31,7 +33,9 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
</table>
|
||||
<fieldset class="actions"><button type="submit"><%=_Encoded("Update All") %></button></fieldset><%
|
||||
}
|
||||
%><h2><%=_Encoded("Add New Item") %></h2><%
|
||||
%>
|
||||
|
||||
<h2><%=_Encoded("Add New Item") %></h2><%
|
||||
using (Html.BeginFormAntiForgeryPost("/admin/navigation/create", FormMethod.Post)) { %>
|
||||
<table class="menu items">
|
||||
<colgroup>
|
||||
@@ -43,16 +47,16 @@ using (Html.BeginFormAntiForgeryPost("/admin/navigation/create", FormMethod.Post
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="addtext"><%=_Encoded("Text") %></label>
|
||||
<input type="text" name="MenuText" id="addtext" />
|
||||
<label for="MenuText"><%=_Encoded("Text") %></label>
|
||||
<%=Html.EditorFor(nmvm => nmvm.NewMenuItem.MenuItem.Item.As<MenuPart>().MenuText) %>
|
||||
</td>
|
||||
<td>
|
||||
<label for="addposition"><%=_Encoded("Position")%></label>
|
||||
<input type="text" name="MenuPosition" id="addposition" />
|
||||
<label for="MenuPosition"><%=_Encoded("Position")%></label>
|
||||
<%=Html.EditorFor(nmvm => nmvm.NewMenuItem.MenuItem.Item.As<MenuPart>().MenuPosition) %>
|
||||
</td>
|
||||
<td>
|
||||
<label for="addurl"><%=_Encoded("Url")%></label>
|
||||
<input type="text" name="Url" id="addurl" />
|
||||
<label for="Url"><%=_Encoded("Url")%></label>
|
||||
<%=Html.EditorFor(nmvm => nmvm.NewMenuItem.MenuItem.Item.As<Orchard.Core.Navigation.Models.MenuItem>().Url)%>
|
||||
</td>
|
||||
<td><button class="add" type="submit"><%=_Encoded("Add") %></button></td>
|
||||
</tr>
|
||||
|
Reference in New Issue
Block a user