174 lines
6.5 KiB
C#
174 lines
6.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Kendo.Mvc.UI;
|
|
using Kreta.Web.Helpers.TabStrip;
|
|
|
|
namespace Kreta.Web.Helpers
|
|
{
|
|
public static class TabStripExrtensions
|
|
{
|
|
public static Kendo.Mvc.UI.Fluent.TabStripBuilder KretaTabStrip(this HtmlHelper helper, string id, string showEventFunction = "")
|
|
{
|
|
var tab = helper.Kendo().TabStrip().Name(id);
|
|
if (!string.IsNullOrWhiteSpace(showEventFunction))
|
|
{
|
|
tab.Events(events => events.Show(showEventFunction));
|
|
}
|
|
|
|
return tab;
|
|
}
|
|
|
|
public static MvcHtmlString KretaTabStripAjax(this HtmlHelper helper, string id, List<TabStripItemModel> list, string activateEvent = null, string selectEvent = null)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (list != null)
|
|
{
|
|
sb.Append("<div id=\"").Append(id).Append("_container\" class='tab-container'>");
|
|
sb.Append("</div>");
|
|
sb.Append("<div id=\"").Append(id).Append("\">");
|
|
sb.Append("<ul>");
|
|
|
|
var activeItem = list.FirstOrDefault(i => i.IsActive);
|
|
if (activeItem == null)
|
|
{
|
|
var firstItem = list.FirstOrDefault();
|
|
if (firstItem != null)
|
|
{
|
|
firstItem.IsActive = true;
|
|
}
|
|
}
|
|
|
|
foreach (var item in list)
|
|
{
|
|
var cssClass = item.KendoCssClass;
|
|
if (!string.IsNullOrWhiteSpace(cssClass))
|
|
{
|
|
sb.AppendFormat("<li class=\"{0}\">", cssClass).Append(item.ItemName).Append("</li>");
|
|
}
|
|
else
|
|
{
|
|
if (item.IsImportantDisabled)
|
|
{
|
|
sb.AppendFormat("<li class=\"{0}\">", "k-state-disabled ").Append(item.ItemName).Append("</li>");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("<li>").Append(item.ItemName).Append("</li>");
|
|
}
|
|
}
|
|
}
|
|
sb.Append("</ul>");
|
|
|
|
var activateFunction = string.IsNullOrWhiteSpace(activateEvent) ? string.Empty : activateEvent + "(e);";
|
|
var selectFunction = string.IsNullOrWhiteSpace(selectEvent) ? string.Empty : selectEvent + "(e);";
|
|
sb.AppendFormat(@"
|
|
<script>
|
|
$(document).ready(function () {{ var ts = $('#{0}').kendoTabStrip({{animation: {{ open: {{ effects: 'fadeIn' }} }},
|
|
activate: function(e){{ {1} $('.modalContainer').scrollTop(0); }},
|
|
select: function(e){{ {2} }},
|
|
contentUrls: [", id, activateFunction, selectFunction);
|
|
|
|
int all = list.Count - 1;
|
|
int cnt2 = 0;
|
|
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
|
|
string action;
|
|
foreach (var item in list)
|
|
{
|
|
action = string.IsNullOrWhiteSpace(item.Area) ? urlHelper.Action(item.Action, item.Controller) : urlHelper.Action(item.Action, item.Controller, new { item.Area });
|
|
|
|
if (item.RouteParameters != null && item.RouteParameters.Count > 0)
|
|
{
|
|
sb.AppendFormat("'{0}?{1}", action, string.Join("&", item.RouteParameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))));
|
|
}
|
|
else
|
|
{
|
|
sb.AppendFormat("'{0}", action);
|
|
}
|
|
|
|
sb.Append("'");
|
|
|
|
if (cnt2 < all)
|
|
{ sb.Append(","); }
|
|
cnt2++;
|
|
}
|
|
sb.Append("]}).data('kendoTabStrip');");
|
|
|
|
// Hekkelés a design miatt
|
|
sb.Append("$('#" + id + " ul.k-tabstrip-items').appendTo('#" + id + "_container');");
|
|
sb.Append("$('#" + id + "_container').prependTo('#" + id + "');");
|
|
|
|
sb.Append("});</script>");
|
|
}
|
|
return new MvcHtmlString(sb.ToString());
|
|
}
|
|
|
|
public static HtmlString JQueryTabStrip(this HtmlHelper helper, string tabId, List<JQueryTabItems> tabItems)
|
|
{
|
|
StringBuilder scriptSb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
scriptSb.Append("<script>$(function() {$(\"#").Append(tabId).Append("\").tabs();});</script>");
|
|
|
|
sb.Append("<div id=\"").Append(tabId).Append("\"><ul>");
|
|
int cnt = 1;
|
|
foreach (var item in tabItems)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item.Url))
|
|
{
|
|
sb.Append(string.Format("<li><a href=\"{0}\">{1}</a></li>", item.Url, item.Title));
|
|
}
|
|
else
|
|
{
|
|
sb.Append(string.Format("<li><a href='#{0}-{1}'>{2}</a></li>", tabId, cnt, item.Title));
|
|
}
|
|
cnt++;
|
|
}
|
|
sb.Append("</ul>");
|
|
|
|
int cnt2 = 1;
|
|
foreach (var item in tabItems)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item.Content))
|
|
{
|
|
sb.Append(string.Format("<div id='{0}-{1}'>", tabId, cnt2));
|
|
sb.Append(item.Content);
|
|
sb.Append("</div>");
|
|
}
|
|
cnt2++;
|
|
}
|
|
sb.Append("</div>");
|
|
|
|
return new HtmlString(string.Format("{0} {1}", scriptSb, sb));
|
|
}
|
|
|
|
public static MvcHtmlString RenderOnModal(this Kendo.Mvc.UI.Fluent.TabStripBuilder helper)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
var id = helper.ToComponent().Id;
|
|
|
|
sb.Append("<div id=\"").Append(id).Append("_container\" class='tab-container'>");
|
|
sb.Append("</div>");
|
|
sb.Append(helper.ToHtmlString());
|
|
|
|
// §§HOWTO: "Hekkelés a design miatt" (KretaTabStripNew-ból jött...)
|
|
var appendix = string.Format(@"
|
|
<script>
|
|
$(document).ready(function() {{
|
|
$('#{0} ul').first().appendTo('#{0}_container');
|
|
$('#{0}_container').prependTo('#{0}');
|
|
}});
|
|
</script>
|
|
", id);
|
|
|
|
sb.Append(appendix);
|
|
|
|
return new MvcHtmlString(sb.ToString());
|
|
}
|
|
|
|
}
|
|
}
|