init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
106
KretaWeb/Helpers/ColorPickerExtensions.cs
Normal file
106
KretaWeb/Helpers/ColorPickerExtensions.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
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;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class ColorPickerExtensions
|
||||
{
|
||||
public static ColorPickerBuilder KretaColorPicker(this HtmlHelper helper, string name, bool enabled = true, Dictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
var cp = helper.Kendo().ColorPicker()
|
||||
.Name(name)
|
||||
.Enable(enabled);
|
||||
|
||||
if (htmlAttributes == null)
|
||||
{
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
}
|
||||
cp.HtmlAttributes(htmlAttributes);
|
||||
|
||||
return cp;
|
||||
}
|
||||
|
||||
public static ColorPickerBuilder KretaColorPickerFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, Dictionary<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>();
|
||||
|
||||
htmlAttributes.Add("data-labelmsg", metadata.DisplayName);
|
||||
|
||||
var cp = helper.Kendo().ColorPicker()
|
||||
.Name(fullBindingName)
|
||||
.HtmlAttributes(htmlAttributes);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
cp.Value(value.ToString());
|
||||
}
|
||||
|
||||
return cp;
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithName(this ColorPickerBuilder helper, int labelWidth = 6, int inputWidth = 6, bool allSizeSame = false, 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 (string.IsNullOrWhiteSpace(tooltipResource))
|
||||
AddRenderWithNameBeginingFrame(sb, labelWidth, inputWidth, allSizeSame, helper.ToComponent().Name, labelMsg, string.Empty);
|
||||
else
|
||||
AddRenderWithNameTooltipBeginingFrame(sb, labelWidth, inputWidth, allSizeSame, helper.ToComponent().Name, labelMsg, string.Empty, tooltipResource);
|
||||
sb.Append(helper.ToHtmlString());
|
||||
AddRenderWithNameCloseingFrame(sb);
|
||||
return new MvcHtmlString(sb.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString RenderWithName(this ColorPickerBuilder helper, string label, int labelWidth = 6, int inputWidth = 6, bool allSizeSame = false, string tooltipResource = null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (string.IsNullOrWhiteSpace(tooltipResource))
|
||||
AddRenderWithNameBeginingFrame(sb, labelWidth, inputWidth, allSizeSame, helper.ToComponent().Name, label, string.Empty);
|
||||
else
|
||||
AddRenderWithNameTooltipBeginingFrame(sb, labelWidth, inputWidth, allSizeSame, 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, bool allSizeSame, string controlName, string labelMsg, string customClass)
|
||||
{
|
||||
sb.AppendFormat("<div class=\"{0} {1} \">", BootsrapHelper.GetSizeClasses(labelWidth, allSizeSame), customClass);
|
||||
sb.AppendFormat("<label class=\"windowInputLabel\" for=\"{0}\">{1}</label>", controlName, labelMsg);
|
||||
sb.AppendFormat("</div><div class=\"{0} {1}\">", BootsrapHelper.GetSizeClasses(inputWidth, allSizeSame), customClass);
|
||||
}
|
||||
|
||||
private static void AddRenderWithNameTooltipBeginingFrame(StringBuilder sb, int labelWidth, int inputWidth, bool allSizeSame, string controlName, string labelMsg, string customClass, string tooltipResource)
|
||||
{
|
||||
sb.AppendFormat("<div class=\"{0} {1} kretaLabelTooltip \">", BootsrapHelper.GetSizeClasses(labelWidth, allSizeSame), 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}\">", BootsrapHelper.GetSizeClasses(inputWidth, allSizeSame), customClass);
|
||||
}
|
||||
|
||||
private static void AddRenderWithNameCloseingFrame(StringBuilder sb)
|
||||
{
|
||||
sb.Append("</div>");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue