/* * Licensed Materials - Property of IBM * * IBM Cognos Products: SHARE * * (C) Copyright IBM Corp. 2015, 2018 * * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define([ 'bi/glass/app/NavbarButtonSlideoutController', 'underscore', 'bi/notifications/app/n10nController', 'bi/sharecommon/utils/translator' ], function(View, _, controller, t) { 'use strict'; var buttonView = View.extend({ onRender: function(context) { if (context) { this.glassContext = context.glassContext; // initially place an aria-live tag on the button. context.target.plugin.$el.attr('aria-live', 'polite'); } /* * Listen for the Notification Service's * 'notification_button:update' event to update the badge text on * this button */ this.glassContext.getSvc('.Notification').then(function(notificationSvc) { notificationSvc.on('notifications:newCount', function(newCount) { this.updateButtonText(newCount); }.bind(this)); notificationSvc.getNewNotifications(); }.bind(this)); }, /** * Function to update the badge number on the Notifications button * * @param newCount number to use to update the badge with */ updateButtonText: function(newCount) { var badgeText = ''; // This grabs all notification buttons in all perspectives. var $button = $('.n10n_badge button'); if ($button.length > 0) { if (newCount > 0) { if (newCount > controller.MAX_DISPLAY) { badgeText = controller.MAX_DISPLAY + '+'; } else { badgeText = newCount; } $button.attr('data-badge', badgeText); $button.attr('aria-label', t.translate('notification_button_accessible_label', {count: badgeText})); } else { $button.removeAttr('data-badge'); $button.removeAttr('aria-label'); } } } }); return buttonView; });