Example #1
0
        public EditorTableBuilder <TModel> WithHiddenFor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField = true)
        {
            var editorHtml    = htmlHelper.HiddenFor(expression);
            var fieldEditorTd = new FluentTagBuilder("td")
                                .AddToInnerHtml(editorHtml.ToHtmlString());

            var editorRow = new FluentTagBuilder("tr")
                            .AddAttribute("style", "display: none")
                            .AddToInnerHtml(fieldEditorTd);

            fluentTagBuilder.AddToInnerHtml(editorRow);
            return(this);
        }
Example #2
0
        public IHtmlString WithFilterButton(bool inSeparateRow = false, string filterFunction = "RefreshGrid", bool useUnobtrusive = false, string filterButtonLabel = null)
        {
            var filterButton = useUnobtrusive
                                   ? htmlHelper.UnobtrusiveFilterButton(filterButtonLabel).ToHtmlString()
                                   : htmlHelper.FilterButton(string.Format("{0}()", filterFunction), filterButtonLabel).ToHtmlString();
            var filterButtonBuilder = new FluentTagBuilder("td").AddToInnerHtml(filterButton);

            if (inSeparateRow)
            {
                if (lastRowBuilder != null)
                {
                    fluentTagBuilder.AddToInnerHtml(lastRowBuilder.AddToInnerHtml(emptyCellBuilder.ToString()));
                }
                var filterRow = new FluentTagBuilder("tr");
                filterRow
                .AddToInnerHtml(emptyCellBuilder.ToString())
                .AddToInnerHtml(filterButtonBuilder.AddAttribute("style", "text-align:right").ToString())
                .AddToInnerHtml(emptyCellBuilder.ToString());
                fluentTagBuilder.AddToInnerHtml(filterRow);
                return(this);
            }

            if (lastRowBuilder != null)
            {
                lastRowBuilder.AddToInnerHtml(filterButtonBuilder.ToString());
                fluentTagBuilder.AddToInnerHtml(lastRowBuilder);
                return(this);
            }

            return(this);
        }
Example #3
0
        public ITextFilterBuilder <TModel> WithTextFilter <TValue>(Expression <Func <TModel, TValue> > expression, bool triggerOn3Char = false, bool notLastRow = false, int width = 198)
        {
            var textEditor = htmlHelper.TextBox(ExpressionHelper.GetExpressionText(expression), null, new { onkeyup = (triggerOn3Char? TriggerFilterOn3Char : TriggerFilterOnEnter), @class = kendoClasses, style = string.Format("width: {0}px", width) });

            if (lastRowBuilder != null)
            {
                fluentTagBuilder.AddToInnerHtml(lastRowBuilder.AddToInnerHtml(emptyCellBuilder.ToString()));
            }

            if (notLastRow)
            {
                fluentTagBuilder.AddToInnerHtml(BuildRowWithLabel(expression, textEditor.ToHtmlString()));
            }
            else
            {
                lastRowBuilder = BuildRowWithLabel(expression, textEditor.ToHtmlString());
            }
            return(this);
        }
Example #4
0
        public GridFilterBuilder <TModel> WithEnumFilter <TValue, TEnum>(Expression <Func <TModel, TValue> > expression, int width = 200, string filterFunction = "RefreshGrid")
            where TEnum : struct
        {
            var enumEditor = htmlHelper.EnumDropDownList <TEnum>(ExpressionHelper.GetExpressionText(expression),
                                                                 emptyText: TextLocalization.All,
                                                                 customize: b => b.HtmlAttributes(GetDropDownHtmlAttributes(width)).Events(events => events.Change(filterFunction)));
            var buildRowWithLabel = BuildRowWithLabel(expression, enumEditor.ToHtmlString(), true, true);

            buildRowWithLabel.AddToInnerHtml(emptyCellBuilder.ToString());
            fluentTagBuilder.AddToInnerHtml(buildRowWithLabel);
            return(this);
        }
Example #5
0
        private void BuildEditor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField, string editorString, string validationMessageHtml, string editorPostfix = null, bool visible = true, string customLabel = null, bool isDropDown = false)
        {
            int editorRightPadding = isDropDown ? 0 : 5;

            if (editorString.Contains("kendo"))
            {
                editorString = editorString.Replace("198px;", "200px;");
            }

            var fieldLabelTd = new FluentTagBuilder("td")
                               .AddToInnerHtml(customLabel.HasText() ? customLabel : htmlHelper.LocalizedLabelFor(expression).ToString())
                               .AddCssClass("field-label");

            if (fieldLabelWidth.HasValue)
            {
                fieldLabelTd.AddAttribute("style", string.Format("min-width: {0}px; max-width: {0}px", fieldLabelWidth));
            }

            if (requiredField)
            {
                fieldLabelTd.AddCssClass("field-required");
            }

            var fieldEditorTd = new FluentTagBuilder("td")
                                .AddToInnerHtml(editorString)
                                .AddCssClass("field-input");

            if (fieldEditorWidth.HasValue)
            {
                fieldEditorTd.AddAttribute("style", string.Format("width: {0}px; padding-right: {1}px", fieldEditorWidth, editorRightPadding));
            }
            else
            {
                fieldEditorTd.AddAttribute("style", string.Format("padding-right: {0}px", editorRightPadding));
            }

            if (editorPostfix != null)
            {
                fieldEditorTd.AddToInnerHtml(editorPostfix);
            }

            string               modelName   = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression));
            ModelState           modelState  = htmlHelper.ViewData.ModelState[modelName];
            ModelErrorCollection modelErrors = (modelState == null) ? null : modelState.Errors;

            var errorTd = new FluentTagBuilder("td").AddAttribute("style", "width: 24px");

            if (modelErrors != null && modelErrors.Count > 0)
            {
                errorTd.AddToInnerHtml(new FluentTagBuilder("img")
                                       .AddAttribute("src", htmlHelper.ToUrlHelper().Content("~/Content/Images/infoerror.gif"))
                                       .AddAttribute("data-property", ExpressionHelper.GetExpressionText(expression))
                                       .AddCssClass("error-image")
                                       .ToString(TagRenderMode.SelfClosing));

                errorTd
                .AddToInnerHtml(
                    new FluentTagBuilder("div")
                    .AddCssClass("error-message-div")
                    .AddAttribute("data-property", ExpressionHelper.GetExpressionText(expression))
                    .AddAttribute("data-title", (string)HtmlHelperExtensions.HtmlHelperExtensions.Localize(expression))
                    .AddToInnerHtml(validationMessageHtml));
            }

            var editorRow = new FluentTagBuilder("tr")
                            .AddToInnerHtml(fieldLabelTd)
                            .AddToInnerHtml(fieldEditorTd)
                            .AddToInnerHtml(errorTd);

            if (!visible)
            {
                editorRow.AddAttribute("style", "display: none");
            }

            fluentTagBuilder.AddToInnerHtml(editorRow);
        }