Esempio n. 1
0
        public static MvcHtmlString ExtDisplayNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > expression, NumberOptionLarge option = null, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.ExtDisplayWidthId(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            if (html.ContainsKey("id"))
            {
                var tempId = html["id"].ToString();
                if (!string.IsNullOrEmpty(tempId))
                {
                    controlId = tempId;
                }
            }
            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add($"vMin: '{option.Min.Value}'");
                }
                if (option.Max.HasValue)
                {
                    options.Add($"vMax: '{option.Max.Value}'");
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add($"aSign: '{option.ASign}'");
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add($"pSign: '{option.PSign}'");
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add($"mDec : {option.NumberOfDecimal.Value}");
                }
                if (!option.APad)
                {
                    options.Add($"aPad : {Convert.ToBoolean("false")}");
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine($"$('#{controlId}').autoNumeric('init', {{{optionsStr}}});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Esempio n. 2
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            html = HtmlAttributeHelper.AddMaxLength(html, maxLength != 0 ? maxLength : 255);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ''",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add($"vMin: '{option.Min.Value}'");
                }
                if (option.Max.HasValue)
                {
                    options.Add($"vMax: '{option.Max.Value}'");
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add($"aSign: '{option.ASign}'");
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add($"pSign: '{option.PSign}'");
                }
                if (!string.IsNullOrEmpty(option.MRound))
                {
                    options.Add($"mRound: '{option.MRound}'");
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add($"mDec : {option.NumberOfDecimal.Value}");
                }
                if (!option.APad)
                {
                    options.Add("aPad : false");
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine($"$('#{controlId}').autoNumeric('init', {{{optionsStr}}});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Esempio n. 3
0
        public static MvcHtmlString ExtDisplayWidthId <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var spanBuilder = new TagBuilder("span");
            var controlId   = HtmlAttributeHelper.GetControlIdFromExpression(expression);
            var htmlAttributesDictionary = htmlAttributes as RouteValueDictionary;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("id"))
            {
                var tempId = htmlAttributesDictionary["id"].ToString();
                if (!string.IsNullOrEmpty(tempId))
                {
                    controlId = tempId;
                }
            }
            var style = string.Empty;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("style"))
            {
                var tempStyle = htmlAttributesDictionary["style"].ToString();
                if (!string.IsNullOrEmpty(tempStyle))
                {
                    style = tempStyle;
                }
            }
            var cssClass = string.Empty;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("class"))
            {
                var tempClass = htmlAttributesDictionary["class"].ToString();
                if (!string.IsNullOrEmpty(tempClass))
                {
                    cssClass = tempClass;
                }
            }
            if (!string.IsNullOrEmpty(cssClass))
            {
                spanBuilder.AddCssClass(cssClass);
            }
            spanBuilder.MergeAttribute("id", controlId);
            spanBuilder.MergeAttribute("style",
                                       !string.IsNullOrEmpty(style) ? style : "display: block;text-align: right");

            spanBuilder.SetInnerText(htmlHelper.DisplayFor(expression, htmlAttributes).ToString());

            return(new MvcHtmlString(spanBuilder.ToString()));
        }
Esempio n. 4
0
        public static MvcHtmlString ExtEditorFullFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                      Expression <Func <TModel, IEnumerable <TValue> > > expression, bool readOnly = false, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextAreaFor(expression, html).ToString());


            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>");
            stringBuilder.AppendLine(readOnly
                ? $"CKEDITOR.replace('{controlId}', {{ readOnly: true }})"
                : $"CKEDITOR.replace('{controlId}')");
            stringBuilder.AppendLine("</script>");

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Esempio n. 5
0
        public static MvcHtmlString ExtDateTimeFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, DateTimeOption option = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            // html.Add("onkeydown", "return false");
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            var controlId     = HtmlAttributeHelper.GetControlIdFromExpression(expression);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group date ' id='dv" + controlId + "'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());



            var options = new List <string>();

            if (option != null)
            {
                if (!string.IsNullOrEmpty(option.ViewMode))
                {
                    options.Add(string.Format("viewMode: '{0}'", option.ViewMode));
                }
                if (!string.IsNullOrEmpty(option.Format))
                {
                    options.Add(string.Format("format: '{0}'", option.Format));
                    if (option.Format == "LT" || option.Format == "HH:mm" || option.Format == "HH:mm:ss")
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span>");
                    }
                    else
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>");
                    }
                }
                if (option.DaysOfWeekDisabled != null)
                {
                    options.Add(string.Format("daysOfWeekDisabled: {0}", option.DaysOfWeekDisabled));
                }
                if (!string.IsNullOrEmpty(option.MinDate))
                {
                    options.Add(string.Format("minDate: {0}", option.MinDate));
                }
                else
                {
                    options.Add(string.Format("minDate: {0}", " moment('01/01/1990')"));
                }
                if (!string.IsNullOrEmpty(option.MaxDate))
                {
                    options.Add(string.Format("maxDate: {0}", option.MaxDate));
                }
                if (option.EnabledHours.HasValue)
                {
                    options.Add(string.Format("enabledHours : '{0}'", option.EnabledHours.Value));
                }
                if (option.ViewDate.HasValue)
                {
                    options.Add(string.Format("viewDate : {0}", option.ViewDate.Value));
                }
                if (option.Inline.HasValue)
                {
                    options.Add(string.Format("inline : {0}", option.Inline.Value));
                }
                // options.Add(string.Format("defaultDate:{0}", DateTime.Now.ToString("d")));
            }
            stringBuilder.AppendLine("</div><script>$(function(){");
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#dv{0}').datetimepicker( {{{1}}});", controlId, optionsStr));
            //stringBuilder.AppendLine(string.Format("$('#{0}').datetimepicker('setDate',{1});", controlId,string.Format( "$('#{0}').val()",controlId)));
            stringBuilder.AppendLine("});</script>");

            if (option != null && option.IsValidationMessageSupported)
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Esempio n. 6
0
        public static MvcHtmlString ExtMultiSuggestionFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                           Expression <Func <TModel, TValue> > expression, MultiSuggestionOption option, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine($"$('#{controlId}').tokenInput('{option.SearchUrl}',{{");
            stringBuilder.AppendLine("theme: 'facebook',");
            if (option.LimitedItem != 0)
            {
                stringBuilder.AppendLine($"tokenLimit: {option.LimitedItem},");
            }
            stringBuilder.AppendLine("method: 'POST',");
            stringBuilder.AppendLine("queryParam: 'query',");
            stringBuilder.AppendLine("tokenValue: 'Id',");
            stringBuilder.AppendLine($"required: {expression.IsRequired().ToString().ToLower()},");
            stringBuilder.AppendLine("propertyToSearch: 'Name',");
            stringBuilder.AppendLine("preventDuplicates: true,");
            stringBuilder.AppendLine("minChars: " + option.MinChars + ",");
            if (option.DefaultValues != null)
            {
                stringBuilder.AppendLine(
                    $"prePopulate: {JsonConvert.SerializeObject(option.DefaultValues).Replace("/", "\\/")},");
            }

            if (!string.IsNullOrEmpty(option.OnAdd))
            {
                stringBuilder.AppendLine($"onAdd: {option.OnAdd},");
            }

            if (!string.IsNullOrEmpty(option.OnDelete))
            {
                stringBuilder.AppendLine($"onDelete: {option.OnDelete},");
            }

            if (!string.IsNullOrEmpty(option.AdditionalParam))
            {
                stringBuilder.AppendLine($"additionalParam: {option.AdditionalParam},");
            }
            if (option.LocalData != null)
            {
                stringBuilder.AppendLine(
                    $"local_data: {JsonConvert.SerializeObject(option.LocalData)},");
            }
            if (option.CreateNew.HasValue)
            {
                stringBuilder.AppendLine($"createNew: {option.CreateNew.Value.ToString().ToLower()},");
            }
            if (!string.IsNullOrEmpty(option.OnResult))
            {
                stringBuilder.AppendLine($"onResult: {option.OnResult},");
            }

            stringBuilder.AppendLine("});});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }