Exemple #1
0
        public EditorTableBuilder <TModel> WithSeparator()
        {
            FluentTagBuilder tdBuilder = new FluentTagBuilder("td").AddAttribute("colspan", "2").AddToInnerHtml(new FluentTagBuilder("hr"));

            fluentTagBuilder.AddToInnerHtml(new FluentTagBuilder("tr").AddToInnerHtml(tdBuilder));
            return(this);
        }
Exemple #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);
        }
Exemple #3
0
        public string ToHtmlString()
        {
            if (!createErrorDialogs)
            {
                return(fluentTagBuilder.ToString());
            }

            var addToInnerHtml = new FluentTagBuilder("script").AddAttribute("type", "text/javascript").AddToInnerHtml("common.createErrorDialogs()");

            return(fluentTagBuilder + addToInnerHtml.ToString());
        }
Exemple #4
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);
        }
Exemple #5
0
        public EditorTableBuilder <TModel> WithDisplayFor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField = true, string editorPostfix = null, bool visible = true)
        {
            if (!visible)
            {
                return(this);
            }

            FluentTagBuilder span = new FluentTagBuilder("span")
                                    .AddAttribute("id", htmlHelper.ClientIdFor(expression).ToHtmlString())
                                    .AddToInnerHtml(htmlHelper.DisplayFor(expression).ToHtmlString());

            BuildEditor(expression, requiredField, span.ToString(), null, editorPostfix);
            return(this);
        }
Exemple #6
0
        public ITextFilterBuilder <TModel> WithDecimalFilter(Expression <Func <TModel, decimal?> > expression, int decimalPlaces = 2, double?defaultValue = null)
        {
            var numericTextBox = htmlHelper.Kendo().NumericTextBox()
                                 .Name(ExpressionHelper.GetExpressionText(expression))
                                 .Spinners(false).Placeholder(TextLocalization.EmptyMessage)
                                 .HtmlAttributes(new { style = styleString, maxlength = 12, onkeyup = TriggerFilterOnEnter })
                                 .Decimals(decimalPlaces)
                                 .Value(defaultValue);

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

            lastRowBuilder = BuildRowWithLabel(expression, numericTextBox.ToHtmlString());
            return(this);
        }
Exemple #7
0
        public ITextFilterBuilder <TModel> WithDateFilter(Expression <Func <TModel, DateTime?> > expression, DateTime?defaultValue = null, int width = 200)
        {
            var dateTimePicker = htmlHelper.Kendo()
                                 .DatePicker()
                                 .Name(ExpressionHelper.GetExpressionText(expression))
                                 .Min(Defaults.MinDateTime)
                                 .Max(Defaults.MaxDateTime)
                                 //.ButtonTitle(ButtonLocalization.Calendar) //NOT supported in Kendo
                                 .HtmlAttributes(new { style = string.Format("width: {0}px", width), onkeyup = TriggerFilterOnEnter })
                                 .Value(defaultValue);

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

            lastRowBuilder = BuildRowWithLabel(expression, dateTimePicker.ToHtmlString());
            return(this);
        }
Exemple #8
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);
        }
Exemple #9
0
        private FluentTagBuilder BuildRowWithLabel <TValue>(Expression <Func <TModel, TValue> > expression, string editorString, bool visible = true, bool isDropDown = false)
        {
            int editorRightPadding = isDropDown ? 0 : 4;

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

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

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

            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));
            }

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

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

            return(editorRow);
        }
Exemple #10
0
        public ITextFilterBuilder <TModel> WithDateTimeFilter(Expression <Func <TModel, DateTime?> > expression)
        {
            var dateTimePicker = htmlHelper.Kendo()
                                 .DateTimePicker()
                                 .Name(ExpressionHelper.GetExpressionText(expression))
                                 .Min(Defaults.MinDateTime)
                                 .Max(Defaults.MaxDateTime)
                                 //.CalendarButtonTitle(ButtonLocalization.Calendar) //NOT supported in Kendo
                                 //.TimeButtonTitle(ButtonLocalization.Clock)        //NOT supported in Kendo
                                 .HtmlAttributes(new { onkeyup = TriggerFilterOnEnter })
                                 .Interval(30);

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

            lastRowBuilder = BuildRowWithLabel(expression, dateTimePicker.ToHtmlString());
            return(this);
        }
Exemple #11
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);
        }
Exemple #12
0
        public FluentTagBuilder AddToInnerHtml(FluentTagBuilder tagBuilder)
        {
            mBuilder.InnerHtml += tagBuilder.ToString(TagRenderMode.Normal);

            return(this);
        }