/* * 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([ 'react', 'react-dom', 'ba-react-admin/ba-react-admin.min', 'bi/content_apps/utils/GlassContextHelper', 'bacontentnav/utils/ContentStoreObject', 'q', 'jquery', 'bi/sharecommon/utils/translator' ], function(React, ReactDOM, AdminReact, GlassContextHelper, ContentStoreObject, Q, $, t) { return { MAX_DISPLAY: 20, // Max number of notifications to fetch / display in the notification badge PREVIEW_PANE_WIDTH: '400px', // Width of the notification message pane /** * @param {Object} messageContext - An object with values to use for loading and displaying a notification * @param {String} messageContext.messageId - The Id of the notification to display * @param {Object} messageContext.messageListView - The current message list view object * @param {Object} messageContext.glassContext - The glassContext object * @param {function} messageContext.onHideCallback - A callback function to call when the slideout.hide function is executed */ showNotificationContent: function(messageContext) { return messageContext.glassContext.getSvc('.Notification').then(function(notificationSvc) { return notificationSvc.getSpecificNotification(messageContext.messageId).then(function(messageDetails) { //render the view after getting the data var newSlideout = React.createElement(AdminReact.PreviewView, { onHide: messageContext.onHideCallback, data: messageDetails, glassContext: messageContext.glassContext, GlassContextHelper: GlassContextHelper, ContentStoreObject: ContentStoreObject, StringResource: t, messageList: messageContext.messageListView }); //check unread -> read status change. If so, call PUT after showing the content if (messageDetails.unread) { notificationSvc.markRead(messageContext.messageId); } $('.flyoutPane.pane-right.active.shadow').append('
'); ReactDOM.unmountComponentAtNode(document.getElementsByClassName('notificationNewSlideout')[0]); newSlideout && newSlideout.type.prototype.setOpen(); ReactDOM.render(newSlideout, document.getElementsByClassName('notificationNewSlideout')[0]); }).catch(function() { // Catch exceptions }); }.bind(this)); }, /** * @param {String} messageId - The notification's Id * @param {Object} context - Context object which contains the glassContext which is needed */ deleteNotification: function(messageId, context) { return context.glassContext.getSvc('.Notification').then(function(notificationSvc) { return notificationSvc.deleteNotification(messageId); }); }, getNotificationState: function(reportId, context) { return context.glassContext.getSvc('.Notification').then(function(notificationSvc) { return notificationSvc.getNotificationState(reportId); }); }, updateNotificationState: function(descriptor, context) { return context.glassContext.getSvc('.Notification').then(function(notificationSvc) { return notificationSvc.updateNotificationState(descriptor); }); }, getObjectProperties: function(properties, context) { return context.glassContext.getSvc('.Content').then(function(contentSvc) { var server_URL = contentSvc.getBaseObjectsURL() + '/' + properties.reportId + '?fields=type,runInAdvancedViewer'; return Promise.resolve(contentSvc.get(server_URL, {})).then(function(data) { if (data.data[0]) { var info = data.data[0]; if ('runInAdvancedViewer' in info) { properties.runInAdvancedViewer = info.runInAdvancedViewer; } if ('type' in info) { properties.type = info.type; } return properties; } else { return Promise.reject(); } }.bind(this)); }.bind(this)); } }; });