/// <summary>
        /// Create drop down menu item for property
        /// selected by expression using provided list item.
        /// </summary>
        /// <typeparam name="TModel">Type of model.</typeparam>
        /// <typeparam name="TProperty">Type of property.</typeparam>
        /// <param name="htmlHelper">HtmlHelper.</param>
        /// <param name="expression">Expression to select needed property.</param>
        /// <param name="listItem">List item to get text and value.</param>
        /// <returns>List item with radio button and span.</returns>
        internal static FluentTagBuilder CreateDropDownButtonMenuItem <TModel, TProperty>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            SelectListItem listItem)
        {
            FluentTagBuilder menuItem = new FluentTagBuilder("li");

            // Initialize span
            FluentTagBuilder span = new FluentTagBuilder("span")
                                    .SetInnerText(listItem.Text);

            // Initialize radio button
            string        fieldName = ExpressionHelper.GetExpressionText(expression);
            ModelMetadata metadata  = ModelMetadata.FromLambdaExpression(
                expression, htmlHelper.ViewData);

            // Get validation attributes and add hidden attribute
            var htmlAttributes = htmlHelper
                                 .GetUnobtrusiveValidationAttributes(fieldName);

            htmlAttributes.Add("hidden", "hidden");

            MvcHtmlString radioButton = htmlHelper
                                        .RadioButton(fieldName, listItem.Value, listItem.Selected, htmlAttributes);

            // Set content of list menu item
            menuItem.AppendChild(span).AppendChild(radioButton);

            return(menuItem);
        }
示例#2
0
        protected virtual string BeginForm <TModel>(HtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, string formId) where TModel : class
        {
            if (roboForm.Layout == RoboUIFormLayout.Wizard)
            {
                roboForm.FormActionUrl = null;
            }

            string formActionUrl = string.IsNullOrEmpty(roboForm.FormActionUrl)
                ? htmlHelper.ViewContext.HttpContext.Request.RawUrl
                : roboForm.FormActionUrl;

            var form = new FluentTagBuilder("form", TagRenderMode.StartTag)
                       .MergeAttribute("action", formActionUrl)
                       .MergeAttribute("id", formId)
                       .MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());

            if (roboForm.Layout == RoboUIFormLayout.Tab)
            {
                form = form.MergeAttribute("data-ajax-begin", formId.Replace("-", "_") + "_ValidateTabs");
            }

            if (!roboForm.AjaxEnabled)
            {
                form = form.MergeAttribute("enctype", "multipart/form-data");
            }
            else
            {
                form = form.MergeAttribute("data-ajax", "true");
            }

            form = form.MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());
            form = form.MergeAttributes(roboForm.HtmlAttributes);

            return(form.ToString());
        }
        public void BeginPanel(Panel panel, TextWriter writer)
        {
            switch (panel.State)
            {
            case State.Danger: panel.EnsureClass("callout alert"); break;

            case State.Info: panel.EnsureClass("callout secondary"); break;

            case State.Inverse: panel.EnsureClass("callout secondary"); break;

            case State.Primary: panel.EnsureClass("callout primary"); break;

            case State.Success: panel.EnsureClass("callout success"); break;

            case State.Warning: panel.EnsureClass("callout warning"); break;

            case State.Default:
            default: panel.EnsureClass("callout"); break;
            }

            var builder = new FluentTagBuilder("div", TagRenderMode.StartTag)
                          .MergeAttributes(panel.HtmlAttributes);

            string tag = builder.ToString();

            writer.Write(tag);
        }
 private void MakeTableHeaders(Row row, FluentTagBuilder tagBuilder)
 {
     foreach (var header in row.Headers)
     {
         MakeTableCell(header, FluentTagBuilder.Th, tagBuilder);
     }
 }
        /// <summary>
        /// Construct configured actions for list data row which will be
        /// managed at server side..
        /// </summary>
        /// <param name="model">Model object to create links according to.</param>
        /// <returns>List data action container as as FluentTagBuilder.</returns>
        private FluentTagBuilder ConstructServerSideListItemActionContainer(TModel model)
        {
            // Css classes for buttons
            string listDataActionContainerCss = "list-data-action-container";

            // Initialize list data action container if needed
            FluentTagBuilder actionContainer = null;

            if (ListItemActionCollection.Count > 0)
            {
                actionContainer = new FluentTagBuilder("div")
                                  .AddCssClass(listDataActionContainerCss);
            }

            foreach (IListEditorActionCore <TModel> action in ListItemActionCollection)
            {
                FluentTagBuilder link = action.GenerateLink(model);
                if (link != null)
                {
                    actionContainer.AppendChild(link);
                }
            }

            return(actionContainer);
        }
 private void MakeTableCells(Row row, FluentTagBuilder tagBuilder)
 {
     foreach (var cell in row.Cells)
     {
         MakeTableCell(cell, FluentTagBuilder.Td, tagBuilder);
     }
 }
        public void BeginAccordionPanel(TextWriter writer, string title, string panelId, string parentAccordionId, bool expanded)
        {
            writer.Write(@"<div class=""card"">");

            var panel = new FluentTagBuilder("div")
                        .AddCssClass("card-header")
                        .MergeAttribute("id", $"{panelId}-heading")
                        .StartTag("h5")
                        .AddCssClass("mb-0")
                        .StartTag("button")
                        .AddCssClass($"btn btn-link{(expanded ? string.Empty : " collapsed")}")
                        .MergeAttribute("type", "button")
                        .MergeAttribute("data-toggle", "collapse")
                        .MergeAttribute("data-target", $"#{panelId}")
                        .MergeAttribute("aria-controls", panelId)
                        .MergeAttribute("aria-expanded", expanded ? "true" : "false")
                        .SetInnerHtml(title)
                        .EndTag()
                        .EndTag();

            writer.Write(panel.ToString());

            var collapse = new FluentTagBuilder("div", TagRenderMode.StartTag)
                           .AddCssClass($"collapse{(expanded ? " show" : string.Empty)}")
                           .MergeAttribute("id", panelId)
                           .MergeAttribute("aria-labelledby", $"{panelId}-heading")
                           .MergeAttribute("data-parent", $"#{parentAccordionId}");

            writer.Write(collapse.ToString());
            writer.Write(@"<div class=""card-body"">");
        }
 private void MakeTableRows(Table table, FluentTagBuilder tagBuilder)
 {
     foreach (var row in table.Rows)
     {
         MakeTableRow(row, tagBuilder);
     }
 }
        public void BeginPanel(Panel panel, TextWriter writer)
        {
            switch (panel.State)
            {
            case State.Default: panel.EnsureClass("panel panel-default"); break;

            case State.Important: panel.EnsureClass("panel panel-danger"); break;

            case State.Info: panel.EnsureClass("panel panel-info"); break;

            case State.Inverse: panel.EnsureClass("panel panel-inverse"); break;

            case State.Primary: panel.EnsureClass("panel panel-primary"); break;

            case State.Success: panel.EnsureClass("panel panel-success"); break;

            case State.Warning: panel.EnsureClass("panel panel-warning"); break;
            }

            var builder = new FluentTagBuilder("div", TagRenderMode.StartTag)
                          .MergeAttributes(panel.HtmlAttributes);

            string tag = builder.ToString();

            writer.Write(tag);
        }
        /// <summary>
        /// Construct list for tree view.
        /// </summary>
        /// <typeparam name="TModel">Type of model.</typeparam>
        /// <typeparam name="TProperty">Type of selected property.</typeparam>
        /// <param name="helper">Html helper.</param>
        /// <param name="expression">Expression which selects property.</param>
        /// <param name="source">Soruce of tree view.</param>
        /// <returns>Tree view list as FluentTagBuilder.</returns>
        private static FluentTagBuilder ConstructList <TModel, TProperty>(
            this HtmlHelper <TModel> helper,
            Expression <Func <TModel, TProperty> > expression,
            TreeViewSource <TProperty> source)
            where TProperty : struct
        {
            // CSS classes
            string listCssClass   = "tree-view-list";
            string loadedCssClass = "tv-loaded";

            // Construct tree view list
            FluentTagBuilder treeViewList = new FluentTagBuilder("ul")
                                            .AddCssClass(listCssClass);

            // If there is not any item return
            if (source == null ||
                source.ItemList == null ||
                source.ItemList.Count == 0)
            {
                return(treeViewList);
            }

            // If source is not empty add class
            treeViewList.AddCssClass(loadedCssClass);

            // Construct list items and add them to treeViewList
            foreach (TreeViewItem <TProperty> listItemSource in source.ItemList)
            {
                FluentTagBuilder listItem = helper
                                            .ConstructListItem(expression, listItemSource);
                treeViewList.AppendChild(listItem);
            }

            return(treeViewList);
        }
示例#11
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var cssClass = String.IsNullOrEmpty(Icon) ? "fa-ellipsis-v" : Icon;

            if (cssClass.StartsWith("fa-"))
            {
                cssClass = $"fa {cssClass}";
            }

            var content = await output.GetChildContentAsync();

            FluentTagBuilder builder = new FluentTagBuilder("div")
                                       .AddCssClass("dropdown")
                                       .AppendHtml(new FluentTagBuilder("a")
                                                   .MergeAttribute("style", "display:inline-block;width:100%")
                                                   .MergeAttribute("data-toggle", "dropdown")
                                                   .MergeAttribute("href", "#")
                                                   .AppendHtml(new FluentTagBuilder("i")
                                                               .AddCssClass(cssClass)))
                                       .AppendHtml(new FluentTagBuilder("ul")
                                                   .AddCssClass("dropdown-menu")
                                                   .AppendHtml(content));

            output.TagName = "";
            output.Content.SetHtmlContent(builder);
        }
示例#12
0
        /// <summary>
        /// Generate link if for model if it should be rendered.
        /// </summary>
        /// <param name="model">Model to generate link for.</param>
        /// <returns>Generated link TagBuilder.</returns>
        public FluentTagBuilder GenerateLink(TModel model)
        {
            if (UrlGenerator == null)
            {
                throw new NullReferenceException(string.Format(
                                                     "{0} must be set to be able to use parameterless overload of {1} method.",
                                                     nameof(UrlGenerator),
                                                     nameof(GenerateLink)));
            }

            // If model is null or link should not be generated then return null.
            if (model == null ||
                !ShouldBeRendered(model))
            {
                return(null);
            }

            FluentTagBuilder linkTag = new FluentTagBuilder("a")
                                       .AddCssClass(string.Format(DefaultLinkCssClassFormat, Name))
                                       .MergeAttributes(HtmlAttributes)
                                       .MergeAttribute("href", GenerateUrl(model))
                                       .SetInnerText(Label);

            return(linkTag);
        }
示例#13
0
        public static MvcHtmlString UnobtrusiveImageButton(this HtmlHelper html, string imageUrl, string text, bool showTextAfterImage = false, string additionalClasses = "", Action <FluentTagBuilder> customizeButtonAnchor = null)
        {
            var anchorBuilder = new FluentTagBuilder("a");

            anchorBuilder.AddCssClass("t-emsg-image-button k-button k-button-icon");

            foreach (var addClass in (additionalClasses ?? string.Empty).Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                anchorBuilder.AddCssClass(addClass);
            }

            anchorBuilder.AddAttribute("title", text);
            anchorBuilder.AddAttribute("tabindex", "0");

            anchorBuilder.AddToInnerHtml(new FluentTagBuilder("img")
                                         .AddAttribute("alt", text)
                                         .AddAttribute("src", imageUrl)
                                         .AddCssClass("k-icon-image")
                                         .ToString(TagRenderMode.SelfClosing));

            if (showTextAfterImage)
            {
                anchorBuilder.AddToInnerHtml(new FluentTagBuilder("span").AddCssClass("imageButtonText").AddToInnerHtml(text));
            }

            if (customizeButtonAnchor != null)
            {
                customizeButtonAnchor(anchorBuilder);
            }

            return(new MvcHtmlString(anchorBuilder.ToString()));
        }
        public void BeginAccordionPanel(TextWriter writer, string title, string panelId, string parentAccordionId, bool expanded)
        {
            writer.Write(@"<div class=""panel panel-default"">");

            var panel = new FluentTagBuilder("div")
                        .AddCssClass("panel-heading")
                        .MergeAttribute("role", "tab")
                        .MergeAttribute("id", $"{panelId}-heading")
                        .StartTag("h4")
                        .AddCssClass("panel-title")
                        .StartTag("a")
                        .MergeAttribute("data-toggle", "collapse")
                        .MergeAttribute("data-parent", $"#{parentAccordionId}")
                        .MergeAttribute("href", $"#{panelId}")
                        .MergeAttribute("aria-controls", panelId)
                        .MergeAttribute("aria-expanded", expanded ? "true" : "false")
                        .SetInnerHtml(title)
                        .EndTag()
                        .EndTag();

            writer.Write(panel.ToString());

            var collapse = new FluentTagBuilder("div", TagRenderMode.StartTag)
                           .AddCssClass(expanded ? "panel-collapse collapse in" : "panel-collapse collapse")
                           .MergeAttribute("id", panelId)
                           .MergeAttribute("role", "tabpanel")
                           .MergeAttribute("aria-labelledby", $"{panelId}-heading");

            writer.Write(collapse.ToString());
            writer.Write(@"<div class=""panel-body"">");
        }
示例#15
0
        public static IHtmlString BsLink(this HtmlHelper htmlHelper, object innerText, string buttonClass, string iconClass, string linkHref, object htmlAttributes = null, AjaxOptions ajaxOptions = null)
        {
            var mainAttrs = new Dictionary <string, object>();

            if (!String.IsNullOrWhiteSpace(linkHref))
            {
                mainAttrs.Add("href", linkHref);
            }
            if (!String.IsNullOrWhiteSpace(buttonClass))
            {
                mainAttrs.Add("class", buttonClass);
            }

            var link = new FluentTagBuilder("a")
                       .AddAttributes(mainAttrs)
                       .AddAttributes(htmlAttributes)
                       .AddContent(htmlHelper.Icon(iconClass, innerText));

            if (ajaxOptions != null)
            {
                link.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
            }

            return(link);
        }
示例#16
0
        public override MvcHtmlString TextBoxWithAddOns(HtmlHelper html, string name, object value, string prependValue, string appendValue, object htmlAttributes = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            var builder = new FluentTagBuilder("div")
                          .AddCssClass("input-group");

            if (!string.IsNullOrEmpty(prependValue))
            {
                builder = builder
                          .StartTag("div")
                          .AddCssClass("input-group-addon")
                          .SetInnerHtml(prependValue)
                          .EndTag();
            }

            builder = builder.AppendContent(html.TextBox(name, value, htmlAttributes).ToString());

            if (!string.IsNullOrEmpty(appendValue))
            {
                builder = builder
                          .StartTag("div")
                          .AddCssClass("input-group-addon")
                          .SetInnerHtml(appendValue)
                          .EndTag();
            }

            return(MvcHtmlString.Create(builder.ToString()));
        }
 /// <summary>
 /// Create a new divider.
 /// </summary>
 public static FluentTagBuilder Div(this FluentTagBuilder @this, string classAttr = null, string content = null)
 {
     return(@this.Append(new FluentTagBuilder()
                         .StartTag("div").ActionIf(!string.IsNullOrEmpty(classAttr), tag => tag.Class(classAttr))
                         .Append(content)
                         .EndTag()));
 }
示例#18
0
        public FluentTagBuilder Render(FluentTagBuilder tbody, IList <T> items)
        {
            var columns          = gridModel_.VisibleColumns.ToList();
            FluentTagBuilder tag = null;

            foreach (var item in items)
            {
                var innerTr = Tag.Tr;
                foreach (var column in gridModel_.HiddenColumns)
                {
                    innerTr.Html(GetContent(column, item));
                }

                foreach (var column in columns)
                {
                    var index = columns.IndexOf(column);
                    var nextColumnIsMerged = index < columns.Count - 1 && columns[index + 1].IsMerged;

                    if (!column.IsMerged)
                    {
                        tag = column.GetContentTag(item);
                    }

                    tag.Html(GetContent(column, item));

                    if (!nextColumnIsMerged)
                    {
                        innerTr.Html(tag);
                    }
                }

                tbody.Html(innerTr);
            }
            return(tbody);
        }
示例#19
0
        public static MvcHtmlString ImageButton(this HtmlHelper html, string imageUrl, string text,
                                                string onClickAction        = null,
                                                bool showTextAfterImage     = false,
                                                string additionalClasses    = "",
                                                string defaultButtonClasses = "t-emsg-image-button k-button k-button-icon",
                                                string defaultImageClasses  = "k-icon-image"
                                                )
        {
            var builder = new FluentTagBuilder("a");

            builder.AddCssClass(defaultButtonClasses);

            foreach (var addClass in (additionalClasses ?? string.Empty).Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                builder.AddCssClass(addClass);
            }
            builder.AddAttribute("title", text);
            builder.AddAttribute("tabindex", "0");
            if (!string.IsNullOrEmpty(onClickAction))
            {
                builder.AddAttribute("onclick", onClickAction);
            }
            builder.AddToInnerHtml(new FluentTagBuilder("img")
                                   .AddAttribute("alt", text)
                                   .AddAttribute("src", imageUrl)
                                   .AddCssClass(defaultImageClasses)
                                   .ToString(TagRenderMode.SelfClosing));

            if (showTextAfterImage)
            {
                builder.AddToInnerHtml(new FluentTagBuilder("span").AddCssClass("imageButtonText").AddToInnerHtml(text));
            }

            return(new MvcHtmlString(builder.ToString()));
        }
示例#20
0
        private string CreateStatusList(int pageIndex, int totalItems, int pageSize)
        {
            RouteValues["page"] = pageIndex;
            string[] pageList = PagerSizesFormat.Split(',').Select(s => s.Trim()).ToArray();

            return(new FluentTagBuilder()
                   .StartTag("div", "dropdown").Style("display: inline-block;")
                   .StartTag("button", "btn btn-default dropdown-toggle").Attribute("data-toggle", "dropdown")
                   .Append($"{pageSize}&nbsp;")
                   .StartTag("span", "caret")
                   .EndTag()
                   .EndTag()
                   .StartTag("ul", "dropdown-menu")
                   .Action(menu =>
            {
                foreach (string item in pageList)
                {
                    RouteValues["pageSize"] = item;
                    var li = new FluentTagBuilder()
                             .StartTag("li").Anchor(UrlHelper.Action(AspAction, AspController, RouteValues, AspProtocol, AspHost, AspFragment), item, AjaxValues).EndTag();
                    menu.Append(li);
                }
            })
                   .EndTag()
                   .EndTag()
                   .StartTag("text").Style("display: inline-block;")
                   .Append($"&nbsp;{StringResources.PagerSizesText}")
                   .EndTag());
        }
 private void MakeTableColumns(Table table, FluentTagBuilder tagBuilder)
 {
     foreach (int relativeWidth in table.RelativeWidths)
     {
         MakeTableColumn(relativeWidth, tagBuilder);
     }
 }
 private void MakeReport(Report report, FluentTagBuilder tagBuilder)
 {
     foreach (var table in report.Tables)
     {
         MakeTable(table, tagBuilder);
     }
 }
        private bool ClassesFor(Cell cell, FluentTagBuilder tagBuilder)
        {
            var classesExist = false;

            classesExist |= AlignmentFor(cell, tagBuilder);
            classesExist |= StyleFor(cell, tagBuilder);
            return(classesExist);
        }
 private void BorderFor(Cell cell, FluentTagBuilder tagBuilder)
 {
     if (cell.Border)
     {
         return;
     }
     tagBuilder.Class("noborder");
 }
 private void ColSpanFor(Cell cell, FluentTagBuilder tagBuilder)
 {
     if (cell.ColSpan == 1)
     {
         return;
     }
     tagBuilder.Colspan(cell.ColSpan);
 }
 /// <summary>
 /// Create a new tag.
 /// </summary>
 public static FluentTagBuilder Tag(this FluentTagBuilder @this, string tagName, string content = null, object htmlAttributes = null)
 {
     return(@this
            .StartTag(tagName)
            .AppendIf(content != null, tag => { return new FluentTagBuilder().Append(content); })
            .Attributes(htmlAttributes)
            .EndTag());
 }
        private void MakeTableRow(Row row, FluentTagBuilder tagBuilder)
        {
            var rowTagBuilder = Tag.Tr;

            MakeTableHeaders(row, rowTagBuilder);
            MakeTableCells(row, rowTagBuilder);

            tagBuilder.Html(rowTagBuilder);
        }
示例#28
0
        protected override string BuildResource(ResourceEntry resource)
        {
            var builder = new FluentTagBuilder("script")
                          .MergeAttribute("type", "text/javascript")
                          .MergeAttribute("src", urlHelper.Content(resource.Path))
                          .MergeAttributes(resource.HtmlAttributes);

            return(builder.ToString());
        }
        public override IHtmlContent Badge(string text, object htmlAttributes = null)
        {
            var builder = new FluentTagBuilder("span")
                          .MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes))
                          .AddCssClass("badge")
                          .SetInnerHtml(text);

            return(new HtmlString(builder.ToString()));
        }
        public void BeginModal(Modal modal, TextWriter writer)
        {
            var builder = new FluentTagBuilder("div", TagRenderMode.StartTag)
                          .MergeAttributes(modal.HtmlAttributes);

            string tag = builder.ToString();

            writer.Write(tag);
        }