Exemplo n.º 1
0
        public string RenderBsLabel <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var labelBuilder = new TagBuilder("label");
            var name         = propertyMetadata.PropertyInfo.Name;
            var displayName  = propertyMetadata.DisplayAttribute.Name;

            switch (propertyMetadata.BsControlAttribute.ControlType)
            {
            case BsControlType.DropDownList:
            case BsControlType.ListBox:
            case BsControlType.TagList:
            {
                name = name + ".SelectedValues";

                break;
            }

            default:
            {
                break;
            }
            }

            var id = GetIdAttributeFromName(name);

            labelBuilder.AddCssClass("control-label " + (propertyMetadata.RequiredAttribute != null ? "required" : ""));
            labelBuilder.MergeAttribute("for", id);

            labelBuilder.InnerHtml = displayName;

            return(labelBuilder.ToString());
        }
Exemplo n.º 2
0
        public string RenderFormGroup <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var controlHtml = RenderFormControl(propertyMetadata, formModel);

            var formGroupBuilder  = new TagBuilder("div");
            var inputGroupBuilder = new TagBuilder("div");

            var width = propertyMetadata.FormGroupAttribute != null
                ? propertyMetadata.FormGroupAttribute.Width
                : ColumnWidth.Large;

            formGroupBuilder.AddCssClass("form-group " + width.GetDescription());
            inputGroupBuilder.AddCssClass("input-group");

            var glyphiconAddonHtml = String.Empty;

            if (propertyMetadata.FormGroupAttribute != null && propertyMetadata.FormGroupAttribute.GlyphiconAddon != Glyphicon.Custom)
            {
                var glyphicon = propertyMetadata.FormGroupAttribute.GlyphiconAddon;

                var glyphiconAddonbuilder = new TagBuilder("span");

                glyphiconAddonbuilder.AddCssClass("input-group-addon glyphicon " + glyphicon.GetDescription());

                glyphiconAddonHtml = glyphiconAddonbuilder.ToString();
            }

            inputGroupBuilder.InnerHtml = glyphiconAddonHtml + controlHtml;
            formGroupBuilder.InnerHtml  = RenderBsLabel(propertyMetadata, formModel) + inputGroupBuilder.ToString();

            return(formGroupBuilder.ToString());
        }
Exemplo n.º 3
0
        public string RenderBsDropdown <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var selectBuilder = GetBsSelectTagBuilder(propertyMetadata, formModel);

            selectBuilder.AddCssClass("bs-dropdown");

            return(selectBuilder.ToString());
        }
Exemplo n.º 4
0
        public string RenderBsTagList <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var selectBuilder = GetBsSelectTagBuilder(propertyMetadata, formModel);

            selectBuilder.AddCssClass("bs-tag-list");
            selectBuilder.MergeAttribute("style", "display:none;");

            return(selectBuilder.ToString());
        }
Exemplo n.º 5
0
        public string RenderRadioButtonList <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel, object value = null)
        {
            var controlValue = value ?? propertyMetadata.PropertyInfo.GetValue(formModel);

            var bsSelectlistItems = controlValue.GetType().GetProperty("Items").GetValue(controlValue, null) as List <BsSelectListItem>;

            var selectedValues = controlValue.GetType().GetProperty("SelectedValues").GetValue(controlValue, null) as string;

            var bsSelectList = new BsSelectList <string>
            {
                Items          = bsSelectlistItems,
                SelectedValues = selectedValues
            };

            return(_helper.BsRadioList <string>(bsSelectList, propertyMetadata.BsControlAttribute.ControlType, propertyMetadata.PropertyInfo.Name, null, false).ToString());
        }
Exemplo n.º 6
0
        public TagBuilder GetBsSelectTagBuilder <TFormModel>(FormControlPropertyMetadata propertyMetadata,
                                                             TFormModel formModel)
        {
            var bsSelectListItems = GetBsSelectListItems(propertyMetadata, formModel);

            var selectBuilder = new TagBuilder("select");

            selectBuilder.AddCssClass("form-control bs-hasBformsSelect");

            foreach (var bsSelectListItem in bsSelectListItems)
            {
                var optionBuilder = new TagBuilder("option");

                optionBuilder.MergeAttribute("value", bsSelectListItem.Value);
                optionBuilder.InnerHtml = bsSelectListItem.Text;

                selectBuilder.InnerHtml += optionBuilder.ToString();
            }

            return(selectBuilder);
        }
Exemplo n.º 7
0
        private List <BsSelectListItem> GetBsSelectListItems <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var controlValue = propertyMetadata.PropertyInfo.GetValue(formModel);

            var bsSelectlistItems = controlValue.GetType().GetProperty("Items").GetValue(controlValue, null) as List <BsSelectListItem>;

            var selectedValues = controlValue.GetType().GetProperty("SelectedValues").GetValue(controlValue, null) as List <object>;

            var selectedValuesStrings = selectedValues != null
                ? selectedValues.Select(x => x.ToString())
                : new List <string>();

            var items = bsSelectlistItems != null
                ? bsSelectlistItems.Select(x => new BsSelectListItem
            {
                Text     = x.Text,
                Value    = x.Value,
                Selected = selectedValuesStrings.Contains(x.Value)
            })
                : new List <BsSelectListItem>();

            return(items.ToList());
        }
Exemplo n.º 8
0
        public string RenderBsNumberPickerInline <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var controlName  = propertyMetadata.PropertyInfo.Name;
            var controlId    = GetIdAttributeFromName(controlName);
            var controlValue = propertyMetadata.PropertyInfo.GetValue(formModel);

            var textInputBuilder   = new TagBuilder("input");
            var numberInputBuilder = new TagBuilder("input");

            textInputBuilder.AddCssClass("form-control bs-number-inline bs-number-single_range_inline");
            textInputBuilder.MergeAttribute("name", controlName + ".TextValue");
            textInputBuilder.MergeAttribute("id", controlId + "_TextValue");
            textInputBuilder.MergeAttribute("type", "text");
            textInputBuilder.MergeAttribute("value", controlValue.ToString());

            numberInputBuilder.AddCssClass("bs-number-value");
            numberInputBuilder.MergeAttribute("data-for", controlName + ".TextValue");
            numberInputBuilder.MergeAttribute("name", controlName + ".ItemValue");
            numberInputBuilder.MergeAttribute("id", controlId + "_ItemValue");
            numberInputBuilder.MergeAttribute("type", "hidden");
            numberInputBuilder.MergeAttribute("value", controlValue.ToString());

            return(textInputBuilder.ToString() + numberInputBuilder.ToString());
        }
Exemplo n.º 9
0
        internal string RenderFormControl <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel)
        {
            var controlString = String.Empty;

            var bsControlType = propertyMetadata.BsControlAttribute.ControlType;

            var controlName     = propertyMetadata.PropertyInfo.Name;
            var controlId       = GetIdAttributeFromName(controlName);
            var controlValue    = propertyMetadata.PropertyInfo.GetValue(formModel);
            var isRequired      = propertyMetadata.RequiredAttribute != null;
            var requiredMessage = isRequired ? propertyMetadata.RequiredAttribute.ErrorMessage : String.Empty;

            switch (bsControlType)
            {
            case BsControlType.TextBox:
            {
                controlString = _helper.BsTextBox(controlName, controlValue).ToString();

                break;
            }

            case BsControlType.TextArea:
            {
                controlString = _helper.BsTextArea(controlName, controlValue).ToString();

                break;
            }

            case BsControlType.DropDownList:
            {
                controlString = RenderBsDropdown(propertyMetadata, formModel);

                break;
            }

            case BsControlType.ListBox:
            {
                controlString = RenderBsListBox(propertyMetadata, formModel);

                break;
            }

            case BsControlType.TagList:
            {
                controlString = RenderBsTagList(propertyMetadata, formModel);

                break;
            }

            case BsControlType.RadioButtonList:
            {
                controlString = RenderRadioButtonList(propertyMetadata, formModel);

                break;
            }

            case BsControlType.NumberInline:
            {
                controlString = RenderBsNumberPickerInline(propertyMetadata, formModel);

                break;
            }

            default:
            {
                break;
            }
            }

            return(controlString);
        }