Esempio n. 1
0
        /// <summary>
        /// Creates a Bootstrap icon
        /// </summary>
        /// <param name="icon">Icon to be created</param>
        /// <param name="htmlAttributes">[Optional] Any extra HTML attributes</param>
        /// <returns>A Bootstrap icon</returns>
        public static IHtmlComponent CreateIcon(EBootstrapIcon icon, object htmlAttributes = null)
        {
            NameValueCollection htmlAttribs = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            List <string> cssClasses = new List <string>();

            if (htmlAttribs.ContainsKey("class"))
            {
                cssClasses.AddRange(htmlAttribs["class"].Split(' '));
                htmlAttribs.Remove("class");
            }

            switch (WebExtrasSettings.BootstrapVersion)
            {
            case EBootstrapVersion.V2:
                cssClasses.Add("icon-" + icon.ToString().ToLowerInvariant().Replace("_", "-"));
                break;

            case EBootstrapVersion.V3:
                cssClasses.Add("glyphicon glyphicon-" + icon.ToString().ToLowerInvariant().Replace("_", "-"));
                break;

            default:
                throw new BootstrapVersionException();
            }

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.AddRange(cssClasses);
            return(i);
        }
        /// <summary>
        ///   Create bootstrap 3 tags
        /// </summary>
        /// <param name="htmlAttributes">Extra HTML attributes</param>
        private void CreateBootstrap3Tags(object htmlAttributes)
        {
            var defaultAttribs = new Dictionary <string, string>
            {
                { "type", "text" },
                { "id", WebExtrasUtil.GetFieldIdFromExpression(m_propertyExpression) },
                { "name", WebExtrasUtil.GetFieldNameFromExpression(m_propertyExpression) }
            };

            DataTypeAttribute[] customAttribs =
                (DataTypeAttribute[])m_propertyExpression.Member.GetCustomAttributes(typeof(DataTypeAttribute), false);
            if (customAttribs.Length > 0)
            {
                switch (customAttribs[0].DataType)
                {
                case DataType.EmailAddress:
                    defaultAttribs["type"] = "email";
                    break;

                case DataType.Password:
                    defaultAttribs["type"] = "password";
                    break;

                case DataType.MultilineText:
                    defaultAttribs["type"] = "textarea";
                    break;
                }
            }

            Dictionary <string, string> attribs = WebExtrasUtil
                                                  .AnonymousObjectToHtmlAttributes(htmlAttributes)
                                                  .ToDictionary()
                                                  .Merge(defaultAttribs)
                                                  .ToDictionary(k => k.Key, v => v.Value);

            HtmlComponent input;

            if (m_selectListItems != null)
            {
                input = new HtmlSelect(m_selectListItems, attribs);
            }
            else if (m_textAreaDimensions != null || attribs.ContainsValue("textarea"))
            {
                attribs.Remove("type");

                input = new HtmlComponent(EHtmlTag.TextArea, attribs);
            }
            else
            {
                input = new HtmlComponent(EHtmlTag.Input, attribs);
            }

            input.CssClasses.Add("form-control");

            Input      = input;
            InputGroup = new HtmlComponent(EHtmlTag.Div);
            InputGroup.CssClasses.Add("input-group");
            InputGroup.AppendTags.Add(input);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an icon
        /// </summary>
        /// <param name="icon">Icon to be created</param>
        /// <param name="htmlAttributes">[Optional] Any extras HTML attributes</param>
        /// <returns>A Gumby icon</returns>
        public static IHtmlComponent CreateIcon(EGumbyIcon icon, object htmlAttributes = null)
        {
            NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.Add("icon-" + icon.ToString().ToLowerInvariant().Replace('_', '-'));

            foreach (string key in attrsDictionary.Keys)
            {
                i.Attributes[key] = attrsDictionary[key];
            }

            return(i);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a Bootstrap Font-Awesome icon
        /// </summary>
        /// <param name="icon">Icon to be rendered</param>
        /// <param name="size">Icon size</param>
        /// <param name="htmlAttributes">Extra HTML attributes</param>
        /// <returns>A Bootstrap icon</returns>
        /// <exception cref="FontAwesomeVersionException">Thrown when a valid FontAwesome
        /// icon library version is not selected</exception>
        public static IHtmlComponent CreateIcon(EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null)
        {
            NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            List <string> cssClasses = new List <string>();

            if (attrsDictionary.ContainsKey("class"))
            {
                cssClasses.AddRange(attrsDictionary["class"].Split(' '));
                attrsDictionary.Remove("class");
            }

            string prefix;

            switch (WebExtrasSettings.FontAwesomeVersion)
            {
            case EFontAwesomeVersion.V3:
                prefix = "icon-";
                break;

            case EFontAwesomeVersion.V4:
                prefix = "fa fa-";
                break;

            default:
                throw new FontAwesomeVersionException();
            }

            cssClasses.Add(prefix + icon.ToString().ToLowerInvariant().Replace("_", "-"));

            if (size != EFontAwesomeIconSize.Normal)
            {
                cssClasses.Add(prefix + size.GetStringValue());
            }

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.AddRange(cssClasses);

            foreach (string key in attrsDictionary.Keys)
            {
                i.Attributes[key] = attrsDictionary[key];
            }

            return(i);
        }
Esempio n. 5
0
        /// <summary>
        ///   Constructor to specify extra HTML attributes as an anonymous type
        /// </summary>
        /// <param name="tag">An HTML tag to initialise this element with</param>
        /// <param name="htmlAttributes">Extra HTML attributes</param>
        public HtmlComponent(EHtmlTag tag, object htmlAttributes = null)
        {
            Tag        = tag;
            Attributes = new Dictionary <string, string>();
            CssClasses = new CssClassList();

            AppendTags  = new HtmlComponentList();
            PrependTags = new HtmlComponentList();

            if (htmlAttributes == null)
            {
                return;
            }

            bool isDict = (htmlAttributes as IDictionary <string, string>) != null;

            if (isDict)
            {
                Attributes = (IDictionary <string, string>)htmlAttributes;
                if (!Attributes.ContainsKey("class"))
                {
                    return;
                }

                CssClasses.Add(Attributes["class"]);
                Attributes.Remove("class");

                return;
            }

            NameValueCollection attribs = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            foreach (string key in attribs.Keys)
            {
                if (key.Equals("class", StringComparison.OrdinalIgnoreCase))
                {
                    CssClasses.Clear();
                    CssClasses.Add(attribs[key]);
                    continue;
                }

                Attributes[key] = attribs[key];
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a jQuery UI icon
        /// </summary>
        /// <param name="icon">Icon to be created</param>
        /// <param name="htmlAttributes">[Optional] Any extra HTML attributes</param>
        /// <returns>A jQuery UI icon</returns>
        public static IHtmlComponent CreateIcon(EJQueryUIIcon icon, object htmlAttributes = null)
        {
            NameValueCollection rvd = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            List <string> cssClasses = new List <string>();

            if (rvd.ContainsKey("class"))
            {
                cssClasses.AddRange(rvd["class"].Split(' '));
                rvd.Remove("class");
            }

            cssClasses.Add("ui-icon");
            cssClasses.Add("ui-icon-" + icon.ToString().ToLowerInvariant().Replace("_", "-"));

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.AddRange(cssClasses);

            return(i);
        }
        /// <summary>
        ///   Add an icon
        /// </summary>
        /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam>
        /// <param name="html">Current html element</param>
        /// <param name="cssClasses">Css classes to be added</param>
        /// <param name="htmlAttributes">[Optional] Extra html attributes</param>
        /// <returns>HTML element with icon added</returns>
        private static T AddIcon <T>(T html, IEnumerable <string> cssClasses, object htmlAttributes = null)
            where T : IExtendedHtmlString
        {
            NameValueCollection rvd = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            List <string> finalClasses = new List <string>(cssClasses);

            if (rvd.ContainsKey("class"))
            {
                finalClasses.AddRange(rvd["class"].Split(' '));
                rvd.Remove("class");
            }

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.AddRange(finalClasses);

            foreach (string key in rvd.Keys)
            {
                i.Attributes[key] = rvd[key];
            }

            // TODO: remove unnecessary conversion
            html.Component.PrependTags.Add(i);

            if (html.Component.Attributes.ContainsKey("style"))
            {
                html.Component.Attributes["style"] += ";text-decoration:none";
            }
            else
            {
                html.Component.Attributes["style"] = "text-decoration:none";
            }

            return(html);
        }
        /// <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);
        }