public static string RenderLabel(HtmlHelper html, BootstrapLabelModel model)
        {
            if (string.IsNullOrEmpty(model.htmlFieldName)) return null;

            string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);

            if (string.IsNullOrEmpty(model.labelText))
                model.labelText = model.metadata.DisplayName
                    ?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null)
                    ?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase();

            TagBuilder label = new TagBuilder("label");
            label.Attributes.Add("for", fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value.ToString() : string.Empty));
            label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());

            TagBuilder requiredSpan = new TagBuilder("span");
            requiredSpan.AddCssClass("required");
            requiredSpan.SetInnerText("*");
            if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) || (!model.showRequiredStar.HasValue && !model.metadata.IsRequired))
                requiredSpan.AddCssStyle("visibility", "hidden");

            if(model.innerInputType != BootstrapInputType._NotSet)
            {
                if(model.innerInputType == BootstrapInputType.CheckBox)
                {
                    label.AddOrMergeCssClass("checkbox");
                    BootstrapCheckBoxModel inputModel = (BootstrapCheckBoxModel)model.innerInputModel;
                    inputModel.displayValidationMessage = false;
                    model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput
                        ? Renderer.RenderCheckBoxCustom(html, inputModel)
                        : Renderer.RenderCheckBox(html, inputModel));
                    if(inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
                        label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
                }
                if(model.innerInputType == BootstrapInputType.Radio)
                {
                    label.AddOrMergeCssClass("radio");
                    BootstrapRadioButtonModel inputModel = (BootstrapRadioButtonModel)model.innerInputModel;
                    model.innerInput = MvcHtmlString.Create(Renderer.RenderRadioButton(html, inputModel));
                    if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
                        label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
                }
            }

            string innerinput = "";
            if (model.innerInput != null) innerinput = model.innerInput.ToHtmlString();

            label.InnerHtml = innerinput + model.labelText + requiredSpan.ToString() + model.innerValidationMessage;

            return label.ToString(TagRenderMode.Normal);
        }
        public static string RenderReadOnly(HtmlHelper html, BootstrapReadOnlyModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.Add("id", model.id);
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder)) model.htmlAttributes.Add("placeholder", model.placeholder);
            // build html for input

            string input = html.Hidden(model.htmlFieldName, model.value).ToHtmlString();

            if (model.value != null && model.value.GetType().IsEnum)
            {
                input =  input + ((Enum)model.value).GetEnumDescription();
            }
            else
            {
                input = input + html.Encode(model.value);

            }

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOnPrependString = "";
                var addOnAppendString = "";
                var addOnPrependButtons = "";
                var addOnAppendButtons = "";
                var addOnPrependIcon = "";
                var addOnAppendIcon = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";
            if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString();
        }
        public static HtmlString RenderSmartTable(SmartTableModel model)
        {
            var table = new TagBuilder("table");
            var html = new StringBuilder();

            if (!string.IsNullOrEmpty(model.name))
                model.htmlAttributes.AddOrReplace("id", model.name);

            if (!string.IsNullOrEmpty(model.toggle))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.toggle), model.toggle);

            if (!string.IsNullOrEmpty(model.url))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.url), model.url);

            if (!string.IsNullOrEmpty(model.sortField))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.sortField), model.sortField);

            if (!string.IsNullOrEmpty(model.sortDirection))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.sortDirection), model.sortDirection);

            if (!string.IsNullOrEmpty(model.rowStyle))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.rowStyle), model.rowStyle);

            if (!model.cache)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.cache), model.cache.ToString().ToLower());

            if (!model.showHeader)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.showHeader), model.showHeader.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.idField))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.idField), model.idField);

            if (model.cardView)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.cardView), model.cardView.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.responseHandler))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.responseHandler), model.responseHandler);

            if (model.clickToSelect)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.clickToSelect),
                    model.clickToSelect.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.selectItemName))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.selectItemName), model.selectItemName);

            if (model.singleSelect)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.singleSelect), model.singleSelect.ToString().ToLower());

            if (!model.sortable)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.sortable), model.sortable.ToString().ToLower());

            if (model.showFooter)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.showFooter), model.showFooter.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.undefinedText))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.undefinedText), model.undefinedText);

            if (!string.IsNullOrEmpty(model.iconsPrefix))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.iconsPrefix), model.iconsPrefix);

            if (!string.IsNullOrEmpty(model.icons))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.icons), model.icons);

            if (!model.checkboxHeader)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.checkboxHeader),
                    model.checkboxHeader.ToString().ToLower());

            if (model.detailView)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.detailView), model.detailView.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.detailFormatter))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.detailFormatter), model.detailFormatter);

            if (model.searchTimeOut != 500)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.searchTimeOut), model.searchTimeOut.ToString());

            if (model.strictSearch)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.strictSearch), model.strictSearch.ToString().ToLower());

            if (!model.searchText.Equals("''"))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.searchText), model.searchText);

            if (!model.trimOnSearch)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.trimOnSearch), model.trimOnSearch.ToString().ToLower());

            if (!model.smartDisplay)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.smartDisplay), model.smartDisplay.ToString().ToLower());

            if (!string.IsNullOrEmpty(model.uniqueId))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.uniqueId), model.uniqueId);

            if (model.toolbar != null)
            {
                if (model.toolbar.showColumns)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.showColumns),
                        model.toolbar.showColumns.ToString().ToLower());

                if (model.toolbar.showRefresh)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.showRefresh),
                        model.toolbar.showRefresh.ToString().ToLower());

                if (model.toolbar.showToggle)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.showToggle),
                        model.toolbar.showToggle.ToString().ToLower());

                if (model.toolbar.search)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.search),
                        model.toolbar.search.ToString().ToLower());

                if (!string.IsNullOrEmpty(model.toolbar.toolbar))
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.toolbar), model.toolbar.toolbar);

                if (model.toolbar.showPaginationSwitch)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.showPaginationSwitch),
                        model.toolbar.showPaginationSwitch.ToString().ToLower());

                if (model.toolbar.minimumCountColumns != 1)
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.minimumCountColumns),
                        model.toolbar.minimumCountColumns.ToString());

                if (!string.IsNullOrEmpty(model.toolbar.searchAlign))
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.searchAlign),
                        model.toolbar.searchAlign);

                if (!string.IsNullOrEmpty(model.toolbar.buttonsAlign))
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.buttonsAlign),
                        model.toolbar.buttonsAlign);

                if (!string.IsNullOrEmpty(model.toolbar.toolbarAlign))
                    model.htmlAttributes.AddOrReplace(model.toolbar.HtmlAttr(() => model.toolbar.toolbarAlign),
                        model.toolbar.toolbarAlign);
            }

            if (model.paging != null)
            {
                model.htmlAttributes.AddOrReplace(model.paging.HtmlAttr(() => model.paging.pagination),
                    model.paging.pagination.ToString().ToLower());
                model.htmlAttributes.AddOrReplace(model.paging.HtmlAttr(() => model.paging.sidePagination),
                    model.paging.sidePagination);
                model.htmlAttributes.AddOrReplace(model.paging.HtmlAttr(() => model.paging.pageList),
                    new JavaScriptSerializer().Serialize(model.paging.pageList));
                model.htmlAttributes.AddOrReplace(model.paging.HtmlAttr(() => model.paging.pageSize),
                    model.paging.pageSize.ToString());
                model.htmlAttributes.AddOrReplace(model.paging.HtmlAttr(() => model.paging.pageNumber),
                    model.paging.pageNumber.ToString());
            }

            if (model.dataSource != null)
            {
                if (!string.IsNullOrEmpty(model.dataSource.url))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.url), model.dataSource.url);

                if (!string.IsNullOrEmpty(model.dataSource.contentType))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.contentType),
                        model.dataSource.contentType);

                if (!string.IsNullOrEmpty(model.dataSource.dataType))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.dataType),
                        model.dataSource.dataType);

                if (!string.IsNullOrEmpty(model.dataSource.ajaxOptions))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.ajaxOptions),
                        model.dataSource.ajaxOptions);

                if (!string.IsNullOrEmpty(model.dataSource.queryParams))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.queryParams),
                        model.dataSource.queryParams);

                if (!string.IsNullOrEmpty(model.dataSource.queryParamsType))
                    model.htmlAttributes.AddOrReplace(model.dataSource.HtmlAttr(() => model.dataSource.queryParamsType),
                        model.dataSource.queryParamsType);
            }

            if (model.tableEvents.Any())
            {
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.tableEvents),
                    new JavaScriptSerializer().Serialize(model.tableEvents));
            }

            model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.height), model.height.ToString());

            //Create Table
            table.AddOrMergeCssClass("table");

            if (!string.IsNullOrEmpty(model.tableClass))
                table.AddOrMergeCssClass(model.tableClass);

            table.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());

            // Table header
            if (model.columns.Any())
            {
                html.Append(TableHeader(model.columns.ToList()));
                table.InnerHtml = html.ToString();
            }

            return new HtmlString(table.ToString());
        }
Example #4
0
        public static string RenderLabel(HtmlHelper html, BootstrapLabelModel model)
        {
            string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);

            if (string.IsNullOrEmpty(model.labelText))
            {
                model.labelText = model.metadata.DisplayName
                                  ?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null)
                                  ?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase();
            }

            TagBuilder label = new TagBuilder("label");

            label.Attributes.Add("for", fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value.ToString() : string.Empty));
            label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());

            TagBuilder requiredSpan = new TagBuilder("span");

            requiredSpan.AddCssClass("required");
            requiredSpan.SetInnerText("*");
            if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) || (!model.showRequiredStar.HasValue && !model.metadata.IsRequired))
            {
                requiredSpan.AddCssStyle("visibility", "hidden");
            }

            if (model.innerInputType != BootstrapInputType._NotSet)
            {
                if (model.innerInputType == BootstrapInputType.CheckBox)
                {
                    label.AddOrMergeCssClass("checkbox");
                    BootstrapCheckBoxModel inputModel = (BootstrapCheckBoxModel)model.innerInputModel;
                    inputModel.displayValidationMessage = false;
                    model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput
                        ? Renderer.RenderCheckBoxCustom(html, inputModel)
                        : Renderer.RenderCheckBox(html, inputModel));
                    if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
                    {
                        label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
                    }
                }
                if (model.innerInputType == BootstrapInputType.Radio)
                {
                    label.AddOrMergeCssClass("radio");
                    BootstrapRadioButtonModel inputModel = (BootstrapRadioButtonModel)model.innerInputModel;
                    model.innerInput = MvcHtmlString.Create(Renderer.RenderRadioButton(html, inputModel));
                    if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
                    {
                        label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
                    }
                }
            }

            string innerinput = "";

            if (model.innerInput != null)
            {
                innerinput = model.innerInput.ToHtmlString();
            }

            label.InnerHtml = innerinput + model.labelText + requiredSpan.ToString() + model.innerValidationMessage;

            return(label.ToString(TagRenderMode.Normal));
        }
        public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword)
        {
            if (model == null || string.IsNullOrEmpty(model.htmlFieldName)) return null;

            string combinedHtml = "{0}{1}{2}";

            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.Add("id", model.id);
            if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary());
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder)) model.htmlAttributes.Add("placeholder", model.placeholder);
            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));
            // build html for input
            var input = isPassword
                ? html.Password(model.htmlFieldName, model.value, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
                : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                TagBuilder appendPrependContainer = new TagBuilder("div");
                string addOnPrependString = "";
                string addOnAppendString = "";
                string addOnPrependButtons = "";
                string addOnAppendButtons = "";
                string addOnPrependIcon = "";
                string addOnAppendIcon = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            string validationMessage = "";
            if(model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return MvcHtmlString.Create(string.Format(combinedHtml, input, validationMessage, helpText)).ToString();
        }
Example #6
0
        public static string RenderCheckBoxCustom(HtmlHelper html, BootstrapCheckBoxModel model)
        {
            var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            if (model.tooltip != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            }

            ModelState modelState;

            if (html.ViewData.ModelState.TryGetValue(fullHtmlFieldName, out modelState))
            {
                if (modelState.Errors.Count > 0)
                {
                    model.htmlAttributes.AddOrMergeCssClass("class", "input-validation-error");
                }
                if (modelState.Value != null && ((string[])modelState.Value.RawValue).Contains("True"))
                {
                    model.isChecked = true;
                }
            }

            var checkBoxDiv = new TagBuilder("div");

            checkBoxDiv.MergeAttribute("class", "checkbox");

            var label = new TagBuilder("label");

            var input = html.CheckBox(model.htmlFieldName, model.isChecked, model.htmlAttributes).ToString();

            var span = new TagBuilder("span");

            span.MergeAttribute("class", "text");
            span.InnerHtml = !string.IsNullOrEmpty(model.metadata.DisplayName) ? model.metadata.DisplayName : model.text;

            label.InnerHtml       = input + span.ToString();
            checkBoxDiv.InnerHtml = label.ToString();

            var widthlg = "";

            if (model.InputWidthLg != 0)
            {
                var width = model.InputWidthLg.ToString();
                widthlg = " col-lg-" + width;
            }

            var widthMd = "";

            if (model.InputWidthMd != 0)
            {
                var width = model.InputWidthMd.ToString();
                widthMd = " col-md-" + width;
            }

            var widthSm = "";

            if (model.InputWidthSm != 0)
            {
                var width = model.InputWidthSm.ToString();
                widthSm = " col-sm-" + width;
            }

            var widthXs = "";

            if (model.InputWidthXs != 0)
            {
                var width = model.InputWidthXs.ToString();
                widthXs = " col-xs-" + width;
            }

            var offsetlg = "";

            if (model.InputOffsetLg != 0)
            {
                var offset = model.InputOffsetLg.ToString();
                offsetlg = " col-lg-offset-" + offset;
            }

            var offsetMd = "";

            if (model.InputOffsetMd != 0)
            {
                var offset = model.InputOffsetMd.ToString();
                offsetMd = " col-md-offset-" + offset;
            }

            var offsetSm = "";

            if (model.InputOffsetSm != 0)
            {
                var offset = model.InputOffsetSm.ToString();
                offsetSm = " col-sm-offset-" + offset;
            }

            var offsetXs = "";

            if (model.InputOffsetXs != 0)
            {
                var offset = model.InputOffsetXs.ToString();
                offsetXs = " col-xs-offset-" + offset;
            }

            checkBoxDiv.AddOrMergeCssClass(widthlg + widthMd + widthSm + widthXs);
            checkBoxDiv.AddOrMergeCssClass(offsetlg + offsetMd + offsetSm + offsetXs);


            return(checkBoxDiv.ToString());
        }
        public static HtmlString RenderDatePicker(HtmlHelper html, DatePickerModel model)
        {
            var combinedHtml = "{0}{1}{2}";
            var addOn = new TagBuilder("span");
            var container = new TagBuilder("div");
            var addOnPrependString = "";
            var addOnPrependIcon = "";
            var addOnAppendIcon = "";

            var htmlAttributes = new
            {
                @type = "text"
            }.ObjectToHtmlAttributesDictionary();

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
                model.htmlAttributes.Add("id", model.id);

            if (!string.IsNullOrEmpty(model.placeholder))
                model.htmlAttributes.Add("placeholder", model.placeholder);

            if (model.size != Size._NotSet)
                model.htmlAttributes.AddOrMergeCssClass("class", $"input-{model.size.ToName()}");

            model.htmlAttributes.AddOrMergeCssClass("class", "date-picker");
            model.htmlAttributes.AddOrMergeCssClass("class", "form-control");

            if (!string.IsNullOrEmpty(model.dateFormat))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.dateFormat), model.dateFormat);

            if (model.weekStart != 0)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.weekStart), model.weekStart.ToString());

            if(model.autoclose)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.autoclose), model.autoclose.ToString().ToLower());

            if(model.calendarWeeks)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.calendarWeeks), model.calendarWeeks.ToString().ToLower());

            if(model.clearBtn)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.clearBtn), model.clearBtn.ToString().ToLower());

            if(!string.IsNullOrEmpty(model.container))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.container), model.container);

            if(model.datesDisabled.Any())
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.datesDisabled), new JavaScriptSerializer().Serialize(model.datesDisabled));

            if(model.daysOfWeekDisabled.Any())
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.daysOfWeekDisabled), new JavaScriptSerializer().Serialize(model.daysOfWeekDisabled));

            if (model.daysOfWeekHighlighted.Any())
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.daysOfWeekHighlighted), new JavaScriptSerializer().Serialize(model.daysOfWeekHighlighted));

            if (!string.IsNullOrEmpty(model.defaultViewDate))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.defaultViewDate), model.defaultViewDate);

            if(model.disableTouchKeyboard)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.disableTouchKeyboard), model.disableTouchKeyboard.ToString().ToLower());

            if(!model.enableOnReadonly)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.enableOnReadonly), model.enableOnReadonly.ToString().ToLower());

            if (model.endDate != null)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.endDate), model.endDate.ToString());

            if(!model.forceParse)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.forceParse), model.forceParse.ToString().ToLower());

            if(model.immediateUpdates)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.immediateUpdates), model.immediateUpdates.ToString().ToLower());

            if (!model.keyboardNavigation)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.keyboardNavigation), model.keyboardNavigation.ToString().ToLower());

            if(!string.IsNullOrEmpty(model.language))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.language), model.language);

            if(model.multidate)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidate), model.multidate.ToString().ToLower());

            if(!string.IsNullOrEmpty(model.multidateSeparator))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidateSeparator), model.multidateSeparator);

            if(!string.IsNullOrEmpty(model.orientation))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.orientation), model.orientation);

            if(!model.showOnFocus)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.showOnFocus), model.showOnFocus.ToString().ToLower());

            if(model.startDate != null)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startDate), model.startDate.ToString());

            if(model.startView != 0)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startView), model.startView.ToString());

            if(!string.IsNullOrEmpty(model.title))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.title), model.title);

            if(!string.IsNullOrEmpty(model.todayBtn))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayBtn), model.todayBtn);

            if (model.todayHighlight)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayHighlight), model.todayHighlight.ToString().ToLower());

            if(model.toggleActive)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.toggleActive), model.toggleActive.ToString().ToLower());

            if(model.zIndexOffset != 10)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.zIndexOffset), model.zIndexOffset.ToString());

            htmlAttributes.MergeHtmlAttributes(model.htmlAttributes.FormatHtmlAttributes());

            var input = html.TextBox(model.htmlFieldName, model.value, model.format, htmlAttributes).ToHtmlString();

            container.AddOrMergeCssClass("input-group");
            //container.AddOrMergeCssClass("date-picker");
            addOn.AddCssClass("input-group-addon");

            addOn.InnerHtml = new Icon(Icons.Calendar, Size.Lg).ToHtmlString();
            addOnAppendIcon = addOn.ToString();

            if (!string.IsNullOrEmpty(model.prependString) || model.iconPrepend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass))
            {
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }

                if (model.iconPrepend != Icons._not_set)
                {
                    addOn.InnerHtml = new Icon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
            }

            container.InnerHtml = addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendIcon;
            combinedHtml = container.ToString(TagRenderMode.Normal) + "{1}{2}";

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            string htmlTextBox = string.Format(combinedHtml, input, helpText, validationMessage);

            TagBuilder inputWrapper = null;

            if (!string.IsNullOrEmpty(model.inputElementWrapper))
            {
                inputWrapper = new TagBuilder(model.inputElementWrapper);

                if (model.inputElementWrapperAttributes != null)
                    inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));

                inputWrapper.InnerHtml = htmlTextBox;
            }

            string htmlString = inputWrapper != null
                ? inputWrapper.ToString(TagRenderMode.Normal)
                : htmlTextBox;

            return new HtmlString(htmlString);
        }
        public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType)
        {
            string combinedHtml = "{0}{1}{2}";
            if (model.selectedValue != null)
            {
                foreach (var item in model.selectList)
                {
                    if (item.Value == model.selectedValue.ToString())
                        item.Selected = true;
                }
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);

            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));

            // build html for input
            string input = string.Empty;

            if(inputType == BootstrapInputType.DropDownList)
                input = html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            if(inputType == BootstrapInputType.ListBox)
                input = html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            TagBuilder appendPrependContainer = new TagBuilder("div");
            if (!string.IsNullOrEmpty(model.prependString) | !string.IsNullOrEmpty(model.appendString) | model.appendButtons.Count() > 0)
            {
                string addOnPrependString = "";
                string addOnAppendString = "";
                string addOnPrependButtons = "";
                string addOnAppendButtons = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.appendButtons).ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.prependButtons).ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            string validationMessage = "";
            if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                string validation = html.ValidationMessage((string)model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString();
        }
Example #9
0
        public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType)
        {
            if (model.selectList == null)
            {
                throw new Exception("The SelectList is null.");
            }
            string combinedHtml = "{0}{1}{2}";

            if (model.selectedValue != null)
            {
                foreach (var item in model.selectList)
                {
                    if (item.Value == model.selectedValue.ToString())
                    {
                        item.Selected = true;
                    }
                }
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            if (model.tooltip != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            }
            if (!string.IsNullOrEmpty(model.id))
            {
                model.htmlAttributes.AddOrReplace("id", model.id);
            }

            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));

            // build html for input
            string input = string.Empty;

            if (inputType == BootstrapInputType.DropDownList)
            {
                input = html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();
            }

            if (inputType == BootstrapInputType.ListBox)
            {
                input = html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();
            }

            // account for appendString, prependString, and AppendButtons
            TagBuilder appendPrependContainer = new TagBuilder("div");

            if (!string.IsNullOrEmpty(model.prependString) | !string.IsNullOrEmpty(model.appendString) | model.appendButtons.Count() > 0)
            {
                string addOnPrependString  = "";
                string addOnAppendString   = "";
                string addOnPrependButtons = "";
                string addOnAppendButtons  = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml    = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml   = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List <BootstrapButton>)model.appendButtons).ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List <BootstrapButton>)model.prependButtons).ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty;

            string validationMessage = "";

            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage((string)model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString());
        }
Example #10
0
        public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword)
        {
            if (model == null || string.IsNullOrEmpty(model.htmlFieldName))
            {
                return(null);
            }

            string combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
            {
                model.htmlAttributes.Add("id", model.id);
            }
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder))
            {
                model.htmlAttributes.Add("placeholder", model.placeholder);
            }
            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));
            // build html for input
            var input = isPassword
                ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
                : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                TagBuilder appendPrependContainer = new TagBuilder("div");
                string     addOnPrependString     = "";
                string     addOnAppendString      = "";
                string     addOnPrependButtons    = "";
                string     addOnAppendButtons     = "";
                string     addOnPrependIcon       = "";
                string     addOnAppendIcon        = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml    = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml   = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml  = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml  = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty;

            string validationMessage = "";

            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return(MvcHtmlString.Create(string.Format(combinedHtml, input, validationMessage, helpText)).ToString());
        }
Example #11
0
        public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            model.htmlAttributes.AddOrMergeCssClass("class", "form-control");
            if (!string.IsNullOrEmpty(model.id))
            {
                model.htmlAttributes.Add("id", model.id);
            }
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            if (model.tooltip != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            }
            if (model.typehead != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.typehead.ToDictionary(html));
            }
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder))
            {
                model.htmlAttributes.Add("placeholder", model.placeholder);
            }
            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));

            if (model.disabled)
            {
                model.htmlAttributes.Add("disabled", "disabled");
            }


            var widthlg = "";

            if (model.InputWidthLg != 0)
            {
                var width = model.InputWidthLg.ToString();
                widthlg = " col-lg-" + width;
            }

            var widthMd = "";

            if (model.InputWidthMd != 0)
            {
                var width = model.InputWidthMd.ToString();
                widthMd = " col-md-" + width;
            }

            var widthSm = "";

            if (model.InputWidthSm != 0)
            {
                var width = model.InputWidthSm.ToString();
                widthSm = " col-sm-" + width;
            }

            var widthXs = "";

            if (model.InputWidthXs != 0)
            {
                var width = model.InputWidthXs.ToString();
                widthXs = " col-xs-" + width;
            }

            var offsetlg = "";

            if (model.InputOffsetLg != 0)
            {
                var offset = model.InputOffsetLg.ToString();
                offsetlg = " col-lg-offset-" + offset;
            }

            var offsetMd = "";

            if (model.InputOffsetMd != 0)
            {
                var offset = model.InputOffsetMd.ToString();
                offsetMd = " col-md-offset-" + offset;
            }

            var offsetSm = "";

            if (model.InputOffsetSm != 0)
            {
                var offset = model.InputOffsetSm.ToString();
                offsetSm = " col-sm-offset-" + offset;
            }

            var offsetXs = "";

            if (model.InputOffsetXs != 0)
            {
                var offset = model.InputOffsetXs.ToString();
                offsetXs = " col-xs-offset-" + offset;
            }

            var widthoffset = widthlg + widthMd + widthSm + widthXs + offsetlg + offsetMd + offsetSm + offsetXs;

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                !string.IsNullOrEmpty(model.iconPrepend) ||
                !string.IsNullOrEmpty(model.iconAppend) ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass) ||
                !string.IsNullOrEmpty(widthoffset))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOnPrependString     = "";
                var addOnAppendString      = "";
                var addOnPrependButtons    = "";
                var addOnAppendButtons     = "";
                var addOnPrependIcon       = "";
                var addOnAppendIcon        = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("input-group-addon");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-group");
                    addOn.InnerHtml    = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-group");
                    addOn.InnerHtml   = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-group");
                    var span = new TagBuilder("span");
                    span.AddOrMergeCssClass("input-group-btn");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                    span.InnerHtml      = addOnPrependButtons;
                    addOnPrependButtons = span.ToString();
                }
                if (model.appendButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-group");
                    var span = new TagBuilder("span");
                    span.AddOrMergeCssClass("input-group-btn");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                    span.InnerHtml     = addOnAppendButtons;
                    addOnAppendButtons = span.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrepend))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-icon icon-left");
                    addOnPrependIcon = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).HtmlAttributes(new { @class = model.prependIconStyle }).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(model.iconAppend))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-icon icon-right");
                    addOnAppendIcon = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).HtmlAttributes(new { @class = model.appendIconStyle }).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml  = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.AddOrMergeCssClass(widthlg + widthMd + widthSm + widthXs);
                appendPrependContainer.AddOrMergeCssClass(offsetlg + offsetMd + offsetSm + offsetXs);

                switch (model.size)
                {
                case InputSize.XSmall:
                    appendPrependContainer.AddOrMergeCssClass("input-group-xs");
                    break;

                case InputSize.Small:
                    appendPrependContainer.AddOrMergeCssClass("input-group-sm");
                    break;

                case InputSize.Large:
                    appendPrependContainer.AddOrMergeCssClass("input-group-lg");
                    break;

                case InputSize.XLarge:
                    appendPrependContainer.AddOrMergeCssClass("input-group-xl");
                    break;
                }


                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnPrependIcon + addOnAppendString + addOnAppendIcon + addOnAppendButtons + "{1}";
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{2}";
            }

            // build html for input
            var input = isPassword
                    ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
                    : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();


            var helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty;

            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString());
        }
        public static HtmlString RenderSelectElement(HtmlHelper html, SelectElementModel model, InputType inputType)
        {
            var combinedHtml = "{0}{1}{2}";
            var input = string.Empty;

            if (model.selectedValue != null)
            {
                foreach (var item in model.selectList)
                {
                    if (item.Value == model.selectedValue.ToString())
                        item.Selected = true;
                }
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);

            if (model.size != Size._NotSet)
                model.htmlAttributes.AddOrMergeCssClass("class", $"input-{model.size.ToName()}");

            model.htmlAttributes.AddOrMergeCssClass("class", "form-control");

            // build html for input

            if (inputType == InputType.DropDownList)
                input =
                    html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel,
                        model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            if (inputType == InputType.ListBox)
                input =
                    html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons

            if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOn = new TagBuilder("span");

                var addOnPrependString = "";
                var addOnAppendString = "";
                var addOnPrependButtons = "";
                var addOnAppendButtons = "";

                appendPrependContainer.AddOrMergeCssClass("input-group");
                addOn.AddCssClass("input-group-addon");

                if (!string.IsNullOrEmpty(model.prependString))
                {
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.appendString))
                {
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString +
                                                   addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            var inputElement = string.Format(combinedHtml, input, helpText, validationMessage);

            TagBuilder inputWrapper = null;

            if (!string.IsNullOrEmpty(model.inputElementWrapper))
            {
                inputWrapper = new TagBuilder(model.inputElementWrapper);

                if (model.inputElementWrapperAttributes != null)
                    inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));

                inputWrapper.InnerHtml = inputElement;
            }

            var htmlString = inputWrapper != null
                ? inputWrapper.ToString(TagRenderMode.Normal)
                : inputElement;

            return new HtmlString(htmlString);
        }
        public static HtmlString RenderTextBox(HtmlHelper html, TextBoxModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
                model.htmlAttributes.Add("id", model.id);

            if (!string.IsNullOrEmpty(model.placeholder))
                model.htmlAttributes.Add("placeholder", model.placeholder);

            if (model.size != Size._NotSet)
                model.htmlAttributes.AddOrMergeCssClass("class", $"input-{model.size.ToName()}");

            model.htmlAttributes.AddOrMergeCssClass("class", "form-control");

            var input = isPassword
                ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
                : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes())
                    .ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString) ||
                model.iconPrepend != Icons._not_set
                || model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                var appendPrependContainer = new TagBuilder("div");
                appendPrependContainer.AddOrMergeCssClass("input-group");
                appendPrependContainer.AddOrMergeCssClass("mar-btm");

                var addOnPrependString = "";
                var addOnAppendString = "";
                var addOnPrependIcon = "";
                var addOnAppendIcon = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("input-group-addon");

                if (!string.IsNullOrEmpty(model.prependString))
                {
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.appendString))
                {
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }

                if (model.iconPrepend != Icons._not_set)
                {
                    addOn.InnerHtml = new Icon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }

                if (model.iconAppend != Icons._not_set)
                {
                    addOn.InnerHtml = new Icon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString +
                                                   addOnAppendIcon;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            var htmlTextBox = string.Format(combinedHtml, input, helpText, validationMessage);

            TagBuilder inputWrapper = null;

            if (!string.IsNullOrEmpty(model.inputElementWrapper))
            {
                inputWrapper = new TagBuilder(model.inputElementWrapper);

                if (model.inputElementWrapperAttributes != null)
                    inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));

                inputWrapper.InnerHtml = htmlTextBox;
            }

            var htmlString = inputWrapper != null
                ? inputWrapper.ToString(TagRenderMode.Normal)
                : htmlTextBox;

            return new HtmlString(htmlString);
        }
Example #14
0
        public static string RenderReadOnly(HtmlHelper html, BootstrapReadOnlyModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
            {
                model.htmlAttributes.Add("id", model.id);
            }
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            if (model.tooltip != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            }
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder))
            {
                model.htmlAttributes.Add("placeholder", model.placeholder);
            }
            // build html for input


            string input = html.Hidden(model.htmlFieldName, model.value).ToHtmlString();

            if (model.value != null && model.value.GetType().IsEnum)
            {
                input = input + ((Enum)model.value).GetEnumDescription();
            }
            else
            {
                input = input + html.Encode(model.value);
            }

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOnPrependString     = "";
                var addOnAppendString      = "";
                var addOnPrependButtons    = "";
                var addOnAppendButtons     = "";
                var addOnPrependIcon       = "";
                var addOnAppendIcon        = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml    = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml   = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml  = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml  = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            var helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty;

            var validationMessage = "";

            if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString());
        }