10

I am looking to catch the Event, when notification bar shows a notification message in GUI using Anguilla framework.

Actually at that perticular event, I want to catch the messages of certain type using message.properties.className and prevent it from displaying in notification bar.

Please suggest the possible options.

8

You should be able to add an event listener onto the MessageCenter listening for the "newmessage" event. You'll probably have to filter off of the returned event object's data property. It's a multi step process, as the data object only contains a messageID property. You can use this identifier to retrieve the actual message object, and perform your predicate off of that.

$messages.addEventListener('newmessage', function (event) {
    var messageId = event.data.messageID;
    var message = $messages.getMessageByID(messageId);
    var className = message.getClassName();

    if (className === "goal") {
        // do something with goals... etc...
    }
});

Hope that helps!

Update

If trying to prevent a message of a certain type from displaying completely, I wasn't able to find an out of the box way (at least poking at the 2013 SP1 API, not sure if Web 8 introduced a way). Calling doArchive and dispose from the event handler causes the message to show for a brief moment before fading away.

We can of course do a little monkey patching by keeping a reference of the original MessageCenter's registerMessage method and overriding it to perform our check in there. If its a message we should hide, we can call the doArchive or dispose from there as well as not call the original method. If the message is fine to show, we then pass the message param to our original method. Here's a quick example of doing such a process to not display any goal messages:

var originalRegisterMessage = Tridion.MessageCenter.prototype.registerMessage; // we store the original register message here...

Tridion.MessageCenter.prototype.registerMessage = function (msg) {
    if (msg.getClassName() === 'goal') {
        // don't do anything if its a goal message
        msg.doArchive(); // marks as read, call this if you still want it to display in the Show All area
        msg.dispose(); // or call this so doesn't show up in notification center at all
        return;
    }
    originalRegisterMessage.call(this, msg); // call the original function if the notification should show
};
  • 1
    SDL Web Cloud added a notification framework/API earlier in 2016, which will also be available in the next on-premise release for SDL Web, planned for Q4 2016. See SDL Docs for details. – Alvin Reyes Sep 1 '16 at 14:46
  • 1
    It works like a charm Alex, Thanks. One point to mention, the lines in code msg.doArchive(); msg.dispose(); could be removed because these adds no value, if someone just want to hide the notification of certain type, Also I noticed for 'workflownotification' these lines cause a issue because that message(we dispode) is needed in further processing and JS doesn't find it and throws an error. – Saurabh Gangwar Sep 1 '16 at 16:35
  • @Alex: Overriding registerMessage method dosn't work on workflow activities page (which is a "feature Page" view). Though it works as expected on "Dashboard" view. – Saurabh Gangwar Nov 15 '16 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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