I want to inform the user if he changed the title (or path) of a structuregroup or folder by broadcasting a message, using the eventsystem. No message however appears in the messageCenter.
Eventsystem:
EventSystem.Subscribe<OrganizationalItem, SaveEventArgs>(OnOrgItemSave, EventPhases.Initiated | EventPhases.Processed | EventPhases.TransactionCommitted);
public void OnOrgItemSave(OrganizationalItem orgItem, SaveEventArgs args, EventPhases phase)
{
if (phase == EventPhases.Processed)
{
if (IsRenamed(orgItem, args) || (orgItem is StructureGroup && IsDirectoryChanged((StructureGroup)orgItem, args)))
{
args.ContextVariables["Signalr4TridionMessage"] = "Caution! You changed the name or path of this item. Don't forget to ......";
}
}
if (phase == EventPhases.TransactionCommitted)
{
if (args.ContextVariables.ContainsKey(Signalr4TridionMessage))
{
string message = args.ContextVariables["Signalr4TridionMessage"].ToString();
SendMessage(message, orgItem);
}
}
}
private static void SendMessage(string message, IdentifiableObject CMSObject)
{
Session session = CMSObject.Session;
JObject details = JObject.FromObject(new
{
creatorId = session.AccessToken.Id.ToString(),
description = message
});
NotificationMessage notificationMessage = new NotificationMessage
{
Action = "tcm:EventSystem",
SubjectIds = new[] { CMSObject.Id.ToString() },
Details = details.ToString()
};
session.NotificationsManager.BroadcastNotification(notificationMessage);
}
I followed the instructions found in the SDL Sites9 documentation and the NotificationHandler.js is as follows:
var notificationHandler = function(event){
alert ("start notificationHandler");
if (Tridion.MessageCenter.getInstance())
{
var title = "Message from me";
var description = "hello world";
Tridion.MessageCenter.registerNotification(title, description, true);
}
};
alert("notificationhandler loaded");
var notificationBroadcaster = Tridion.Web.UI.Core.NotificationBroadcaster.getInstance();
alert("notificationBroadcaster=" + notificationBroadcaster);
notificationBroadcaster.addEventListener("notification", notificationHandler);
alert("eventlistener added");
All alerts are shown (except for the one in the function notificationHandler, so it seems that the event never fires).
Anyone any clues?
this.properties.isEnabled = true;
in the file \Tridion\web\WebUI\Core\Client\NotificationBroadcaster\NotificationBroadcaster.js. btw: this is about SDL Sites9