kreta/KretaWeb/Helpers/RadioButtonExtensions.cs
2024-03-13 00:33:46 +01:00

63 lines
2.9 KiB
C#

using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using Kendo.Mvc.UI.Fluent;
namespace Kreta.Web.Helpers
{
public static class RadioButtonExtensions
{
public static RadioButtonBuilder KretaRadioButton(this HtmlHelper helper, string name, string label, bool check, bool enabled = true, IDictionary<string, object> htmlAttributes = null)
{
var rb = helper.Kendo().RadioButton()
.Name(name)
.Label(label)
.Checked(check)
.Enable(enabled);
if (htmlAttributes != null)
{
rb.HtmlAttributes(htmlAttributes);
}
return rb;
}
public static MvcHtmlString RenderWithoutName(this RadioButtonBuilder helper, string customClass = "", string tooltipResource = null, string tooltipWidth = null, bool isInnerTooltip = true)
{
var sb = new StringBuilder();
sb.AppendFormat("<div class=\"{0}\">", BootsrapHelper.GetSizeClasses(12));
sb.AppendFormat("<div class=\"{0}\" style=\"float: left;\">", customClass);
sb.Append(helper.ToHtmlString());
sb.Append("</div>");
if (!string.IsNullOrWhiteSpace(tooltipResource))
{
if (isInnerTooltip)
{
sb.AppendFormat("<div class=\"{0} kretaLabelTooltip\" style=\"width: 40px; float: left;\">", customClass);
sb.AppendFormat("<label class=\"windowInputLabel\" for=\"{0}\">", helper.ToComponent().Name);
sb.Append("&nbsp;<img class='kretaLabelTooltipImg' />");
sb.AppendFormat("<span class=\"kretaLabelTooltipText\" {1}>{0}</span>", tooltipResource, string.IsNullOrWhiteSpace(tooltipWidth) ? "" : string.Format("style=\"width:{0};\"", tooltipWidth));
sb.Append("</label>");
sb.Append("</div>");
}
else
{
sb.AppendLine($@"<div class=""kretaLabelTooltipTextOuter"" style=""bottom: 100%; {(string.IsNullOrWhiteSpace(tooltipWidth) ? "" : string.Format("width:{0};", tooltipWidth))}"">
<span>{tooltipResource}</span></div>");
sb.Append($@"<script type=""text/javascript"">
$('label[for=""{helper.ToComponent().Name}_{helper.ToComponent().Value}""]').append(""<img class='kretaLabelTooltipImgOuter'/>"");
$('label[for=""{helper.ToComponent().Name}_{helper.ToComponent().Value}""]').parent().parent().parent('div[class^=""col-""]').css(""overflow"", ""visible"");
$('label[for=""{helper.ToComponent().Name}_{helper.ToComponent().Value}""]').parent().addClass(""kretaLabelTooltipOuter"")</script>");
}
}
sb.Append("</div>");
return new MvcHtmlString(sb.ToString());
}
}
}