Exemplo n.º 1
0
        /// <summary>
        /// Retuns HTML5 input type based on BsControlType
        /// </summary>
        internal static string GetHtml5Type(this BsControlType bsType)
        {
            var html5Type = String.Empty;

            switch (bsType)
            {
            case BsControlType.TextBox:
                html5Type = "text";
                break;

            case BsControlType.Password:
                html5Type = "password";
                break;

            case BsControlType.Number:
                html5Type = "number";
                break;

            case BsControlType.Url:
                html5Type = "url";
                break;

            case BsControlType.DatePicker:
                html5Type = "datetime";
                break;

            case BsControlType.TimePicker:
                html5Type = "time";
                break;

            case BsControlType.Email:
                html5Type = "email";
                break;

            case BsControlType.Upload:
                html5Type = "file";
                break;

            case BsControlType.CheckBox:
                html5Type = "checkbox";
                break;

            case BsControlType.RadioButton:
                html5Type = "radio";
                break;

            case BsControlType.ColorPicker:
                html5Type = "color";
                break;
            }

            return(html5Type);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns an input element based on BsControlType with placeholder and info tooltip
 /// </summary>
 public static MvcHtmlString BsInputFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                            Expression <Func <TModel, TProperty> > expression, BsControlType controlType, object htmlAttributes, object dataOptions)
 {
     return(BsInputFor(htmlHelper, expression, controlType, null,
                       HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes),
                       HtmlHelper.AnonymousObjectToHtmlAttributes(dataOptions)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns an input element with placeholder and info tooltip
 /// </summary>
 public static MvcHtmlString BsInputFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                            Expression <Func <TModel, TProperty> > expression, BsControlType controlType)
 {
     return(BsInputFor(htmlHelper, expression, controlType, null, null, null));
 }
Exemplo n.º 4
0
        public static MvcHtmlString BsInput <TProperty>(this HtmlHelper htmlHelper, BsControlType controlType,
                                                        string name, string format, string value,
                                                        IDictionary <string, object> htmlAttributes,
                                                        IDictionary <string, object> dataOptions,
                                                        ModelMetadata metadata = null)
        {
            var inputHtml = new MvcHtmlString("");

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            if (dataOptions == null)
            {
                dataOptions = new Dictionary <string, object>();
            }

            //add html attributes
            htmlAttributes.ApplyBFormsAttributes(metadata, dataOptions);

            //set html5 input type based on BsControlType attribute

            htmlAttributes.MergeAttribute("type", controlType.GetHtml5Type(), true);
            htmlAttributes.MergeAttribute("class", controlType.GetDescription());


            switch (controlType)
            {
            case BsControlType.TextBox:
                inputHtml = htmlHelper.TextBoxInternal(name, value, format, htmlAttributes);
                break;

            case BsControlType.TextArea:
                inputHtml = htmlHelper.TextAreaInternal(name, value, 2, 20, htmlAttributes);
                break;

            case BsControlType.Password:
                inputHtml = htmlHelper.PasswordInternal(name, value, htmlAttributes);
                break;

            case BsControlType.Url:
            case BsControlType.Email:
            case BsControlType.Number:
            case BsControlType.NumberInline:
                var genericArguments = typeof(TProperty).GetGenericArguments();

                if (genericArguments.Any() && (genericArguments[0] == typeof(int) || genericArguments[0] == typeof(int?)))
                {
                    htmlAttributes.MergeAttribute("class",
                                                  controlType == BsControlType.NumberInline
                                ? "bs-number-single_range_inline"
                                : "bs-number-single_range");
                    htmlAttributes.MergeAttribute("type", "text");

                    if (genericArguments[0] == typeof(int))
                    {
                        // var numberRange = (Expression<Func<TModel, BsRangeItem<int>>>)(object)expression;
                        // inputHtml = htmlHelper.NumberRangeForInternal(numberRange, htmlAttributes, dataOptions);
                    }
                    else
                    {
                        //  var numberRange = (Expression<Func<TModel, BsRangeItem<int?>>>)(object)expression;
                        //  inputHtml = htmlHelper.NumberRangeForInternal(numberRange, htmlAttributes, dataOptions);
                    }
                }
                else
                {
                    inputHtml = htmlHelper.TextBoxInternal(name, value, format, htmlAttributes);
                }

                break;

            case BsControlType.DatePicker:
            case BsControlType.DateTimePicker:
            case BsControlType.TimePicker:
                if (typeof(TProperty) != typeof(BsDateTime))
                {
                    throw new ArgumentException("The " + name + " property must be of type BsDateTime");
                }
                //var dateExpression = (Expression<Func<TModel, BsDateTime>>)(object)expression;
                //inputHtml = htmlHelper.DateTimeForInternal(dateExpression, htmlAttributes, dataOptions);
                break;

            default:
                throw new ArgumentException("The " + name + " of type " + controlType.GetDescription() + " does not match an input element");
            }


            //add info tooltip
            var description = new MvcHtmlString("");

            if (!string.IsNullOrEmpty(metadata.Description))
            {
                // description = htmlHelper.BsDescriptionFor(expression);
            }

            return(MvcHtmlString.Create(inputHtml.ToHtmlString() + description.ToHtmlString()));
        }
Exemplo n.º 5
0
        public static MvcHtmlString BsInputFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TProperty> > expression, BsControlType controlType, string format,
                                                                   IDictionary <string, object> htmlAttributes,
                                                                   IDictionary <string, object> dataOptions)
        {
            var inputHtml = new MvcHtmlString("");
            var metadata  = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            var name      = ExpressionHelper.GetExpressionText(expression);

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            if (dataOptions == null)
            {
                dataOptions = new Dictionary <string, object>();
            }

            //add html attributes
            htmlAttributes.ApplyBFormsAttributes(metadata, dataOptions);

            htmlAttributes.MergeAttribute("type", controlType.GetHtml5Type(), true);
            htmlAttributes.MergeAttribute("class", controlType.GetDescription());

            switch (controlType)
            {
            case BsControlType.TextBox:
                inputHtml = htmlHelper.TextBoxForInternal(expression, format, htmlAttributes);
                break;

            case BsControlType.TextArea:
                inputHtml = htmlHelper.TextAreaForInternal(expression, 2, 20, htmlAttributes);
                break;

            case BsControlType.Password:
                inputHtml = htmlHelper.PasswordFor(expression, htmlAttributes);
                break;

            case BsControlType.Url:
            case BsControlType.Email:
            case BsControlType.Number:
            case BsControlType.NumberInline:
                var genericArguments = typeof(TProperty).GetGenericArguments();

                if (genericArguments.Any() && (genericArguments[0] == typeof(int) || genericArguments[0] == typeof(int?)))
                {
                    htmlAttributes.MergeAttribute("class",
                                                  controlType == BsControlType.NumberInline
                                ? "bs-number-single_range_inline"
                                : "bs-number-single_range");
                    htmlAttributes.MergeAttribute("type", "text");

                    if (genericArguments[0] == typeof(int))
                    {
                        var numberRange = (Expression <Func <TModel, BsRangeItem <int> > >)(object) expression;
                        inputHtml = htmlHelper.NumberRangeForInternal(numberRange, htmlAttributes, dataOptions);
                    }
                    else
                    {
                        var numberRange = (Expression <Func <TModel, BsRangeItem <int?> > >)(object) expression;
                        inputHtml = htmlHelper.NumberRangeForInternal(numberRange, htmlAttributes, dataOptions);
                    }
                }
                else
                {
                    inputHtml = htmlHelper.TextBoxForInternal(expression, format, htmlAttributes);
                }

                break;

            case BsControlType.DatePicker:
            case BsControlType.DateTimePicker:
            case BsControlType.TimePicker:
                if (typeof(TProperty) != typeof(BsDateTime))
                {
                    throw new ArgumentException("The " + name + " property must be of type BsDateTime");
                }
                var dateExpression = (Expression <Func <TModel, BsDateTime> >)(object) expression;
                inputHtml = htmlHelper.DateTimeForInternal(dateExpression, htmlAttributes, dataOptions);
                break;

            case BsControlType.CheckBox:
                if (typeof(TProperty) != typeof(bool))
                {
                    throw new ArgumentException("The " + name + " property must be of type bool");
                }
                var checkExpression = (Expression <Func <TModel, bool> >)(object) expression;
                inputHtml = htmlHelper.CheckBoxForInternal(checkExpression, htmlAttributes);
                break;

            case BsControlType.RadioButton:
                if (typeof(TProperty) != typeof(bool))
                {
                    throw new ArgumentException("The " + name + " property must be of type bool");
                }
                var radioExpression = (Expression <Func <TModel, bool> >)(object) expression;
                inputHtml = htmlHelper.RadioButtonForInternal(radioExpression, htmlAttributes);
                break;

            case BsControlType.ColorPicker:
                inputHtml = htmlHelper.TextBoxForInternal(expression, format, htmlAttributes);
                break;

            case BsControlType.Upload:
                inputHtml = htmlHelper.UploadForInternal(expression, format, htmlAttributes);
                break;

            default:
                throw new ArgumentException("The " + name + " property of type " + controlType.GetDescription() + " does not match an input element");
            }

            //add info tooltip
            var description = new MvcHtmlString("");

            if (!string.IsNullOrEmpty(metadata.Description))
            {
                description = htmlHelper.BsDescriptionFor(expression);
            }

            return(MvcHtmlString.Create(inputHtml.ToHtmlString() + description.ToHtmlString()));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Specifies the name of an BFroms control type to associate with an input HTML field
 /// </summary>
 public BsControlAttribute(BsControlType controlType)
 {
     ControlType = controlType;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Specifies the name of an BFroms control type to associate with an input HTML field
 /// </summary>
 public BsControlAttribute(BsControlType controlType)
 {
     ControlType = controlType;
 }
Exemplo n.º 8
0
 public static MvcHtmlString BsRadioList <TKey>(this HtmlHelper htmlHelper, BsSelectList <TKey> radioList, BsControlType controlType, string name, IDictionary <string, object> htmlAttributes, bool allowMultiple, ModelMetadata metadata = null)
 {
     return(BsRadioListInternal(htmlHelper, name, radioList, htmlAttributes, allowMultiple, controlType.GetDescription(), metadata));
 }
Exemplo n.º 9
0
 public static MvcHtmlString BsTagList <TKey>(this HtmlHelper helper, BsSelectList <TKey> selectList, BsControlType controlType, string name, Dictionary <string, object> htmlAttributes, ModelMetadata metadata = null)
 {
     return(BsTagListInternal(helper, name, selectList, null, htmlAttributes, controlType.GetDescription(), null));
 }