Beispiel #1
0
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="options">List of options</param>
        /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
        public HtmlSelect(string[] options, object htmlAttributes = null)
            : base(EHtmlTag.Select, htmlAttributes)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "Select list options cannot be null");
            }

            Array.ForEach(options, f =>
            {
                var option = new HtmlComponent(EHtmlTag.Option, new { value = f })
                {
                    InnerHtml = f
                };
                AppendTags.Add(option);
            });
        }
Beispiel #2
0
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="options">List of options</param>
        /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
        public HtmlSelect(IEnumerable <HtmlSelectListOption> options, object htmlAttributes = null)
            : base(EHtmlTag.Select, htmlAttributes)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "Select list options cannot be null");
            }

            Array.ForEach(options.ToArray(), f =>
            {
                var option = new HtmlComponent(EHtmlTag.Option, new { value = f.Value })
                {
                    InnerHtml = f.Text
                };

                if (f.Selected)
                {
                    option.Attributes["selected"] = "true";
                }

                AppendTags.Add(option);
            });
        }
        /// <summary>
        ///   Creates a Bootstrap navigation bar from the given
        ///   list of items
        /// </summary>
        /// <param name="list">Navigation bar items</param>
        private void CreateNavBar(HtmlList list)
        {
            list.Attributes["class"] = "nav navbar-nav";

            Attributes["class"] = Type.GetStringValue();

            switch (WebExtrasSettings.BootstrapVersion)
            {
            case EBootstrapVersion.V2:
                HtmlComponent innerNav = new HtmlComponent(EHtmlTag.Div);

                innerNav.Attributes["class"] = "navbar-inner";

                if (Brand != null)
                {
                    innerNav.PrependTags.Add(Brand.Component);
                }

                innerNav.AppendTags.Add(list);

                AppendTags.Add(innerNav);
                break;

            case EBootstrapVersion.V3:
                if (Brand != null)
                {
                    Brand.Attributes["class"] = "navbar-brand";
                    PrependTags.Add(Brand.Component);
                }

                AppendTags.Add(list);
                break;

            default:
                throw new BootstrapVersionException();
            }
        }
Beispiel #4
0
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name="type">Type of list</param>
 /// <param name="listItems">A collection of items</param>
 /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
 public HtmlList(EList type, IEnumerable <HtmlListItem> listItems, object htmlAttributes = null)
     : base(type == EList.Ordered ? EHtmlTag.Ol : EHtmlTag.Ul, htmlAttributes)
 {
     Type = type;
     AppendTags.AddRange(listItems);
 }
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="name">HTML field name</param>
        /// <param name="id">HTML field id</param>
        /// <param name="options">Date time picker options</param>
        /// <param name="htmlAttributes">Extra HTML attributes</param>
        public DateTimePickerHtmlComponent(string name, string id, PickerOptions options, object htmlAttributes)
            : base(EHtmlTag.Div)
        {
            PickerOptions pickerOptions =
                (options ?? BootstrapSettings.DateTimePickerOptions).TryFontAwesomeIcons();

            string fieldId   = id;
            string fieldName = name;

            // create the text box
            HtmlComponent input   = new HtmlComponent(EHtmlTag.Input);
            var           attribs = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes).ToDictionary();

            input.Attributes.Add(attribs);
            input.Attributes["type"] = "text";
            input.Attributes["name"] = fieldName;

            if (input.Attributes.ContainsKey("class"))
            {
                input.Attributes["class"] += " form-control";
            }
            else
            {
                input.Attributes["class"] = "form-control";
            }

            // create icon
            HtmlComponent icons = new HtmlComponent(EHtmlTag.I);

            if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V4)
            {
                icons.CssClasses.Add("fa fa-calendar");
            }
            else if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V3)
            {
                icons.CssClasses.Add("icon-calendar");
            }
            else
            {
                icons.CssClasses.Add("glyphicon glyphicon-calendar");
            }

            // create addon
            HtmlComponent addOn = new HtmlComponent(EHtmlTag.Span);

            addOn.CssClasses.Add("input-group-addon");
            addOn.AppendTags.Add(icons);

            // create JSON dictionary of the picker options
            string op = pickerOptions.ToJson(new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            HtmlComponent script = new HtmlComponent(EHtmlTag.Script);

            script.Attributes["type"] = "text/javascript";
            script.InnerHtml          = "$(function(){ $('#" + fieldId + "').datetimepicker(" + op + "); });";

            // setup up datetime picker
            Attributes["id"]    = fieldId;
            Attributes["class"] = "input-group date";
            AppendTags.Add(input);
            AppendTags.Add(addOn);
            AppendTags.Add(script);
        }