コード例 #1
0
        public static MvcHtmlString ExtTextBoxAddOnForEnable <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                              Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, string target = null, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            //html.Add("readonly", true);
            var textBox = "<div class='input-group'>";

            textBox += htmlHelper.TextBoxFor(expression, html).ToString();
            if (addOn == CustomControlConstants.AddOn.Search)
            {
                textBox +=
                    "<span class='input-group-addon' style='cursor: pointer' data-toggle='modal' data-target='" + target + "'><i class='fa fa-search'></i></span>";
            }
            textBox += "</div>";
            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     textBox, expression));
        }
コード例 #2
0
        public static MvcHtmlString ExtEditorBasicFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, IEnumerable <TValue> > > expression, bool readOnly = false, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                                                        ? new RouteValueDictionary()
                                                        : new RouteValueDictionary(htmlAttributes);

            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>");
            if (readOnly)
            {
                stringBuilder.AppendLine(string.Format("CKEDITOR.replace('{0}', {{ customConfig: 'config-basic.js', readOnly: true }})", controlId));
            }
            else
            {
                stringBuilder.AppendLine(string.Format("CKEDITOR.replace('{0}', {{ customConfig: 'config-basic.js' }})", controlId));
            }

            stringBuilder.AppendLine("</script>");

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
コード例 #3
0
        public static MvcHtmlString ExtSingleSuggestionFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                            Expression <Func <TModel, TValue> > expression, SingleSuggestionOption 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(string.Format("$('#{0}').tokenInput('{1}',{{", controlId, option.SearchUrl));
            stringBuilder.AppendLine("theme: 'facebook',");
            stringBuilder.AppendLine("tokenLimit: 1,");
            stringBuilder.AppendLine("method: 'POST',");
            stringBuilder.AppendLine(string.Format("required: {0},", expression.IsRequired().ToString().ToLower()));
            stringBuilder.AppendLine("queryParam: 'query',");
            stringBuilder.AppendLine("tokenValue: 'Id',");
            stringBuilder.AppendLine("propertyToSearch: 'Name',");
            stringBuilder.AppendLine("minChars: 0,");
            if (option.DefaultValue != null)
            {
                stringBuilder.AppendLine(string.Format("prePopulate: [{0}],", Newtonsoft.Json.JsonConvert.SerializeObject(option.DefaultValue)));
            }

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

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

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

            if (!string.IsNullOrEmpty(option.OnResult))
            {
                stringBuilder.AppendLine(string.Format("onResult: {0},", option.OnResult));
            }

            stringBuilder.AppendLine("});});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
コード例 #4
0
        public static MvcHtmlString ExtDropDownListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                        Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList,
                                                                        string optionLabel = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.DropDownListFor(expression, selectList, optionLabel, html).ToString(), expression));
        }
コード例 #5
0
ファイル: ExtTextArea.cs プロジェクト: yongxiang-soh/iKCSP
        public static MvcHtmlString ExtTextAreaFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextAreaFor(expression, html).ToString(), expression));
        }
コード例 #6
0
        public static MvcHtmlString ExtTextBoxNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

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

            if (!string.IsNullOrEmpty(format))
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, format, html).ToString());
            }
            else
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            }

            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine("$('#" + controlId + "').keypress(function(event) {");
            // stringBuilder.AppendLine("var charCode = (event.which) ? event.which : event.keyCode;");
            stringBuilder.AppendLine("if (event.which != 8 && event.which != 0 && (event.which < 48 || event.which > 57)) {");
            stringBuilder.AppendLine("return false;");
            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("else {");
            stringBuilder.AppendLine("return true;");
            stringBuilder.AppendLine("};");
            stringBuilder.AppendLine("});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
コード例 #7
0
        public static MvcHtmlString ExtTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextBoxFor(expression, html).ToString(), expression));
        }
コード例 #8
0
        public static MvcHtmlString ExtNumberAddOnFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, String textAddOn = null, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group padding-right-8'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            switch (addOn)
            {
            case CustomControlConstants.AddOn.Text:
                stringBuilder.AppendLine(" <span class='input-group-addon'>" + textAddOn + "</span>");
                break;
            }
            stringBuilder.AppendLine("</div >");
            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(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
コード例 #9
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null, bool showmessage = true)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 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(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            if (showmessage)
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         stringBuilder.ToString(), expression));
            }
            else
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
        }