Attr() public method

public Attr ( string key, string value ) : HtmlTag
key string
value string
return HtmlTag
Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        public override MvcHtmlString ToHtml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.SurroundLine(new HtmlTag("div").Class("btn-group")))
            {
                var a = new HtmlTag("a")
                    .Id(Id)
                    .Class("btn")
                    .Class("btn-" + Style.ToString().ToLower())
                    .Class(CssClass)
                    .Class("dropdown-toggle")
                    .Attr("data-toggle", "dropdown")
                    .Attr("alt", Tooltip)
                    .Attrs(HtmlProps);

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

                using (sb.SurroundLine(a))
                {
                    sb.AddLine(new MvcHtmlString(Text));
                    sb.AddLine(new HtmlTag("span").Class("caret"));
                }


                using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                {
                    if (Items != null)
                        foreach (var ci in Items)
                            sb.Add(ci.ToHtml());
                }
            }

            return sb.ToHtml();
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static void CanFilterDecorator(QueryToken qt, HtmlTag option)
        {
            string canFilter = QueryUtils.CanFilter(qt);

            if (canFilter.HasText())
            {
                option.Attr("data-filter", canFilter);
            }
        }
Ejemplo n.º 6
0
        public static void CanColumnDecorator(QueryToken qt, HtmlTag option)
        {
            string canColumn = QueryUtils.CanColumn(qt);

            if (canColumn.HasText())
            {
                option.Attr("data-column", canColumn);
            }
        }
Ejemplo n.º 7
0
 static HtmlTag AttachTimePiceker(HtmlTag tag, string format)
 {
     return(tag.Attr("data-provide", "timepicker")
            .Attr("data-minute-step", "1")
            .Attr("data-second-step", "1")
            .Attr("data-show-meridian", false.ToString().ToLower())
            .Attr("data-show-seconds", (format.Contains("s")).ToString().ToLower())
            .Attr("data-hours-two-digits", (format.Contains("hh") || format.Contains("HH")).ToString().ToLower()));
 }
Ejemplo n.º 8
0
 private static HtmlTag AttachDatePicker(HtmlTag tag, CultureInfo culture, string jsFormat)
 {
     return(tag.Attr("data-provide", "datepicker")
            .Attr("data-date-language", culture.TwoLetterISOLanguageName)
            .Attr("data-date-week-start", ((int)culture.DateTimeFormat.FirstDayOfWeek).ToString())
            .Attr("data-date-autoclose", "true")
            .Attr("data-date-format", jsFormat)
            .Attr("data-date-today-btn", "linked")
            .Attr("data-date-today-highlight", "true"));
 }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
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 (Enabled)
            {
                if (OnClick != null)
                    a.Attr("onclick", OnClick.ToString());

                a.Attr("href", Href.DefaultText("#"));
            }
            else
                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);
            }

            return result;
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
0
        public override MvcHtmlString ToHtml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("btn-group")))
            {
                var a = new HtmlTag("a")
                        .Id(Id)
                        .Class("btn")
                        .Class("btn-" + Style.ToString().ToLower())
                        .Class(CssClass)
                        .Class("dropdown-toggle")
                        .Attr("data-toggle", "dropdown")
                        .Attr("alt", Tooltip)
                        .Attrs(HtmlProps);

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

                using (sb.SurroundLine(a))
                {
                    sb.AddLine(new MvcHtmlString(Text));
                    sb.AddLine(new HtmlTag("span").Class("caret"));
                }


                using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                {
                    if (Items != null)
                    {
                        foreach (var ci in Items)
                        {
                            sb.Add(ci.ToHtml());
                        }
                    }
                }
            }

            return(sb.ToHtml());
        }
Ejemplo n.º 13
0
        public static MvcHtmlString CheckBox(this HtmlHelper html, string name, bool isChecked, bool enabled, IDictionary <string, object> htmlAttributes = null)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            if (enabled)
            {
                return(html.CheckBox(name, isChecked, htmlAttributes)); //MVC CheckBox only applied disabled=disabled to the checkbox, not to the hidden value
            }
            else
            {
                HtmlTag checkbox = new HtmlTag("input")
                                   .Id(name)
                                   .Attrs(new
                {
                    type     = "checkbox",
                    name     = name,
                    value    = (isChecked ? "true" : "false"),
                    disabled = "disabled"
                })
                                   .Attrs(htmlAttributes);

                if (isChecked)
                {
                    checkbox.Attr("checked", "checked");
                }

                HtmlTag hidden = new HtmlTag("input")
                                 .Attrs(new
                {
                    type     = "hidden",
                    name     = name,
                    value    = (isChecked ? "true" : "false"),
                    disabled = "disabled"
                });

                return(checkbox.ToHtmlSelf().Concat(hidden.ToHtmlSelf()));
            }
        }
Ejemplo n.º 14
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());
        }
Ejemplo n.º 15
0
        private static MvcHtmlString InternalRepeaterElement <T>(this HtmlHelper helper, TypeElementContext <T> itemTC, EntityListCheckbox entityListCheckBox, bool isChecked, Lite <IEntity> lite)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            var label = new HtmlTag("label", itemTC.Compose(EntityRepeaterKeys.RepeaterElement)).Class("sf-checkbox-element");

            entityListCheckBox.CustomizeLabel?.Invoke(label, lite);

            using (sb.SurroundLine(label))
            {
                if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    sb.AddLine(EntityBaseHelper.RenderPopup(helper, itemTC, RenderPopupMode.PopupInDiv, entityListCheckBox));
                }
                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 cb = new HtmlTag("input")
                         .Attr("type", "checkbox")
                         .Attr("name", itemTC.Compose(EntityBaseKeys.RuntimeInfo))
                         .Attr("value", itemTC.RuntimeInfo()?.ToString());

                if (isChecked)
                {
                    cb.Attr("checked", "checked");
                }

                if (entityListCheckBox.ReadOnly)
                {
                    cb.Attr("disabled", "disabled");
                }

                entityListCheckBox.CustomizeCheckBox?.Invoke(cb, lite);

                sb.AddLine(cb);

                if (lite != null && (entityListCheckBox.Navigate || entityListCheckBox.View))
                {
                    var dic = new Dictionary <string, object>
                    {
                        { "target", "_blank" }
                    };

                    sb.AddLine(
                        helper.Href(itemTC.Compose(EntityBaseKeys.Link),
                                    lite.ToString(),
                                    lite.IdOrNull == null ? null : Navigator.NavigateRoute(lite),
                                    lite.ToString(), "sf-entitStrip-link", dic));
                }
                else
                {
                    sb.AddLine(
                        helper.Span(itemTC.Compose(EntityBaseKeys.Link),
                                    itemTC.UntypedValue.ToString() ?? " ", "sf-entitStrip-link"));
                }
            }

            return(sb.ToHtml());
        }
Ejemplo n.º 16
0
 static HtmlTag AttachTimePiceker(HtmlTag tag, string format)
 {
     return tag.Attr("data-provide", "timepicker")
      .Attr("data-minute-step", "1")
      .Attr("data-second-step", "1")
      .Attr("data-show-meridian", false.ToString().ToLower())
      .Attr("data-show-seconds", (format.Contains("s")).ToString().ToLower())
      .Attr("data-hours-two-digits", (format.Contains("hh") || format.Contains("HH")).ToString().ToLower());
 }
Ejemplo n.º 17
0
 private static HtmlTag AttachDatePicker(HtmlTag tag, CultureInfo culture, string jsFormat)
 {
     return tag.Attr("data-provide", "datepicker")
        .Attr("data-date-language", culture.TwoLetterISOLanguageName)
        .Attr("data-date-autoclose", "true")
        .Attr("data-date-format", jsFormat)
        .Attr("data-date-today-btn", "linked")
        .Attr("data-date-today-highlight", "true");
 }
Ejemplo n.º 18
0
 private static HtmlTag AttachDatePicker(HtmlTag tag, CultureInfo culture, string jsFormat)
 {
     return tag.Attr("data-provide", "datepicker")
        .Attr("data-date-language", culture.TwoLetterISOLanguageName)
        .Attr("data-date-week-start", ((int)culture.DateTimeFormat.FirstDayOfWeek).ToString())
        .Attr("data-date-autoclose", "true")
        .Attr("data-date-format", jsFormat)
        .Attr("data-date-today-btn", "linked")
        .Attr("data-date-today-highlight", "true");
 }
Ejemplo n.º 19
0
        protected virtual HtmlTag GetLinkElement()
        {
            var a = new HtmlTag("a")
               .Id(Id)
               .Class("bg-" + Style.ToString().ToLower())
               .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");
            return a;
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
 public static void CanFilterDecorator(QueryToken qt, HtmlTag option)
 {
     string canFilter = QueryUtils.CanFilter(qt);
     if (canFilter.HasText())
         option.Attr("data-filter", canFilter);
 }
Ejemplo n.º 22
0
 public static void CanColumnDecorator(QueryToken qt, HtmlTag option)
 {
     string canColumn = QueryUtils.CanColumn(qt);
     if (canColumn.HasText())
         option.Attr("data-column", canColumn);
 }