Exemple #1
0
        /// <summary>
        ///   Creates an alert
        /// </summary>
        /// <param name="type">Type of alert</param>
        /// <param name="message">Alert message</param>
        /// <param name="title">Title/Heading of the alert</param>
        /// <param name="icon">Icon to be rendered with title/heading</param>
        private void CreateAlert(EMessage type, string message, string title, IHtmlComponent icon)
        {
            CssClasses.Add(type.GetStringValue());

            HtmlComponent bc = new HtmlComponent(EHtmlTag.B)
            {
                InnerHtml = title ?? string.Empty
            };

            if (icon != null)
            {
                bc.PrependTags.Add(icon);
            }

            if (WebExtrasSettings.CssFramework != ECssFramework.JQueryUI)
            {
                CssClasses.Add("alert");

                Button closeBtn = new Button(EButton.Regular, "&times;", string.Empty);
                closeBtn.CssClasses.Add("close");
                closeBtn.Attributes["data-dismiss"] = "alert";

                PrependTags.Add(closeBtn);
                PrependTags.Add(bc);
                InnerHtml = (!string.IsNullOrWhiteSpace(title) || icon != null)
          ? WebExtrasSettings.HTMLSpace + message
          : message;
            }
            else
            {
                HtmlComponent div = new HtmlComponent(EHtmlTag.Div);

                switch (type)
                {
                case EMessage.Error:
                    div.CssClasses.Add("ui-state-error");
                    break;

                case EMessage.Information:
                case EMessage.Warning:
                    div.CssClasses.Add("ui-state-highlight");
                    break;

                case EMessage.Success:
                    div.CssClasses.Add("ui-state-success");
                    break;
                }

                div.CssClasses.Add("ui-corner-all");
                div.PrependTags.Add(bc);
                div.InnerHtml = (!string.IsNullOrWhiteSpace(title) || icon != null)
          ? WebExtrasSettings.HTMLSpace + message
          : message;

                PrependTags.Add(div);
            }

            Type = type;
        }
Exemple #2
0
        /// <summary>
        ///   HtmlHelper extension method to save a message to the Controller.TempData session cache using the key:
        ///   TempDataMessageKey.
        ///   TempData is only alive for one request only before being wiped.
        /// </summary>
        /// <param name="helper">HtmlHelper</param>
        /// <returns>The last message if available in a div object</returns>
        public static MvcHtmlString GetLastActionMessage(this HtmlHelper helper)
        {
            if (!helper.ViewContext.TempData.ContainsKey(TempDataMessageKey))
            {
                return(MvcHtmlString.Empty);
            }

            // get message
            string       message   = helper.ViewContext.TempData[TempDataMessageKey].ToString();
            EMessage     type      = (EMessage)helper.ViewContext.TempData[TempDataMessageTypeKey];
            const string controlId = "actionmessage";

            // create the dismiss button
            //<button type="button" class="close" data-dismiss="alert">&times;</button>
            TagBuilder dismissBtn = new TagBuilder("button");

            dismissBtn.AddCssClass("close");
            dismissBtn.Attributes["data-dismiss"] = "alert";
            dismissBtn.Attributes["aria-hidden"]  = "true";
            dismissBtn.InnerHtml = "&times;";

            // create action message div
            TagBuilder builder = new TagBuilder("span");

            builder.Attributes["class"] = "alert alert-dismissable keep-center strong";
            builder.GenerateId(controlId);
            builder.AddCssClass(type.GetStringValue());
            builder.InnerHtml = dismissBtn.ToString(TagRenderMode.Normal) + message;

            // create the script tag
            TagBuilder script = new TagBuilder("script");

            script.Attributes["type"] = "text/javascript";

            StringBuilder sb = new StringBuilder();

            sb.Append("$(document).ready(function () { ");
            sb.Append("\n");
            sb.Append("var control = $('#" + controlId + "');");
            sb.Append("\n");

            switch (type)
            {
            case EMessage.Success:
                sb.Append("control.delay(3000).fadeOut('500');");
                break;

            default:
                sb.Append("control.fadeIn('500');");
                break;
            }
            sb.Append("\n");
            sb.Append("});");

            script.InnerHtml = sb.ToString();

            return(MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal) + script.ToString(TagRenderMode.Normal)));
        }