Inheritance: IHtmlString
Beispiel #1
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();
        }
Beispiel #2
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();
        }
Beispiel #3
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);
        }
Beispiel #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 (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;
        }
Beispiel #5
0
        public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, bool formGroup, string value, string dateFormat, IDictionary<string, object> htmlProps = null)
        {
            if (dateFormat.Contains("f") || dateFormat.Contains("F"))
            {
                htmlProps["class"] += " form-control";
                return helper.TextBox(TypeContextUtilities.Compose(name, "Time"), value, htmlProps);
            }

            var input = new HtmlTag("input")
                .IdName(name)
                .Attr("type", "text")
                .Class("form-control")
                .Attrs(htmlProps)
                .Attr("value", value);

            if (!formGroup)
                return AttachTimePiceker(input, dateFormat);

            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(AttachTimePiceker(new HtmlTag("div").Class("input-group time"), dateFormat)))
            {
                sb.Add(input);

                using (sb.Surround(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-time"));
            }

            return sb.ToHtml();
        }
Beispiel #6
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");
 }
Beispiel #7
0
        public static MvcHtmlString DatePicker(this HtmlHelper helper, string name, bool formGroup, string value, string jsFormat, CultureInfo culture = null, IDictionary<string, object> htmlProps = null)
        {
            if (culture == null)
                culture = CultureInfo.CurrentCulture;

            var input = new HtmlTag("input")
                .IdName(name)
                .Attr("type", "text")
                .Class("form-control")               
                .Attrs(htmlProps)
                .Attr("value", value);
               
            if(!formGroup)
                return AttachDatePicker(input, culture, jsFormat);
            
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(AttachDatePicker(new HtmlTag("div").Class("input-group date"), culture, jsFormat)))
            {
                sb.Add(input);

                using (sb.Surround(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-calendar"));
            }

            return sb.ToHtml();
        }
Beispiel #8
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;
        }
        private static MvcHtmlString InternalEntityList <T>(this HtmlHelper helper, EntityList entityList)
        {
            if (!entityList.Visible || entityList.HideIfNull && entityList.UntypedValue == null)
            {
                return(MvcHtmlString.Empty);
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", entityList.Prefix).Class("SF-entity-list SF-control-container")))
            {
                sb.AddLine(helper.Hidden(entityList.Compose(EntityListBaseKeys.ListPresent), ""));

                using (sb.SurroundLine(new HtmlTag("div", entityList.Compose("hidden")).Class("hide")))
                {
                }

                HtmlStringBuilder sbSelect = new HtmlStringBuilder();

                var sbSelectContainer = new HtmlTag("select").Attr("size", "6").Class("form-control")
                                        .IdName(entityList.Compose(EntityListBaseKeys.List));

                if (entityList.ListHtmlProps.Any())
                {
                    sbSelectContainer.Attrs(entityList.ListHtmlProps);
                }

                using (sbSelect.SurroundLine(sbSelectContainer))
                {
                    if (entityList.UntypedValue != null)
                    {
                        foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityList.Parent))
                        {
                            sb.Add(InternalListElement(helper, sbSelect, itemTC, entityList));
                        }
                    }
                }

                using (sb.SurroundLine(new HtmlTag("div", entityList.Compose("inputGroup")).Class("input-group")))
                {
                    sb.Add(sbSelect.ToHtml());

                    using (sb.SurroundLine(new HtmlTag("span", entityList.Compose("shownButton")).Class("input-group-btn btn-group-vertical")))
                    {
                        sb.AddLine(EntityButtonHelper.Create(helper, entityList, btn: true));
                        sb.AddLine(EntityButtonHelper.Find(helper, entityList, btn: true));
                        sb.AddLine(EntityButtonHelper.View(helper, entityList, btn: true));
                        sb.AddLine(EntityButtonHelper.Remove(helper, entityList, btn: true));
                        sb.AddLine(EntityButtonHelper.MoveUp(helper, entityList, btn: true));
                        sb.AddLine(EntityButtonHelper.MoveDown(helper, entityList, btn: true));
                    }
                }

                if (entityList.ElementType.IsEmbeddedEntity() && entityList.Create)
                {
                    T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T));
                    TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)entityList.Parent, 0, null);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityList, EntityBaseHelper.RenderPopup(helper, templateTC, RenderPopupMode.Popup, entityList, isTemplate: true), null));
                }
                sb.AddLine(entityList.ConstructorScript(JsModule.Lines, "EntityList"));
            }

            return(helper.FormGroup(entityList, entityList.Prefix, entityList.LabelHtml ?? entityList.LabelText.FormatHtml(), sb.ToHtml()));
        }
Beispiel #10
0
        public IDisposable Surround(HtmlTag div)
        {
            AddLine(div.ToHtml(TagRenderMode.StartTag));

            return new Disposable(() => AddLine(div.ToHtml(TagRenderMode.EndTag)));
        }
 public static void CanFilterDecorator(QueryToken qt, HtmlTag option)
 {
     string canFilter = QueryUtils.CanFilter(qt);
     if (canFilter.HasText())
         option.Attr("data-filter", canFilter);
 }
 public static void CanColumnDecorator(QueryToken qt, HtmlTag option)
 {
     string canColumn = QueryUtils.CanColumn(qt);
     if (canColumn.HasText())
         option.Attr("data-column", canColumn);
 }
Beispiel #13
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");
 }
Beispiel #14
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);
                }

               
            }
        }
Beispiel #15
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());
 }
Beispiel #16
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)));
        }
Beispiel #17
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);
        }