Created
May 4, 2023 13:42
-
-
Save hishaamn/f58ee8cacfa6cbfef809f33895841a39 to your computer and use it in GitHub Desktop.
Notification Manager to trigger the toast message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Events; | |
using Sitecore.Experiment.Notification.Models; | |
using Sitecore.Web.UI.Sheer; | |
using System; | |
public class CmsNotificationManager | |
{ | |
private static bool _initialized; | |
private static readonly object globalLock = new object(); | |
public static void Initialize() | |
{ | |
if (_initialized) | |
{ | |
return; | |
} | |
lock (globalLock) | |
{ | |
if (_initialized) | |
{ | |
return; | |
} | |
try | |
{ | |
Event.Subscribe("cms:notify", new EventHandler(CmsNotifier)); | |
} | |
finally | |
{ | |
_initialized = true; | |
} | |
} | |
} | |
private static void CmsNotifier(object sender, EventArgs args) | |
{ | |
var parameters = Event.ExtractParameter<NotifierArgs>(args, 0); | |
var message = string.Empty; | |
switch (parameters.EventName) | |
{ | |
case "package:end": | |
{ | |
message = "The package installation has completed"; | |
break; | |
} | |
case "item:save": | |
{ | |
message = "The item has been saved"; | |
break; | |
} | |
} | |
var script = $"toastr.info('{message}')"; | |
SheerResponse.Eval(script); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment