6

I am sending the notification messages to the client in component save event through below code.

            var message = new NotificationMessage
            {
                Action = "Save",
                SubjectIds = new[] { component.Id.ToString() },
                Details = string.Format("Component was updated by {0}", session.AccessToken.Title)
            };
            session.NotificationsManager.BroadcastNotification(message);

My question is how I can consume the above notifications using GUI using NotificationBroadCaster.js in below location, But It's not very detailed to understand and to make the changes to work.

If your GUI extension communicates with Content Manager, use the Notification Broadcaster (as found in the file %TRIDION_HOME%\web\WebUI\Core\Client\NotificationBroadcaster\NotificationBroadCaster.js) to catch these notifications

Can you please provide suggestions or solution on this.

2
  • Above question doesn't clarify what are you trying to achieve, there may be other ways to achieve what you need so please explain your use case.
    – Hiren Kaku
    Commented Jan 18, 2017 at 7:01
  • I need to send notifications to author saying that particular component is updated using Notification Broad Caster.
    – Target
    Commented Jan 18, 2017 at 9:35

2 Answers 2

6

How you hook into the push notifications on the client side is briefly outlined on the documentation page entitled "Notification framework".

To summarize, you create an event handler for all incoming push notifications:

var notificationHandler = function(evt) { console.log("Push event received! Details:", evt); }

And then you hook into the "notification" event on the aforementioned NotificationBroadcaster object:

var notificationBroadcaster = Tridion.Web.UI.Core.NotificationBroadcaster.getInstance();
notificationBroadcaster.addEventListener("notification", notificationHandler);

Now, as this will get called on every push event, you'll want to check the "data" properties of the "evt" argument to check that it is an event you want to handle. For example:

switch (evt.data.action)
{
   case "tcm:updated":
      // The default push notification for any save action
      break;
   case "Save":
      // Your new, custom save notification. You might want to prefix this one, by the way :)
      break;
}

As mentioned in the documentation and in my example above, there is already an event for the save of every item (action='tcm:updated'). But it doesn't include the name of the person who did the save, so if that is what you need you will indeed have to introduce your own notification.

3
  • I tried same as you recommended, it`s not working for me. looking for solution in receiving GUI notification. please provide details example for me. Commented Jan 30, 2017 at 22:07
  • This IS a solution, so you're going to have to be a little more specific as to what isn't working for you :) Commented Jan 31, 2017 at 8:46
  • Thanks Peter Kjaer, it`s working fine for me. notification message i want to add anchor link url for save component. please find below my same code and do you have any solution for anchor link url. var samplecomponenthref = "<a href='sf1-test:1001/WebUI/…>"; $messages.registerNotification("Notification", "CMSResponder handleNotification :" + samplecomponenthref, true, false); Commented Feb 2, 2017 at 0:16
1

Final logic Implemented and using below code for GUI Receiving notification.

Tridion.ContentManager.SDLWebResponder = function SDLWebResponder()
{   
    Tridion.OO.enableInterface(this, "Tridion.ContentManager.SDLWebResponder");
    this.addInterface("Tridion.MarshallableObject");
    this.addInterface("Tridion.InitializableObject");

    this.initialize();
};

Tridion.ContentManager.SDLWebResponder.IDENTIFIER = "tcm:SDLWebResponder";

Tridion.ContentManager.SDLWebResponder.prototype._initialize = function SDLWebResponder$_initialize()
{   
    Tridion.Web.UI.Core.NotificationBroadcaster.getInstance().addEventListener("notification", this.getDelegate(this.handleNotification));
};


// This method should include the necessary logic for processing notifications.
// For example, loading an item if it's in an existing list.

Tridion.ContentManager.SDLWebResponder.prototype.handleNotification = function SDLWebResponder$handleNotification(event)
{
    $messages.registerNotification("Notification", "SDLWebResponder handleNotification", true, false);
    var data = event.data;
};

if (!$models.getFromRepository(Tridion.ContentManager.SDLWebResponder.IDENTIFIER))
{
    $models.createInRepository(Tridion.ContentManager.SDLWebResponder.IDENTIFIER, "Tridion.ContentManager.SDLWebResponder");
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.