ToHtml() public method

public ToHtml ( ) : System.Web.Mvc.MvcHtmlString
return System.Web.Mvc.MvcHtmlString
        public virtual MvcHtmlString ToHtml()
        {
            var a = GetLinkElement();

            var result = new HtmlTag("li").InnerHtml(a.ToHtml());

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "left");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
            {
                return(html);
            }

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return(html.Concat(script));
        }
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
            {
                return(MvcHtmlString.Create(""));
            }

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.Options);

            if (queryTokens.IsEmpty())
            {
                return(new HtmlTag("input")
                       .Attr("type", "hidden")
                       .IdName(context.Compose("ddlTokensEnd_" + index))
                       .Attr("disabled", "disabled")
                       .Attr("data-parenttoken", previous == null ? "" : previous.FullKey()));
            }

            var options = new HtmlStringBuilder();

            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                             .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                             .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                {
                    option.Attr("selected", "selected");
                }

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                {
                    settings.Decorators(qt, option);
                }

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                               .Class("form-control")
                               .IdName(context.Compose("ddlTokens_" + index))
                               .InnerHtml(options.ToHtml())
                               .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return(dropdown.ToHtml());
        }
        public virtual MvcHtmlString ToHtml(HtmlHelper helper)
        {
            var a = new HtmlTag("a")
                    .Id(Id)
                    .Class("btn")
                    .Class("btn-" + Style.ToString().ToLower())
                    .Class("sf-entity-button")
                    .Class(CssClass)
                    .Attrs(HtmlProps);

            if (Text != null)
            {
                a.SetInnerText(Text);
            }

            if (Html != null)
            {
                a.InnerHtml(Html);
            }

            if (Title.HasText())
            {
                a.Attr("title", Title);
            }

            if (Href != null)
            {
                a.Attr("href", Href);
            }

            if (!Enabled)
            {
                a.Attr("disabled", "disabled");
            }

            var result = new HtmlTag("div").Class("btn-group").InnerHtml(a);

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "bottom");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
            {
                return(html);
            }

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return(html.Concat(script));
        }
        static MvcHtmlString InternalListElement <T>(this HtmlHelper helper, HtmlStringBuilder sbOptions, TypeElementContext <T> itemTC, EntityList entityList)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();


            sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
            sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

            if (entityList.IsVisible == null || entityList.IsVisible(itemTC))
            {
                if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    sb.AddLine(EntityBaseHelper.RenderPopup(helper, itemTC, RenderPopupMode.PopupInDiv, entityList));
                }
                else if (itemTC.Value != null)
                {
                    sb.Add(helper.Div(itemTC.Compose(EntityBaseKeys.Entity), null, "",
                                      new Dictionary <string, object> {
                        { "style", "display:none" }, { "class", "sf-entity-list" }
                    }));
                }

                var optionTag = new HtmlTag("option")
                                .Id(itemTC.Compose(EntityBaseKeys.ToStr))
                                .Class("sf-entity-list-option")
                                .Let(a => itemTC.Index > 0 ? a : a.Attr("selected", "selected"))
                                .SetInnerText(itemTC.Value?.ToString());

                if (!EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    PrimaryKey?idOrNull = null;
                    Type       type     = itemTC.Value.GetType();
                    if (type.IsLite())
                    {
                        idOrNull = ((Lite <IEntity>)itemTC.Value).IdOrNull;
                    }

                    if (type.IsEntity())
                    {
                        idOrNull = ((Entity)(object)itemTC.Value).IdOrNull;
                    }

                    optionTag.Attr("title", " ".CombineIfNotEmpty(itemTC.Value.GetType().CleanType().NiceName(), idOrNull));
                }

                sbOptions.Add(optionTag.ToHtml(TagRenderMode.Normal));
            }

            return(sb.ToHtml());
        }
Esempio n. 5
0
        public static MvcHtmlString RenderOption(this SelectListItem item)
        {
            HtmlTag builder = new HtmlTag("option").SetInnerText(item.Text);

            if (item.Value != null)
            {
                builder.Attr("value", item.Value);
            }

            if (item.Selected)
            {
                builder.Attr("selected", "selected");
            }

            return(builder.ToHtml());
        }
Esempio n. 6
0
        public virtual MvcHtmlString ToHtml(HtmlHelper helper)
        {
            var a = new HtmlTag("a")
                .Id(Id)
                .Class("btn")
                .Class("btn-" + Style.ToString().ToLower())
                .Class("sf-entity-button")
                .Class(CssClass)
                .Attrs(HtmlProps);

            if (Text != null)
                a.SetInnerText(Text);

            if (Html != null)
                a.InnerHtml(Html);

            if (Title.HasText())
                a.Attr("title", Title);

            if (Href != null)
                a.Attr("href", Href);

            if (!Enabled)
                a.Attr("disabled", "disabled");

            var result = new HtmlTag("div").Class("btn-group").InnerHtml(a);

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "bottom");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
                return html;

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return html.Concat(script);
        }
Esempio n. 7
0
        public static MvcHtmlString Href(this HtmlHelper html, string id, string innerText, string url, string title, string cssClass, IDictionary <string, object> htmlAttributes)
        {
            HtmlTag href = new HtmlTag("a", id)
                           .Attrs(htmlAttributes)
                           .Class(cssClass)
                           .SetInnerText(innerText);

            if (url.HasText())
            {
                href.Attr("href", url);
            }

            if (title.HasText())
            {
                href.Attr("title", title);
            }

            return(href.ToHtml());
        }
Esempio n. 8
0
        //http://stackoverflow.com/questions/979095/asp-net-mvc-dropdownlist-pre-selected-item-ignored
        public static MvcHtmlString SafeDropDownList(this HtmlHelper html, string idAndName, IEnumerable <SelectListItem> elements, IDictionary <string, object> htmlAttributes = null)
        {
            var select = new HtmlTag("select").IdName(idAndName).Attrs(htmlAttributes);

            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (var se in elements)
            {
                var option = new HtmlTag("option").Attr("value", se.Value).SetInnerText(se.Text);

                if (se.Selected)
                {
                    option.Attr("selected", "selected");
                }

                sb.Add(option.ToHtml());
            }

            select.InnerHtml(sb.ToHtml());

            return(select.ToHtml());
        }
Esempio n. 9
0
        public static IDisposable Surround(TextWriter writer, HtmlTag div)
        {
            writer.WriteLine(div.ToHtml(TagRenderMode.StartTag).ToString());

            return new Disposable(() => writer.WriteLine(div.ToHtml(TagRenderMode.EndTag)));
        }
Esempio n. 10
0
        }                                 //is applied to link


        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
            {
                throw new InvalidOperationException("Invisible menu");
            }

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                            children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                    {
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    }
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                      .Attrs(new { href = link, title = Title, id = Id })
                                      .Class(Class);

                        if (Html != null)
                        {
                            tbA.InnerHtml(Html);
                        }
                        else
                        {
                            tbA.SetInnerText(Text);
                        }

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                                           .Class("dropdown-toggle")
                                           .Class(Class)
                                           .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                        {
                            sb.Add(Html);
                        }
                        else
                        {
                            sb.Add(new HtmlTag("span").SetInnerText(Text));
                        }

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                {
                    sb.AddLine(Html);
                }
                else
                {
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));
                }

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if (lastHeader)
                                {
                                    sb.AddLine(new HtmlTag("li").Class("divider"));
                                }

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                    {
                        menu.Write(sb, currentUrl, depth + 1);
                    }
                }
            }
        }
Esempio n. 11
0
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
                return MvcHtmlString.Create("");

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.CanAggregate);

            if (queryTokens.IsEmpty())
                return new HtmlTag("input")
                .Attr("type", "hidden")
                .IdName(context.Compose("ddlTokensEnd_" + index))
                .Attr("disabled", "disabled")
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            var options = new HtmlStringBuilder();
            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                    .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                    .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                    option.Attr("selected", "selected");

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                    settings.Decorators(qt, option); 

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                .Class("form-control")
                .IdName(context.Compose("ddlTokens_" + index))
                .InnerHtml(options.ToHtml()) 
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return dropdown.ToHtml();
        }
Esempio n. 12
0
        public virtual MvcHtmlString ToHtml()
        {
            var a = GetLinkElement();

            var result = new HtmlTag("li").InnerHtml(a.ToHtml());

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "left");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
                return html;

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return html.Concat(script);
        }
Esempio n. 13
0
        public IDisposable Surround(HtmlTag div)
        {
            AddLine(div.ToHtml(TagRenderMode.StartTag));

            return new Disposable(() => AddLine(div.ToHtml(TagRenderMode.EndTag)));
        }
Esempio n. 14
0
        public IDisposable Surround(HtmlTag div)
        {
            Add(div.ToHtml(TagRenderMode.StartTag));

            return(new Disposable(() => Add(div.ToHtml(TagRenderMode.EndTag))));
        }
Esempio n. 15
0
        public static IDisposable Surround(TextWriter writer, HtmlTag div)
        {
            writer.WriteLine(div.ToHtml(TagRenderMode.StartTag).ToString());

            return(new Disposable(() => writer.WriteLine(div.ToHtml(TagRenderMode.EndTag))));
        }
Esempio n. 16
0
        public string Class { get; set; } //is applied to link

     
        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
                throw new InvalidOperationException("Invisible menu");

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                .Attrs(new { href = link, title = Title, id = Id })
                                .Class(Class);

                        if (Html != null)
                            tbA.InnerHtml(Html);
                        else
                            tbA.SetInnerText(Text);

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                        .Class("dropdown-toggle")
                        .Class(Class)
                        .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                            sb.Add(Html);
                        else 
                            sb.Add(new HtmlTag("span").SetInnerText(Text));

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                    sb.AddLine(Html);
                else
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if(lastHeader)
                                    sb.AddLine(new HtmlTag("li").Class("divider")); 

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                        menu.Write(sb, currentUrl, depth + 1);
                }

               
            }
        }