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