init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
214
KretaWeb/Helpers/TimePickerExtensions.cs
Normal file
214
KretaWeb/Helpers/TimePickerExtensions.cs
Normal file
|
@ -0,0 +1,214 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Kendo.Mvc.UI;
|
||||
using Kendo.Mvc.UI.Fluent;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Web.Security;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class TimePickerExtensions
|
||||
{
|
||||
public static TimePickerBuilder KretaTimePicker(this HtmlHelper helper, string id, string className = "", bool enabled = true, string culture = "hu-HU", int interval = 1, DateTime? minValue = null, DateTime? maxValue = null, IDictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
if (helper.ViewData.ModelState[id] != null && helper.ViewData.ModelState[id].Errors.Count > 0)
|
||||
className = string.Format("{0} input-validation-error", className);
|
||||
|
||||
var timepicker = helper.Kendo().TimePicker()
|
||||
.Name(id)
|
||||
.Enable(enabled)
|
||||
.Culture(culture)
|
||||
.Interval(interval)
|
||||
.Format("HH:mm")
|
||||
.ParseFormats(new string[] { "HH:mm" });
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(className) || !string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
var attributes = new Dictionary<string, object>();
|
||||
if (!string.IsNullOrWhiteSpace(className))
|
||||
attributes.Add("class", className.Trim());
|
||||
if (!string.IsNullOrWhiteSpace(id))
|
||||
attributes.Add("id", id);
|
||||
timepicker.HtmlAttributes(attributes);
|
||||
}
|
||||
|
||||
if (minValue.HasValue)
|
||||
timepicker.Min(minValue.Value);
|
||||
if (maxValue.HasValue)
|
||||
timepicker.Max(maxValue.Value);
|
||||
if (htmlAttributes != null)
|
||||
timepicker.HtmlAttributes(htmlAttributes);
|
||||
|
||||
return timepicker;
|
||||
}
|
||||
|
||||
public static TimePickerBuilder KretaTimePickerFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, IDictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
var fieldName = ExpressionHelper.GetExpressionText(expression);
|
||||
var fullBindingName = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(fieldName);
|
||||
var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
|
||||
var value = metadata.Model;
|
||||
|
||||
if (htmlAttributes == null)
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
|
||||
if (metadata.IsRequired)
|
||||
{
|
||||
htmlAttributes.Add("data-rule-required", "true");
|
||||
htmlAttributes.Add("data-msg-required", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
||||
htmlAttributes.Add("data-labelmsg", metadata.DisplayName + " *");
|
||||
}
|
||||
else
|
||||
{ htmlAttributes.Add("data-labelmsg", metadata.DisplayName); }
|
||||
|
||||
var timePicker = (expression.ReturnType == typeof(DateTime))
|
||||
? helper.Kendo().TimePickerFor(Expression.Lambda<Func<TModel, DateTime>>(expression.Body, expression.Parameters))
|
||||
: helper.Kendo().TimePickerFor(Expression.Lambda<Func<TModel, DateTime?>>(expression.Body, expression.Parameters));
|
||||
|
||||
timePicker.HtmlAttributes(htmlAttributes);
|
||||
|
||||
if (ClaimData.LCID == 1038 /*Magyar*/)
|
||||
{
|
||||
timePicker.Format("HH:mm");
|
||||
}
|
||||
|
||||
return timePicker;
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderSearchPanel(this TimePickerBuilder helper, bool withMask = true)
|
||||
{
|
||||
string labelMsg = "";
|
||||
foreach (var item in helper.ToComponent().HtmlAttributes)
|
||||
{
|
||||
if (item.Key == "data-labelmsg" && item.Value != null)
|
||||
labelMsg = item.Value.ToString();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (withMask)
|
||||
sb.Append($"<script>KretaDateTimeHelper.SetMaskedTimepickerById(\"{helper.ToComponent().Name.Replace('.', '_')}\");</script>");
|
||||
|
||||
sb.Append("<div class=\"searchInputRowHeight\"><div>");
|
||||
sb.Append("<label class=\"searchPanelInputLabel\" for=\"").Append(helper.ToComponent().Name).Append("\">").Append(labelMsg).Append("</label>");
|
||||
sb.Append("</div><div>");
|
||||
sb.Append(helper.ToHtmlString());
|
||||
sb.Append("</div></div>");
|
||||
|
||||
return new MvcHtmlString(sb.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderSearchPanelSideBar(this TimePickerBuilder helper, bool withMask = true)
|
||||
{
|
||||
string labelMsg = "";
|
||||
foreach (var item in helper.ToComponent().HtmlAttributes)
|
||||
{
|
||||
if (item.Key == "data-labelmsg" && item.Value != null)
|
||||
labelMsg = item.Value.ToString();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (withMask)
|
||||
sb.Append($"<script>KretaDateTimeHelper.SetMaskedTimepickerById(\"{helper.ToComponent().Name.Replace('.', '_')}\");</script>");
|
||||
|
||||
sb.Append("<div class=\"searchPanelRow\">");
|
||||
sb.Append("<div class=\"searchPanelRowTitle\">");
|
||||
sb.Append("<label class=\"searchPanelLabel\" for=\"").Append(helper.ToComponent().Name).Append("\">").Append(labelMsg).Append("</label>");
|
||||
sb.Append("</div>");
|
||||
sb.Append("<div class=\"searchPanelRowValue\">");
|
||||
sb.Append(helper.ToHtmlString());
|
||||
sb.Append("</div>");
|
||||
sb.Append("</div>");
|
||||
|
||||
return new MvcHtmlString(sb.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithMask(this TimePickerBuilder helper)
|
||||
{
|
||||
var controlId = helper.ToComponent().Id;
|
||||
|
||||
var output = new StringBuilder();
|
||||
output.Append(helper.ToHtmlString());
|
||||
output.Append("<script>");
|
||||
output.Append($"KretaDateTimeHelper.SetMaskedTimepickerById(\"{controlId}\");");
|
||||
output.Append("</script>");
|
||||
|
||||
return new MvcHtmlString(output.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithoutMask(this TimePickerBuilder helper)
|
||||
{
|
||||
var controlId = helper.ToComponent().Id;
|
||||
|
||||
var output = new StringBuilder();
|
||||
output.Append(helper.ToHtmlString());
|
||||
return new MvcHtmlString(output.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithName(this TimePickerBuilder helper, int labelWidth = 6, int inputWidth = 6, bool withMask = true, string tooltipResource = null)
|
||||
{
|
||||
string labelMsg = "";
|
||||
foreach (var item in helper.ToComponent().HtmlAttributes)
|
||||
{
|
||||
if (item.Key == "data-labelmsg" && item.Value != null)
|
||||
labelMsg = item.Value.ToString();
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (withMask)
|
||||
sb.Append($"<script>KretaDateTimeHelper.SetMaskedTimepickerById(\"{helper.ToComponent().Name.Replace('.', '_')}\");</script>");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tooltipResource))
|
||||
AddRenderWithNameBeginingFrame(sb, labelWidth, inputWidth, helper.ToComponent().Name, labelMsg, string.Empty);
|
||||
else
|
||||
AddRenderWithNameTooltipBeginingFrame(sb, labelWidth, inputWidth, helper.ToComponent().Name, labelMsg, string.Empty, tooltipResource);
|
||||
|
||||
sb.Append(helper.ToHtmlString());
|
||||
AddRenderWithNameCloseingFrame(sb);
|
||||
return new MvcHtmlString(sb.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithName(this TimePickerBuilder helper, string label, int labelWidth = 6, int inputWidth = 6, bool withMask = true, string tooltipResource = null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (withMask)
|
||||
sb.Append($"<script>KretaDateTimeHelper.SetMaskedTimepickerById(\"{helper.ToComponent().Name.Replace('.', '_')}\");</script>");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tooltipResource))
|
||||
AddRenderWithNameBeginingFrame(sb, labelWidth, inputWidth, helper.ToComponent().Name, label, string.Empty);
|
||||
else
|
||||
AddRenderWithNameTooltipBeginingFrame(sb, labelWidth, inputWidth, helper.ToComponent().Name, label, string.Empty, tooltipResource);
|
||||
|
||||
sb.Append(helper.ToHtmlString());
|
||||
AddRenderWithNameCloseingFrame(sb);
|
||||
|
||||
return new MvcHtmlString(sb.ToString());
|
||||
}
|
||||
|
||||
private static void AddRenderWithNameBeginingFrame(StringBuilder sb, int labelWidth, int inputWidth, string controlName, string labelMsg, string customClass)
|
||||
{
|
||||
sb.AppendFormat("<div class=\"{0} {1} \">", BootsrapHelper.GetSizeClasses(labelWidth), customClass);
|
||||
sb.AppendFormat("<label class=\"windowInputLabel\" for=\"{0}\">{1}</label>", controlName, labelMsg);
|
||||
sb.AppendFormat("</div><div class=\"{0} {1} timepickerMinWidth\">", BootsrapHelper.GetSizeClasses(inputWidth), customClass);
|
||||
}
|
||||
|
||||
private static void AddRenderWithNameTooltipBeginingFrame(StringBuilder sb, int labelWidth, int inputWidth, string controlName, string labelMsg, string customClass, string tooltipResource)
|
||||
{
|
||||
sb.AppendFormat("<div class=\"{0} {1} kretaLabelTooltip \">", BootsrapHelper.GetSizeClasses(labelWidth), customClass);
|
||||
sb.AppendFormat("<label class=\"windowInputLabel\" for=\"{0}\">{1}", controlName, labelMsg);
|
||||
sb.Append(" <img class='kretaLabelTooltipImg' />");
|
||||
sb.AppendFormat("<span class=\"kretaLabelTooltipText\">{0}</span>", tooltipResource);
|
||||
sb.Append("</label>");
|
||||
sb.AppendFormat("</div><div class=\"{0} {1} timepickerMinWidth\">", BootsrapHelper.GetSizeClasses(inputWidth), customClass);
|
||||
}
|
||||
|
||||
private static void AddRenderWithNameCloseingFrame(StringBuilder sb)
|
||||
{
|
||||
sb.Append("</div>");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue