Example #1
0
        protected override void OnStart(TextWriter writer)
        {
            // Change to a div if no link was provided, otherwise wrap in a div
            string href = GetAttribute("href");

            if (string.IsNullOrWhiteSpace(href))
            {
                TagName = "div";
            }
            else
            {
                // Copy media CSS classes to the wrapping div
                _wrapper = GetHelper().Div().Component;
                foreach (string mediaClass in CssClasses.Where(x => x.StartsWith("media-")).ToList())
                {
                    _wrapper.AddCss(mediaClass);
                    CssClasses.Remove(mediaClass);
                }
                _wrapper.Start(writer);
            }

            base.OnStart(writer);

            _image = GetHelper().Image(Src, Alt).AddCss(Css.MediaObject).Component;
            _image.Start(writer);
        }
        // This prepares the outer form group if we need one
        // Needs to be in a separate method so that derived classes can create the form group before outputting any wrappers of their own
        protected void Prepare(TextWriter writer)
        {
            // Only prepare once
            if (_prepared)
            {
                return;
            }
            _prepared = true;

            // Make sure we're in a form group
            IFormGroup formGroup = GetComponent <IFormGroup>();

            if (formGroup == null && EnsureFormGroup)
            {
                _formGroup = new FormGroup <THelper>(Helper);
                formGroup  = _formGroup;
            }

            // Move any validation classes to the form group, but only if it's implicit for this control and doesn't already have any
            if (CssClasses.Any(x => x.StartsWith("has-")) && _formGroup != null && formGroup != null && !formGroup.CssClasses.Any(x => x.StartsWith("has-")))
            {
                foreach (string formValidation in CssClasses.Where(x => x.StartsWith("has-")))
                {
                    formGroup.CssClasses.Add(formValidation);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("has-"));
            }

            // Move any grid column classes to the form group, but only if it's implicit for this control and doesn't already have any
            if (CssClasses.Any(x => x.StartsWith("col-")) && _formGroup != null && formGroup != null && !formGroup.CssClasses.Any(x => x.StartsWith("col-")))
            {
                foreach (string col in CssClasses.Where(x => x.StartsWith("col-")))
                {
                    formGroup.CssClasses.Add(col);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("col-"));
            }

            // Add the label to the form group or write it
            if (_label != null)
            {
                // Set the label's for attribute to the input name
                string name = Attributes.GetValue("name");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    _label.MergeAttribute("for", name);
                }

                // Add or write the label
                if (_formGroup != null)
                {
                    _formGroup.ControlLabel = _label;
                }
                else
                {
                    _label.StartAndFinish(writer);
                }
            }

            // Start the new form group if we created one
            if (_formGroup != null)
            {
                _formGroup.Start(writer);
            }

            _prepared = true;
        }
Example #3
0
        protected override void OnStart(TextWriter writer)
        {
            // Set column classes if we're horizontal
            if (AutoColumns)
            {
                ComponentBuilder <BootstrapConfig, FormGroup> builder = GetBuilder(this);
                Form form = GetComponent <Form>();
                if ((form != null && form.Horizontal && (!Horizontal.HasValue || Horizontal.Value)) || (Horizontal.HasValue && Horizontal.Value))
                {
                    int labelWidth = form == null ? Config.DefaultFormLabelWidth : form.DefaultLabelWidth;

                    // Set label column class
                    if (_label != null && !_label.CssClasses.Any(x => x.StartsWith("col-")))
                    {
                        _label.SetColumnClass(Config, "col-md-", labelWidth);
                    }

                    // Add column classes to this (these will get moved to a wrapper later in this method)
                    if (!CssClasses.Any(x => x.StartsWith("col-")))
                    {
                        builder.SetMd(Config.GridColumns - labelWidth);

                        // Also need to add an offset if no label
                        if (_label == null)
                        {
                            builder.SetMdOffset(labelWidth);
                        }
                    }
                }
                else if (form != null && form.Horizontal)
                {
                    // If the form is horizontal but we requested not to be, create a full-width column wrapper
                    builder.SetMd(Config.GridColumns);
                    _columnWrapperBeforeLabel = true;
                }
            }

            // Move any grid column classes to a container class
            if (CssClasses.Any(x => x.StartsWith("col-")))
            {
                _columnWrapper = GetHelper().Element("div").AddCss(CssClasses.Where(x => x.StartsWith("col-")).ToArray()).Component;
            }
            CssClasses.RemoveWhere(x => x.StartsWith("col-"));

            base.OnStart(writer);

            // Write the column wrapper first if needed
            if (_columnWrapperBeforeLabel && _columnWrapper != null)
            {
                _columnWrapper.Start(writer);
            }

            // Write the label
            if (_label != null)
            {
                _label.StartAndFinish(writer);
            }

            // Write the column wrapper
            if (!_columnWrapperBeforeLabel && _columnWrapper != null)
            {
                _columnWrapper.Start(writer);
            }

            // Add the feedback icon as a final child of either this or the wrapper
            if (Icon != Icon.None)
            {
                Component icon = GetHelper().Icon(Icon).AddCss(Css.FormControlFeedback).Component;
                if (_columnWrapper == null)
                {
                    AddChildAtEnd(icon);
                }
                else
                {
                    _columnWrapper.AddChildAtEnd(icon);
                }
            }
            else if (IconFontAwesome != IconFontAwesome.None)
            {
                Component icon = GetHelper().Icon(IconFontAwesome).AddCss(Css.FormControlFeedback).Component;
                if (_columnWrapper == null)
                {
                    AddChildAtEnd(icon);
                }
                else
                {
                    _columnWrapper.AddChildAtEnd(icon);
                }
            }
        }
Example #4
0
        protected override void OnStart(TextWriter writer)
        {
            // Check if we're in a navbar, and if so, make sure we're in a navbar nav
            if (GetComponent <Navbar>() != null && GetComponent <NavbarNav>() == null)
            {
                GetHelper().NavbarNav().Component.Start(writer);
            }

            // Check if we're in a nav
            if (GetComponent <Nav>(true) != null || GetComponent <NavbarNav>(true) != null)
            {
                TagName = "li";
                Link link = GetHelper().Link(null).Component;
                link.AddCss(Css.DropdownToggle);
                link.MergeAttribute("data-toggle", "dropdown");
                _toggle = link;
            }
            else
            {
                // Create a button and copy over any button classes and text
                Button button = GetHelper().Button().Component;
                button.RemoveCss(Css.BtnDefault);
                button.AddCss(Css.DropdownToggle);
                button.MergeAttribute("data-toggle", "dropdown");
                foreach (string buttonClass in CssClasses.Where(x => x.StartsWith("btn")))
                {
                    button.CssClasses.Add(buttonClass);
                }
                _toggle = button;
            }
            CssClasses.RemoveWhere(x => x.StartsWith("btn"));

            // Add the text and caret
            if (TextContent != null)
            {
                _toggle.AddChild(GetHelper().Content(TextContent));
                _toggle.AddChild(GetHelper().Content(" "));
            }
            else
            {
                Element element = GetHelper().Element("span").AddCss(Css.SrOnly).Component;
                element.AddChild(GetHelper().Content("Toggle Dropdown"));
                _toggle.AddChild(element);
            }
            TextContent = null;
            if (Caret)
            {
                _toggle.AddChild(GetHelper().Caret());
            }

            // Check if we're in a InputGroupButton, then
            // Check if we're in a button group, and if so change the outer CSS class
            // Do this after copying over the btn classes so this doesn't get copied
            if (GetComponent <InputGroupButton>(true) != null)
            {
                _inputGroupButton = true;
            }
            else if (GetComponent <ButtonGroup>(true) != null)
            {
                ToggleCss(Css.BtnGroup, true, Css.Dropdown);
            }

            // Create the list
            _list = GetHelper().List(ListType.Unordered).Component;
            _list.AddCss(Css.DropdownMenu);
            _list.MergeAttribute("role", "menu");
            if (MenuRight)
            {
                _list.AddCss(Css.DropdownMenuRight);
            }
            if (MenuLeft)
            {
                _list.AddCss(Css.DropdownMenuLeft);
            }
            if (Scrollable)
            {
                _list.AddCss(Css.PreScrollable);
            }

            // Start this component
            base.OnStart(_inputGroupButton ? new SuppressOutputWriter() : writer);

            // Output the button
            _toggle.StartAndFinish(writer);

            // Output the start of the list
            _list.Start(writer);
        }
        // This prepares the outer form group if we need one
        // Needs to be in a separate method so that derived classes can create the form group before outputting any wrappers of their own
        public void Prepare(TextWriter writer)
        {
            // Only prepare once
            if (_prepared)
            {
                return;
            }
            _prepared = true;

            // Make sure we're in a form group, but only if we're also in a form
            FormGroup formGroup = null;

            if (GetComponent <Form>() != null && GetComponent <FormGroup>() == null && EnsureFormGroup)
            {
                formGroup = new FormGroup(GetHelper());
                _wrapper  = formGroup;
            }

            // Move any validation classes to the wrapper
            if (CssClasses.Any(x => x.StartsWith("has-")))
            {
                if (_wrapper == null)
                {
                    _wrapper = GetHelper().Element("div").Component;
                }
                foreach (string formValidation in CssClasses.Where(x => x.StartsWith("has-")))
                {
                    _wrapper.CssClasses.Add(formValidation);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("has-"));
            }

            // Move any grid column classes to the wrapper
            if (CssClasses.Any(x => x.StartsWith("col-")))
            {
                if (_wrapper == null)
                {
                    _wrapper = GetHelper().Element("div").Component;
                }
                foreach (string col in CssClasses.Where(x => x.StartsWith("col-")))
                {
                    _wrapper.CssClasses.Add(col);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("col-"));
            }

            // Add the label to the form group or write it
            if (_label != null)
            {
                // Set the label's for attribute to the input name
                string name = Attributes.GetValue("name");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    _label.MergeAttribute("for", name);
                }

                // Add or write the label
                if (formGroup != null)
                {
                    formGroup.ControlLabel = _label;
                }
                else
                {
                    _label.StartAndFinish(writer);
                }
            }

            // Start the new form group if we created one
            if (_wrapper != null)
            {
                _wrapper.Start(writer);
            }

            _prepared = true;
        }
Example #6
0
        protected override void OnStart(TextWriter writer)
        {
            // Check if we're in a navbar, and if so, make sure we're in a navbar nav
            if (GetComponent <INavbar>() != null && GetComponent <INavbarNav>() == null)
            {
                new NavbarNav <THelper>(Helper).Start(writer);
            }

            // Check if we're in a nav
            if (GetComponent <INav>(true) != null || GetComponent <INavbarNav>(true) != null)
            {
                TagName = "li";
                Link <THelper> link = Helper.Link(null);
                link.AddCss(Css.DropdownToggle);
                link.AddAttribute("data-toggle", "dropdown");
                _toggle = link;
            }
            else
            {
                // Create a button and copy over any button classes and text
                Button <THelper> button = Helper.Button();
                button.RemoveCss(Css.BtnDefault);
                button.AddCss(Css.DropdownToggle);
                button.AddAttribute("data-toggle", "dropdown");
                foreach (string buttonClass in CssClasses.Where(x => x.StartsWith("btn")))
                {
                    button.CssClasses.Add(buttonClass);
                }
                _toggle = button;
            }
            CssClasses.RemoveWhere(x => x.StartsWith("btn"));

            // Add the text and caret
            if (!string.IsNullOrWhiteSpace(TextContent))
            {
                _toggle.AddChild(new Content <THelper>(Helper, TextContent + " "));
            }
            else
            {
                Element <THelper> element = new Element <THelper>(Helper, "span").AddCss(Css.SrOnly);
                element.AddChild(new Content <THelper>(Helper, "Toggle Dropdown"));
                _toggle.AddChild(element);
            }
            TextContent = null;
            if (_caret)
            {
                _toggle.AddChild(Helper.Caret());
            }

            // Check if we're in a IDropdownButton or IInputGroupButton, then
            // Check if we're in a button group, and if so change the outer CSS class
            // Do this after copying over the btn classes so this doesn't get copied
            if (GetComponent <IDropdownButton>(true) != null || GetComponent <IInputGroupButton>(true) != null)
            {
                _dropdownButton = true;
            }
            else if (GetComponent <IButtonGroup>(true) != null)
            {
                ToggleCss(Css.BtnGroup, true, Css.Dropdown);
            }

            // Create the list
            _list = Helper.List(ListType.Unordered);
            _list.AddCss(Css.DropdownMenu);
            _list.MergeAttribute("role", "menu");
            if (_menuRight)
            {
                _list.AddCss(Css.DropdownMenuRight);
            }
            if (_menuLeft)
            {
                _list.AddCss(Css.DropdownMenuLeft);
            }

            // Start this component
            base.OnStart(_dropdownButton ? new SuppressOutputWriter() : writer);

            // Output the button
            _toggle.StartAndFinish(writer);

            // Output the start of the list
            _list.Start(writer);
        }
Example #7
0
        protected override void OnStart(TextWriter writer)
        {
            // Set column classes if we're horizontal
            IForm form = GetComponent <IForm>();

            if ((form != null && form.Horizontal && (!Horizontal.HasValue || Horizontal.Value)) || (Horizontal.HasValue && Horizontal.Value))
            {
                int labelWidth = form == null ? Helper.DefaultFormLabelWidth : form.DefaultLabelWidth;

                // Set label column class
                if (_label != null && !_label.CssClasses.Any(x => x.StartsWith("col-")))
                {
                    _label.SetColumnClass(Helper, "col-md-", labelWidth);
                }

                // Add column classes to this (these will get moved to a wrapper later in this method)
                if (!CssClasses.Any(x => x.StartsWith("col-")))
                {
                    this.SetMd(Helper.GridColumns - labelWidth);

                    // Also need to add an offset if no label
                    if (_label == null)
                    {
                        this.SetMdOffset(labelWidth);
                    }
                }
            }
            else if (form != null && form.Horizontal)
            {
                // If the form is horizontal but we requested not to be, create a full-width column wrapper
                this.SetMd(Helper.GridColumns);
                _columnWrapperBeforeLabel = true;
            }

            // Move any grid column classes to a container class
            if (CssClasses.Any(x => x.StartsWith("col-")))
            {
                _columnWrapper = Helper.Element("div").AddCss(CssClasses.Where(x => x.StartsWith("col-")).ToArray());
            }
            CssClasses.RemoveWhere(x => x.StartsWith("col-"));

            base.OnStart(writer);

            // Write the column wrapper first if needed
            if (_columnWrapperBeforeLabel && _columnWrapper != null)
            {
                _columnWrapper.Start(writer);
            }

            // Write the label
            if (_label != null)
            {
                _label.StartAndFinish(writer);
            }

            // Write the column wrapper
            if (!_columnWrapperBeforeLabel && _columnWrapper != null)
            {
                _columnWrapper.Start(writer);
            }
        }