Пример #1
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");

            tb.AddCssClass(Type.ToCssClass());
            if (Closable)
            {
                tb.AddCssClass("alert-dismissable");
            }
            tb.MergeAttribute("role", "alert");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (Closable)
            {
                var dsmb = context.CreateTagBuilder("button");
                dsmb.MergeAttribute("type", "button");
                dsmb.MergeAttribute("class", "close");
                dsmb.MergeAttribute("data-dismiss", "alert");
                dsmb.MergeAttribute("aria-hidden", "true");
                dsmb.InnerHtml = "×";
                dsmb.WriteFullTag(writer);
            }

            return(tb.GetEndTag());
        }
Пример #2
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var li = context.CreateTagBuilder("li");

            if (DisabledValue)
            {
                li.AddCssClass("disabled");
            }
            else
            {
                if (ActiveValue)
                {
                    li.AddCssClass("active");
                }
            }

            li.WriteStartTag(writer);

            var link = context.CreateTagBuilder(DisabledValue ? "span" : "a");
            if (!DisabledValue)
            {
                link.MergeAttribute("href", HrefValue);
            }

            link.WriteStartTag(writer);

            return link.GetEndTag() + li.GetEndTag();
        }
Пример #3
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var li = context.CreateTagBuilder("li");

            if (DisabledValue)
            {
                li.AddCssClass("disabled");
            }
            else
            {
                if (ActiveValue)
                {
                    li.AddCssClass("active");
                }
            }

            li.WriteStartTag(writer);

            var link = context.CreateTagBuilder(DisabledValue ? "span" : "a");

            if (!DisabledValue)
            {
                link.MergeAttribute("href", HrefValue);
            }

            link.WriteStartTag(writer);

            return(link.GetEndTag() + li.GetEndTag());
        }
Пример #4
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var formGroup = context.PeekNearest<FormGroup>();
            if (formGroup != null && ControlContextValue == null)
            {
                ControlContextValue = formGroup.ControlContextValue;
            }

            ITagBuilder div = null;
            if (!InlineValue)
            {
                div = context.CreateTagBuilder("div");
                div.AddCssClass("checkbox");
                div.WriteStartTag(writer);
            }

            var lbl = context.CreateTagBuilder("label");
            if (InlineValue)
            {
                lbl.AddCssClass("checkbox-inline");
            }
            lbl.WriteStartTag(writer);

            var input = context.CreateTagBuilder("input");
            input.MergeAttribute("type", "checkbox");
            if (ControlContextValue != null)
            {
                input.MergeAttribute("id", ControlContextValue.Name);
                input.MergeAttribute("name", ControlContextValue.Name);
                input.MergeAttribute("value", "true");
                var controlValue = ControlContextValue.Value;
                if (controlValue != null && bool.Parse(controlValue.ToString()))
                {
                    input.MergeAttribute("checked", "checked");
                }
            }
            if (DisabledValue)
            {
                input.MergeAttribute("disabled", "disabled");
            }

            ApplyCss(input);
            ApplyAttributes(input);

            ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata));

            input.WriteFullTag(writer);

            writer.Write(" "); // writing space to separate text from checkbox itself

            writer.Write(context.HtmlEncode(TextValue));

            lbl.WriteEndTag(writer);

            if (div != null)
            {
                div.WriteEndTag(writer);
            }
        }
Пример #5
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form      = context.PeekNearest <IFormContext>();
            var formGroup = context.PeekNearest <FormGroup>();

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return(string.Empty);
            }

            ITagBuilder tb  = null;
            ITagBuilder tb2 = null;

            if (form != null && form.TypeValue == FormType.Horizontal)
            {
                tb = context.CreateTagBuilder("div");
                tb.AddCssClass(form.ControlsWidthValue.ToCssClass());
                if (WithoutLabelValue)
                {
                    tb.AddCssClass(form.ControlsWidthValue.Invert().ToOffsetCssClass());
                }

                ApplyCss(tb);
                ApplyAttributes(tb);

                tb.WriteStartTag(writer);
            }

            if (formGroup != null && formGroup.WithSizedControlValue)
            {
                tb2 = context.CreateTagBuilder("div");
                tb2.AddCssClass("row");
                tb2.WriteStartTag(writer);
            }

            if (tb != null && tb2 != null)
            {
                return(tb2.GetEndTag() + tb.GetEndTag());
            }
            if (tb2 != null)
            {
                return(tb2.GetEndTag());
            }
            if (tb != null)
            {
                return(tb.GetEndTag());
            }
            return(string.Empty);
        }
Пример #6
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("form");

            if (TypeValue != FormType.DefaultNone)
            {
                tb.AddCssClass(TypeValue.ToCssClass());
            }
            if (MethodValue != SubmitMethod.Get)
            {
                tb.MergeAttribute("method", MethodValue.ToString().ToLowerInvariant());
            }
            if (EnctypeValue != FormEnctype.NoValue)
            {
                tb.MergeAttribute("enctype", EnctypeValue.ToEnctype());
            }
            if (!string.IsNullOrEmpty(HrefValue))
            {
                tb.MergeAttribute("action", HrefValue);
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);
        }
Пример #7
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");

            tb.AddCssClass("btn-group");
            tb.AddCssClass(SizeValue.ToButtonGroupCssClass());
            if (VerticalValue)
            {
                tb.AddCssClass("btn-group-vertical");
            }
            if (JustifiedValue)
            {
                tb.AddCssClass("btn-group-justified");
            }
            if (DropUpValue)
            {
                tb.AddCssClass("dropup");
            }
            tb.MergeAttribute("role", "group");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);

            if (content != null)
            {
                content.WriteTo(writer, context);
            }
        }
Пример #8
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("option");

            if (ValueValue != null)
            {
                tb.MergeAttribute("value", ValueValue.ToString());
            }
            if (DisabledValue)
            {
                tb.MergeAttribute("disabled", "disabled");
            }

            var formGroup = context.PeekNearest<Select>();
            var controlContext = formGroup == null ? null : formGroup.ControlContextValue;
            if (controlContext != null && controlContext.Value != null && ValueValue != null && ValueValue.ToString().Equals(controlContext.Value.ToString()))
            {
                tb.MergeAttribute("selected", "selected");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return tb.GetEndTag();
        }
Пример #9
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var formGroup = context.PeekNearest <FormGroup>();

            if (formGroup != null && controlContext == null)
            {
                controlContext = formGroup.ControlContextValue;
            }

            var input = context.CreateTagBuilder("p");

            input.AddCssClass("form-control-static");
            if (controlContext != null)
            {
                input.MergeAttribute("id", controlContext.Name);
                var value = controlContext.Value;
                if (value != null)
                {
                    input.SetInnerText(value.ToString());
                }
            }
            if (DisabledValue)
            {
                // nothing - already read-only :)
            }

            ApplyCss(input);
            ApplyAttributes(input);

            writer.Write(input.GetFullTag());
        }
Пример #10
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("option");

            if (ValueValue != null)
            {
                tb.MergeAttribute("value", ValueValue.ToString());
            }
            if (DisabledValue)
            {
                tb.MergeAttribute("disabled", "disabled");
            }

            var formGroup      = context.PeekNearest <Select>();
            var controlContext = formGroup == null ? null : formGroup.ControlContextValue;

            if (controlContext != null && controlContext.Value != null && ValueValue != null && ValueValue.ToString().Equals(controlContext.Value.ToString()))
            {
                tb.MergeAttribute("selected", "selected");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return(tb.GetEndTag());
        }
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");
            tb.AddCssClass("divider");
            tb.MergeAttribute("role", "presentation");

            tb.WriteFullTag(writer);
        }
Пример #12
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");

            tb.AddCssClass("divider");
            tb.MergeAttribute("role", "presentation");

            tb.WriteFullTag(writer);
        }
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");
            tb.AddCssClass("dropdown-header");
            tb.MergeAttribute("role", "presentation");

            tb.WriteStartTag(writer);

            return tb.GetEndTag();
        }
Пример #14
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder(TagName);

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return(tb.GetEndTag());
        }
Пример #15
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            writer.Write("<nav>");

            var tb = context.CreateTagBuilder("ul");

            tb.AddCssClass("pagination");
            tb.AddCssClass(SizeValue.ToCssClass());

            tb.WriteStartTag(writer);
        }
Пример #16
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder(TagName);

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return tb.GetEndTag();
        }
Пример #17
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");

            tb.AddCssClass("dropdown-header");
            tb.MergeAttribute("role", "presentation");

            tb.WriteStartTag(writer);

            return(tb.GetEndTag());
        }
Пример #18
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");
            tb.MergeAttribute("role", "presentation");
            if (DisabledValue)
            {
                tb.AddCssClass("disabled");
            }

            tb.WriteStartTag(writer);

            var a = context.CreateTagBuilder("a");
            a.MergeAttribute("role", "menuitem");
            a.MergeAttribute("tabindex", "-1");
            a.MergeAttribute("href", DisabledValue ? "#" : HrefValue);

            a.WriteStartTag(writer);

            return "</a></li>";
        }
Пример #19
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");

            tb.AddCssClass("row");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);
        }
Пример #20
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");
            tb.AddCssClass("panel-heading");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return tb.GetEndTag();
        }
Пример #21
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("span");

            tb.AddCssClass(TypeValue.ToCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return(tb.GetEndTag());
        }
Пример #22
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("li");

            tb.MergeAttribute("role", "presentation");
            if (DisabledValue)
            {
                tb.AddCssClass("disabled");
            }

            tb.WriteStartTag(writer);

            var a = context.CreateTagBuilder("a");

            a.MergeAttribute("role", "menuitem");
            a.MergeAttribute("tabindex", "-1");
            a.MergeAttribute("href", DisabledValue ? "#" : HrefValue);

            a.WriteStartTag(writer);

            return("</a></li>");
        }
Пример #23
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");
            tb.AddCssClass(SizeValue.ToCssClass());
            tb.AddCssClass(OffsetValue.ToOffsetCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return tb.GetEndTag();
        }
Пример #24
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder(GetTagName());

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (content != null)
            {
                content.WriteTo(writer, context);
            }
        }
Пример #25
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("dl");

            if (HorizontalValue)
            {
                tb.AddCssClass("dl-horizontal");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);
        }
Пример #26
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("th");

            if (ColorValue != TableRowCellColor.DefaultNone)
            {
                tb.AddCssClass(ColorValue.ToCssClass());
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return(tb.GetEndTag());
        }
Пример #27
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("ul");

            tb.AddCssClass("dropdown-menu");
            if (RightAlignValue)
            {
                tb.AddCssClass("dropdown-menu-right");
            }
            tb.MergeAttribute("role", "menu");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);
        }
Пример #28
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");

            tb.AddCssClass("btn-toolbar");
            tb.MergeAttribute("role", "toolbar");

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (content != null)
            {
                content.WriteTo(writer, context);
            }
        }
Пример #29
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form = context.PeekNearest <IFormContext>();
            var tb   = context.CreateTagBuilder("div");

            tb.AddCssClass("form-group");
            if (ControlContextValue != null)
            {
                if (ControlContextValue.HasErrors)
                {
                    tb.AddCssClass("has-error");
                }
                else if (ControlContextValue.HasWarning)
                {
                    tb.AddCssClass("has-warning");
                }
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);

            if (LabelValue != null)
            {
                LabelValue.WriteTo(writer, context);
            }

            if (ControlValue != null)
            {
                using (context.CreateWriter <FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent(writer))
                {
                    ControlValue.WriteTo(writer, context);
                }
            }

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return("</div> "); // trailing space is important for inline forms! Bootstrap does not provide spacing between groups in css!
            }

            return("</div>");
        }
Пример #30
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("tr");

            if (ColorValue != TableRowCellColor.DefaultNone)
            {
                tb.AddCssClass(ColorValue.ToCssClass());
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (content != null)
            {
                content.WriteTo(writer, context);
            }
        }
Пример #31
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("i");
            tb.AddCssClass(TypeValue.ToCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            if (!NoSpacingValue)
            {
                writer.Write(" ");
            }

            tb.WriteFullTag(writer);

            if (!NoSpacingValue)
            {
                writer.Write(" ");
            }
        }
Пример #32
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("table");

            tb.AddCssClass(StyleValue.ToCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (CaptionValue != null)
            {
                CaptionValue.WriteTo(writer, context);
            }
            if (HeaderValue != null)
            {
                HeaderValue.WriteTo(writer, context);
            }
        }
Пример #33
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder(TypeValue == ListType.Ordered ? "ol" : "ul");

            if (TypeValue == ListType.Unstyled)
            {
                tb.AddCssClass("list-unstyled");
            }

            if (TypeValue == ListType.Inline)
            {
                tb.AddCssClass("list-inline");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            endTag = tb.GetEndTag();
        }
Пример #34
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("i");

            tb.AddCssClass(TypeValue.ToCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            if (!NoSpacingValue)
            {
                writer.Write(" ");
            }

            tb.WriteFullTag(writer);

            if (!NoSpacingValue)
            {
                writer.Write(" ");
            }
        }
Пример #35
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("fieldset");

            if (DisabledValue)
            {
                tb.MergeAttribute("disabled", "disabled");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (LegendValue != null)
            {
                LegendValue.WriteTo(writer, context);
            }

            return("</fieldset>");
        }
Пример #36
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("fieldset");

            if (DisabledValue)
            {
                tb.MergeAttribute("disabled", "disabled");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (LegendValue != null)
            {
                LegendValue.WriteTo(writer, context);
            }

            return "</fieldset>";
        }
Пример #37
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var bg = context.PeekNearest <ButtonGroup>();

            if (bg == null)
            {
                WriteWhitespaceSuffix = true;
            }
            else
            {
                SizeValue = bg.SizeValue;
            }

            var withHref = !string.IsNullOrEmpty(HrefValue);
            var tb       = context.CreateTagBuilder(withHref ? "a" : "button");

            tb.AddCssClass(TypeValue.ToCssClass());
            tb.AddCssClass(SizeValue.ToButtonCssClass());

            if (DisabledValue)
            {
                tb.AddCssClass("disabled");
            }
            if (BlockSizeValue)
            {
                tb.AddCssClass("btn-block");
            }
            if (withHref)
            {
                tb.MergeAttribute("href", HrefValue);
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return(withHref ? "</a>" : "</button>");
        }
Пример #38
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("div");

            tb.AddCssClass(TypeValue.ToCssClass());

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (PanelHeaderValue != null)
            {
                PanelHeaderValue.WriteTo(writer, context);
            }
            if (PanelBodyValue != null)
            {
                PanelBodyValue.WriteTo(writer, context);
            }

            endTag = tb.GetEndTag();
        }
Пример #39
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form           = context.PeekNearest <IFormContext>();
            var groupContext   = context.PeekNearest <FormGroup>();
            var controlContext = groupContext == null ? null : groupContext.ControlContextValue;

            var required = groupContext == null ? false : groupContext.IsRequiredValue;
            var name     = controlContext == null ? null : controlContext.Name;

            var tb = context.CreateTagBuilder("label");

            if (form != null && form.TypeValue == FormType.Horizontal)
            {
                tb.AddCssClass("control-label");
                tb.AddCssClass(form.LabelWidthValue.ToCssClass());
            }

            if (!string.IsNullOrEmpty(name))
            {
                tb.MergeAttribute("for", name);
            }
            if (required)
            {
                tb.AddCssClass("required");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return(tb.GetEndTag() + " "); // trailing space is important for inline forms! Bootstrap does not provide spacing between groups in css!
            }

            return(tb.GetEndTag());
        }
Пример #40
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var bg = context.PeekNearest<ButtonGroup>();
            if (bg == null)
            {
                WriteWhitespaceSuffix = true;
            }
            else
            {
                SizeValue = bg.SizeValue;
            }

            var withHref = !string.IsNullOrEmpty(HrefValue);
            var tb = context.CreateTagBuilder(withHref ? "a" : "button");

            tb.AddCssClass(TypeValue.ToCssClass());
            tb.AddCssClass(SizeValue.ToButtonCssClass());

            if (DisabledValue)
            {
                tb.AddCssClass("disabled");
            }
            if (BlockSizeValue)
            {
                tb.AddCssClass("btn-block");
            }
            if (withHref)
            {
                tb.MergeAttribute("href", HrefValue);
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            return withHref ? "</a>" : "</button>";
        }
Пример #41
0
        protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var tb = context.CreateTagBuilder("optgroup");

            tb.MergeAttribute("label", LabelValue);

            if (DisabledValue)
            {
                tb.MergeAttribute("disabled", "disabled");
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            if (ItemsValue != null)
            {
                foreach (var item in ItemsValue)
                {
                    item.WriteTo(writer, context);
                }
            }
        }
Пример #42
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form = context.PeekNearest<IFormContext>();
            var tb = context.CreateTagBuilder("div");
            tb.AddCssClass("form-group");
            if (ControlContextValue != null)
            {
                if (ControlContextValue.HasErrors)
                {
                    tb.AddCssClass("has-error");
                }
                else if (ControlContextValue.HasWarning)
                {
                    tb.AddCssClass("has-warning");
                }
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);

            if (LabelValue != null)
            {
                LabelValue.WriteTo(writer, context);
            }

            if (ControlValue != null)
            {
                using (context.CreateWriter<FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent(writer))
                {
                    ControlValue.WriteTo(writer, context);
                }
            }

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return "</div> "; // trailing space is important for inline forms! Bootstrap does not provide spacing between groups in css!
            }

            return "</div>";
        }
Пример #43
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form      = context.PeekNearest <IFormContext>();
            var formGroup = context.PeekNearest <FormGroup>();

            if (formGroup != null && ControlContextValue == null)
            {
                ControlContextValue = formGroup.ControlContextValue;
            }

            ITagBuilder div = null;

            if (!SizeValue.IsEmpty())
            {
                // Inline forms does not support sized controls (we need 'some other' sizing rules?)
                if (form != null && form.TypeValue != FormType.Inline)
                {
                    if (formGroup != null && formGroup.WithSizedControlValue)
                    {
                        div = context.CreateTagBuilder("div");
                        div.AddCssClass(SizeValue.ToCssClass());
                        writer.Write(div.GetStartTag());
                    }
                    else
                    {
                        throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup.");
                    }
                }
            }

            var input = context.CreateTagBuilder("input");

            input.AddCssClass("form-control");
            var actualType = TypeValue;

            if (actualType != InputType.File && ControlContextValue != null)
            {
                input.MergeAttribute("id", ControlContextValue.Name);
                input.MergeAttribute("name", ControlContextValue.Name);
                if (ControlContextValue.IsRequired)
                {
                    input.MergeAttribute("required", "required");
                }
                var value = ControlContextValue.Value;
                if (value != null)
                {
                    var valueString = value.ToString();
                    if (TypeValue == InputType.Date || TypeValue == InputType.Datetime || TypeValue == InputType.DatetimeLocal || TypeValue == InputType.Time)
                    {
                        var valueDateTime       = value as DateTime?;
                        var valueDateTimeOffset = value as DateTimeOffset?;
                        var valueTimeSpan       = value as TimeSpan?;
                        if (valueDateTimeOffset.HasValue)
                        {
                            valueDateTime = valueDateTimeOffset.Value.DateTime;
                        }
                        if (valueDateTime.HasValue)
                        {
                            valueTimeSpan = valueDateTime.Value.TimeOfDay;
                        }
                        var asHtml5 = (DateInputMode == BootstrapMvc.DateInputMode.Html5);
                        if (!asHtml5)
                        {
                            actualType = InputType.Text;
                        }
                        switch (TypeValue)
                        {
                        case InputType.Date:
                            if (valueDateTime.HasValue)
                            {
                                valueString = asHtml5
                                        ? valueDateTime.Value.ToString("yyyy-MM-dd")
                                        : valueDateTime.Value.ToString("d");
                            }
                            break;

                        case InputType.DatetimeLocal:
                            if (valueDateTime.HasValue)
                            {
                                valueString = asHtml5
                                        ? valueDateTime.Value.ToString("o")
                                        : valueDateTime.Value.ToString();
                            }
                            break;

                        case InputType.Datetime:
                            if (valueDateTime.HasValue)
                            {
                                valueString = asHtml5
                                        ? valueDateTimeOffset.Value.ToString("o")
                                        : valueDateTimeOffset.Value.ToString();
                            }
                            break;

                        case InputType.Time:
                            if (valueDateTime.HasValue)
                            {
                                valueString = valueTimeSpan.ToString();
                            }
                            break;
                        }
                    }
                    input.MergeAttribute("value", valueString);
                }
            }

            if (actualType != InputType.Text)
            {
                input.MergeAttribute("type", actualType.ToType());
            }
            if (DisabledValue)
            {
                input.MergeAttribute("disabled", "disabled");
            }

            ApplyCss(input);
            ApplyAttributes(input);

            ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata));

            writer.Write(input.GetFullTag());

            if (div != null)
            {
                writer.Write(div.GetEndTag());
            }
        }