572 lines
27 KiB
C#
572 lines
27 KiB
C#
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.Resources;
|
|
|
|
namespace Kreta.Web.Helpers
|
|
{
|
|
public static class NumericExtensions
|
|
{
|
|
public static NumericTextBoxBuilder<double> KretaNumeric(this HtmlHelper helper, string name, Dictionary<string, object> htmlAttributes = null)
|
|
{
|
|
if (htmlAttributes == null)
|
|
htmlAttributes = new Dictionary<string, object>();
|
|
|
|
var numeric = helper.Kendo().NumericTextBox()
|
|
.Name(name)
|
|
.Min(0)
|
|
.Max(Constants.General.DoubleNumericTextboxDefaultMaxValue)
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<decimal> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, decimal>> 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
|
htmlAttributes.Add("labelmsg", metadata.DisplayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(Constants.General.DecimalNumericTextboxDefaultMaxValue)
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<decimal> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, decimal?>> 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
|
htmlAttributes.Add("labelmsg", metadata.DisplayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(Constants.General.DecimalNumericTextboxDefaultMaxValue)
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<int> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
|
htmlAttributes.Add("labelmsg", metadata.DisplayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(int.MaxValue)
|
|
.Decimals(0)
|
|
.Format("#")
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<int> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int?>> 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
|
htmlAttributes.Add("labelmsg", metadata.DisplayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(int.MaxValue)
|
|
.Decimals(0)
|
|
.Format("#")
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<double> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, double>> 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), metadata.DisplayName));
|
|
htmlAttributes.Add("labelmsg", metadata.DisplayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
//if (value != null)
|
|
// htmlAttributes.Add("value", value.ToString().Replace(",", "."));
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(Constants.General.DoubleNumericTextboxDefaultMaxValue)
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static NumericTextBoxBuilder<double> KretaNumericFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, double?>> expression, IDictionary<string, object> htmlAttributes = null, string label = 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("labelmsg", metadata.DisplayName + " *"); }
|
|
//else { htmlAttributes.Add("labelmsg", metadata.DisplayName); }
|
|
|
|
var displayName = string.IsNullOrWhiteSpace(label) ? metadata.DisplayName : label;
|
|
|
|
if (metadata.IsRequired)
|
|
{
|
|
htmlAttributes.Add("data-rule-required", "true");
|
|
htmlAttributes.Add("title", string.Format(StringResourcesUtil.GetString(3477), displayName));
|
|
htmlAttributes.Add("labelmsg", displayName + " *");
|
|
}
|
|
else
|
|
{ htmlAttributes.Add("labelmsg", displayName); }
|
|
|
|
//if (value != null)
|
|
// htmlAttributes.Add("value", value.ToString().Replace(",", "."));
|
|
|
|
var numeric = helper.Kendo()
|
|
.NumericTextBoxFor(expression)
|
|
.Min(0)
|
|
.Max(Constants.General.DoubleNumericTextboxDefaultMaxValue)
|
|
.HtmlAttributes(htmlAttributes);
|
|
|
|
if (metadata.IsRequired)
|
|
numeric.Events(e => e.Change("KretaNumericHelper.setTitle"));
|
|
|
|
numeric.DecreaseButtonTitle(CommonResource.ErtekCsokkentese).IncreaseButtonTitle(CommonResource.ErtekNovelese);
|
|
|
|
return numeric;
|
|
}
|
|
|
|
public static MvcHtmlString RenderSearchPanel(this NumericTextBoxBuilder<int> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 RenderSearchPanel(this NumericTextBoxBuilder<decimal> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 RenderSearchPanel(this NumericTextBoxBuilder<double> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 NumericTextBoxBuilder<int> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 RenderSearchPanelSideBar(this NumericTextBoxBuilder<decimal> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 RenderSearchPanelSideBar(this NumericTextBoxBuilder<double> helper)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "labelmsg" && item.Value != null)
|
|
labelMsg = item.Value.ToString();
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 RenderWithName(this NumericTextBoxBuilder<int> 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 == "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);
|
|
|
|
if (helper.ToComponent().Max.HasValue)
|
|
{
|
|
sb.Append(@"<script>
|
|
$('#").Append(helper.ToComponent().Name).Append(@"').on('keydown keyup', function(e){
|
|
var maxAttr = $(this).attr('max');
|
|
if (!CommonUtils.isNullOrUndefined(maxAttr) && maxAttr !== false) {
|
|
if (parseInt(this.value) > parseInt(maxAttr) && e.keyCode != 46 && e.keyCode != 8) {
|
|
e.preventDefault();
|
|
$(this).val(maxAttr);
|
|
}
|
|
}
|
|
});
|
|
</script>");
|
|
}
|
|
|
|
if (helper.ToComponent().Min.HasValue)
|
|
{
|
|
sb.Append(@"<script>
|
|
$('#").Append(helper.ToComponent().Name).Append(@"').on('keydown keyup', function(e){
|
|
var minAttr = $(this).attr('min');
|
|
if (!CommonUtils.isNullOrUndefined(minAttr) && minAttr !== false) {
|
|
if (parseInt(this.value) < parseInt(minAttr) && e.keyCode != 46 && e.keyCode != 8) {
|
|
e.preventDefault();
|
|
$(this).val(minAttr);
|
|
}
|
|
}
|
|
});
|
|
</script>");
|
|
}
|
|
|
|
return new MvcHtmlString(sb.ToString());
|
|
}
|
|
public static MvcHtmlString RenderWithName(this NumericTextBoxBuilder<decimal> 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 == "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 NumericTextBoxBuilder<double> helper, int labelWidth = 6, int inputWidth = 6, bool allSizeSame = false, string tooltipResource = null, bool needLabel = true)
|
|
{
|
|
string labelMsg = "";
|
|
foreach (var item in helper.ToComponent().HtmlAttributes)
|
|
{
|
|
if (item.Key == "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, needLabel);
|
|
else
|
|
AddRenderWithNameTooltipBeginingFrame(sb, labelWidth, inputWidth, allSizeSame, helper.ToComponent().Name, labelMsg, string.Empty, tooltipResource, needLabel);
|
|
|
|
sb.Append(helper.ToHtmlString());
|
|
AddRenderWithNameCloseingFrame(sb);
|
|
return new MvcHtmlString(sb.ToString());
|
|
}
|
|
|
|
public static MvcHtmlString RenderWithName(this NumericTextBoxBuilder<int> 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);
|
|
|
|
if (helper.ToComponent().Max.HasValue)
|
|
{
|
|
sb.Append(@"<script>
|
|
$('#").Append(helper.ToComponent().Name).Append(@"').on('keydown keyup', function(e){
|
|
var maxAttr = $(this).attr('max');
|
|
if (!CommonUtils.isNullOrUndefined(maxAttr) && maxAttr !== false) {
|
|
if (parseInt(this.value) > parseInt(maxAttr) && e.keyCode != 46 && e.keyCode != 8) {
|
|
e.preventDefault();
|
|
$(this).val(maxAttr);
|
|
}
|
|
}
|
|
});
|
|
</script>");
|
|
}
|
|
|
|
if (helper.ToComponent().Min.HasValue)
|
|
{
|
|
sb.Append(@"<script>
|
|
$('#").Append(helper.ToComponent().Name).Append(@"').on('keydown keyup', function(e){
|
|
var minAttr = $(this).attr('min');
|
|
if (!CommonUtils.isNullOrUndefined(minAttr) && minAttr !== false) {
|
|
if (parseInt(this.value) < parseInt(minAttr) && e.keyCode != 46 && e.keyCode != 8) {
|
|
e.preventDefault();
|
|
$(this).val(minAttr);
|
|
}
|
|
}
|
|
});
|
|
</script>");
|
|
}
|
|
|
|
return new MvcHtmlString(sb.ToString());
|
|
}
|
|
public static MvcHtmlString RenderWithName(this NumericTextBoxBuilder<decimal> 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());
|
|
}
|
|
public static MvcHtmlString RenderWithName(this NumericTextBoxBuilder<double> 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());
|
|
}
|
|
|
|
public static MvcHtmlString RenderWithoutName(this NumericTextBoxBuilder<double> helper, int inputWidth = 6, string tooltipResource = null)
|
|
{
|
|
return RenderWithName(helper, 1, inputWidth, tooltipResource: tooltipResource, needLabel: false);
|
|
}
|
|
|
|
private static void AddRenderWithNameBeginingFrame(StringBuilder sb, int labelWidth, int inputWidth, bool allSizeSame, string controlName, string labelMsg, string customClass, bool needLabel = true)
|
|
{
|
|
if (needLabel)
|
|
{
|
|
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>");
|
|
}
|
|
sb.AppendFormat("<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, bool needLabel = true)
|
|
{
|
|
sb.AppendFormat("<div class=\"{0} {1} kretaLabelTooltip \">", BootsrapHelper.GetSizeClasses(labelWidth, allSizeSame), customClass);
|
|
if (needLabel)
|
|
{
|
|
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.Append("</div>");
|
|
}
|
|
sb.AppendFormat("<div class=\"{0} {1}\">", BootsrapHelper.GetSizeClasses(inputWidth, allSizeSame), customClass);
|
|
}
|
|
|
|
private static void AddRenderWithNameCloseingFrame(StringBuilder sb)
|
|
{
|
|
sb.Append("</div>");
|
|
}
|
|
}
|
|
}
|