/// <summary> /// This function generates an script string to show a message growl /// </summary> /// <param name="msg">Content of the message</param> /// <param name="type">Type of the message, can be one of {success, warning, info, danger}</param> /// <param name="title">Header message</param> /// <param name="position">The position for Toastr</param> /// <param name="addOnDocumentReady">set true to add jquery Document ready to script</param> /// <returns>string contains script needed to show a message growl</returns> public static string ShowToast(string title, string msg, MessageType type, ToastrPosition position = ToastrPosition.BottomRight, bool addOnDocumentReady = false, bool addScript = true) { // ShowToast(title, msg, position, type) var str = new StringBuilder(); if (addScript) { str.Append("<script>"); } if (addOnDocumentReady) { str.Append("$(function() {"); } if (type == MessageType.Message || type == MessageType.Question) { type = MessageType.Info; } str.Append($"ShowToast('{title}', `{msg}`, '{position.GetDescription()}', '{type.GetDescription()}');"); if (addOnDocumentReady) { str.Append("});"); } if (addScript) { str.Append("</script>"); } return(str.ToString()); }
public static string ToClassName(this ToastrPosition position) { switch (position) { case ToastrPosition.TopRight: return("toast-top-right"); case ToastrPosition.BottomRight: return("toast-bottom-right"); case ToastrPosition.BottomLeft: return("toast-bottom-left"); case ToastrPosition.TopLeft: return("toast-top-left"); case ToastrPosition.TopFullWidth: return("toast-top-full-width"); case ToastrPosition.BottomFullWidth: return("toast-bottom-full-width"); case ToastrPosition.TopCenter: return("toast-bottom-full-width"); case ToastrPosition.BottomCenter: return("toast-bottom-center"); default: return("toast-top-right"); } }