2011-11-14 01:22:18 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2010-10-02 21:01:43 +02:00
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Mvc.Html;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
|
2011-11-14 01:22:18 +01:00
|
|
|
|
namespace NzbDrone.Web.Helpers
|
2010-10-02 21:01:43 +02:00
|
|
|
|
{
|
|
|
|
|
public static class IsCurrentActionHelper
|
|
|
|
|
{
|
2012-10-15 02:50:01 +02:00
|
|
|
|
private static bool IsCurrentController(HtmlHelper helper, string controllerName)
|
2010-10-02 21:01:43 +02:00
|
|
|
|
{
|
2011-04-10 04:44:01 +02:00
|
|
|
|
var currentControllerName = (string) helper.ViewContext.RouteData.Values["controller"];
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-15 02:50:01 +02:00
|
|
|
|
private static bool IsCurrentAction(HtmlHelper helper, string actionName, string controllerName)
|
|
|
|
|
{
|
|
|
|
|
var currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
|
|
|
|
|
var currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
|
|
|
|
|
|
|
|
|
|
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) &&
|
|
|
|
|
currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string CurrentControllerLink(this HtmlHelper helper, string text, string actionName, string controllerName)
|
2010-10-02 21:01:43 +02:00
|
|
|
|
{
|
|
|
|
|
string result;
|
|
|
|
|
|
2012-10-15 02:50:01 +02:00
|
|
|
|
if (IsCurrentController(helper, controllerName))
|
2010-10-02 21:01:43 +02:00
|
|
|
|
{
|
|
|
|
|
result = "<li class='current_page_item'>";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = "<li>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result + helper.ActionLink(text, actionName, controllerName).ToHtmlString() + @"</li>";
|
|
|
|
|
}
|
2012-10-15 02:50:01 +02:00
|
|
|
|
|
|
|
|
|
public static string CurrentActionLink(this HtmlHelper helper, string text, string actionName, string controllerName)
|
|
|
|
|
{
|
|
|
|
|
string result;
|
|
|
|
|
|
|
|
|
|
if (IsCurrentAction(helper, actionName, controllerName))
|
|
|
|
|
{
|
|
|
|
|
result = "<li class='current_action'>";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = "<li>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result + helper.ActionLink(text, actionName, controllerName).ToHtmlString() + @"</li>";
|
|
|
|
|
}
|
2010-10-02 21:01:43 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|