using NTDLS.Helpers; using System.Text; namespace ZelWiki.Library { public static class ConfirmActionHelper { /// /// Generates a link that navigates via GET to a "confirm action" page where the yes link is RED, but the NO button is still GREEN. /// /// The message to be displayed. /// the label for the link that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. /// public static string GenerateDangerLink(string basePath, string message, string linkLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var param = new StringBuilder(); param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}"); param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}"); param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}"); param.Append($"&Message={Uri.EscapeDataString(message)}"); param.Append($"&Style=Danger"); return $"{linkLabel}"; } /// /// Generates a link that navigates via GET to a "confirm action" page where the yes link is GREEN. /// /// The message to be displayed. /// the label for the link that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. /// public static string GenerateSafeLink(string basePath, string message, string linkLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var param = new StringBuilder(); param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}"); param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}"); param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}"); param.Append($"&Message={Uri.EscapeDataString(message)}"); param.Append($"&Style=Safe"); return $"{linkLabel}"; } /// /// Generates a link that navigates via GET to a "confirm action" page where the yes link is YELLOW, but the NO button is still GREEN. /// /// The message to be displayed. /// the label for the link that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. /// public static string GenerateWarnLink(string basePath, string message, string linkLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var param = new StringBuilder(); param.Append($"ControllerURL={Uri.EscapeDataString($"{basePath}{controllerURL}")}"); param.Append($"&YesRedirectURL={Uri.EscapeDataString(yesOrDefaultRedirectURL)}"); param.Append($"&NoRedirectURL={Uri.EscapeDataString(noRedirectURL)}"); param.Append($"&Message={Uri.EscapeDataString(message)}"); param.Append($"&Style=Warn"); return $"{linkLabel}"; } /* /// /// Generates a link that navigates via POST to a "confirm action" page where the yes button is RED, but the NO button is still GREEN. /// /// The message to be displayed. /// the label for the button that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. /// public static string GenerateDangerButton(string message, string buttonLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var html = new StringBuilder(); html.Append("
"); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append("
"); return html.ToString(); } /// /// Generates a link that navigates via POST to a "confirm action" page where the yes and no buttons are GREEN. /// /// The message to be displayed. /// the label for the button that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. public static string GenerateSafeButton(string message, string buttonLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var html = new StringBuilder(); html.Append("
"); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append("
"); return html.ToString(); } /// /// Generates a link that navigates via POST to a "confirm action" page where the yes button is YELLOW, but the NO button is still GREEN. /// /// The message to be displayed. /// the label for the button that will redirect to this confirm action page. /// The URL which will handle the click of the "yes" or "no" for the confirm action page. /// An optional parameter to pass to the page and controller function. /// The URL to redirect to AFTER the controller has been called if the user selected YES (or NO, if the NO link is not specified. /// The URL to redirect to AFTER the controller has been called if the user selected NO, if not specified, the same link that is provided to yesOrDefaultRedirectURL is used. public static string GenerateWarnButton(string message, string buttonLabel, string controllerURL, string? yesOrDefaultRedirectURL, string? noRedirectURL = null) { noRedirectURL ??= yesOrDefaultRedirectURL; yesOrDefaultRedirectURL.EnsureNotNull(); noRedirectURL.EnsureNotNull(); var html = new StringBuilder(); html.Append("
"); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append($""); html.Append("
"); return html.ToString(); } */ } }