notificationsBundle.js 17 KB

12345678910
  1. /**
  2. * IBM Confidential OCO Source Materials IBM Business Platform: CA Share
  3. * (C) Copyright IBM Corp. 2017, 2018
  4. *
  5. * The source code for this program is not published or otherwise divested of
  6. * its trade secrets, irrespective of what has been deposited with the U.S.
  7. * Copyright Office
  8. */
  9. define("bi/notifications/app/n10nController",["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(e,t,n,i,s,a,o,r){return{MAX_DISPLAY:20,PREVIEW_PANE_WIDTH:"400px",showNotificationContent:function(a){return a.glassContext.getSvc(".Notification").then(function(d){return d.getSpecificNotification(a.messageId).then(function(l){var c=e.createElement(n.PreviewView,{onHide:a.onHideCallback,data:l,glassContext:a.glassContext,GlassContextHelper:i,ContentStoreObject:s,StringResource:r,messageList:a.messageListView});l.unread&&d.markRead(a.messageId),o(".flyoutPane.pane-right.active.shadow").append('<div class="notificationNewSlideout"></div>'),t.unmountComponentAtNode(document.getElementsByClassName("notificationNewSlideout")[0]),c&&c.type.prototype.setOpen(),t.render(c,document.getElementsByClassName("notificationNewSlideout")[0])})["catch"](function(){})}.bind(this))},deleteNotification:function(e,t){return t.glassContext.getSvc(".Notification").then(function(t){return t.deleteNotification(e)})},getNotificationState:function(e,t){return t.glassContext.getSvc(".Notification").then(function(t){return t.getNotificationState(e)})},updateNotificationState:function(e,t){return t.glassContext.getSvc(".Notification").then(function(t){return t.updateNotificationState(e)})},getObjectProperties:function(e,t){return t.glassContext.getSvc(".Content").then(function(t){var n=t.getBaseObjectsURL()+"/"+e.reportId+"?fields=type,runInAdvancedViewer";return Promise.resolve(t.get(n,{})).then(function(t){if(t.data[0]){var n=t.data[0];return"runInAdvancedViewer"in n&&(e.runInAdvancedViewer=n.runInAdvancedViewer),"type"in n&&(e.type=n.type),e}return Promise.reject()}.bind(this))}.bind(this))}}}),define("bi/notifications/views/n10nBtnView",["bi/glass/app/NavbarButtonSlideoutController","underscore","bi/notifications/app/n10nController","bi/sharecommon/utils/translator"],function(e,t,n,i){"use strict";var s=e.extend({onRender:function(e){e&&(this.glassContext=e.glassContext,e.target.plugin.$el.attr("aria-live","polite")),this.glassContext.getSvc(".Notification").then(function(e){e.on("notifications:newCount",function(e){this.updateButtonText(e)}.bind(this)),e.getNewNotifications()}.bind(this))},updateButtonText:function(e){var t="",s=$(".n10n_badge button");s.length>0&&(e>0?(t=e>n.MAX_DISPLAY?n.MAX_DISPLAY+"+":e,s.attr("data-badge",t),s.attr("aria-label",i.translate("notification_button_accessible_label",{count:t}))):(s.removeAttr("data-badge"),s.removeAttr("aria-label")))}});return s}),define("bi/notifications/views/legacyAppButtonView",["bi/glass/app/plugins/MenuActionInterface","bi/commons/utils/Utils"],function(e,t){"use strict";var n=e.extend({onSelectItem:function(e){var n=e.target.specItemIndex,i=e.target.plugin.itemSpec.items[n];i.tool&&t.legacyLaunch(e.glassContext,i.tool)},isItemVisible:function(e){var t=e.target.itemId,n=t.split("."),i=n[n.length-1];return"legacy_myInbox"===i||"legacy_myWatchItems"===i?this._getIsLaunchable():!1},onRender:function(e){e.glassContext.services.config.getLegacyLaunchable().done(function(e){this._setIsLaunchable(1===e)}.bind(this))},_setIsLaunchable:function(e){this.isLaunchable=e},_getIsLaunchable:function(){return this.isLaunchable}});return n}),define("bi/sharecommon/utils/simpledoT",["doT"],function(e){var t=e;return t.NOT_REPLACED="__NOT_REPLACED__",t.options={verbose:!1},t.simpleTemplate=function(n){var i=n;return t.options.verbose&&(i=n.replace(/\{\{(=[\s\S]+?(\}?)+)\}\}/g,"{{$1 || '"+t.NOT_REPLACED+"($1)'}}")),e.template(i)},t}),define("text!bi/notifications/templates/notification.html",[],function(){return'<!-- Licensed Materials - Property of IBM\n \n IBM Cognos Products: SHARE\n \n (C) Copyright IBM Corp. 2015, 2016\n \n US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\n-->\n<div class="n10n_flyout_pageview n10n_overlay share_message_panel">\n <div id="share_message_list" class="share_message_panel">\n <div class="share_message_panel_header">\n <h2>{{=it.n10n_label}}</h2>\n </div>\n <div class="n10n_message_container"></div>\n </div>\n</div>\n'}),define("text!bi/notifications/templates/emptyMessageList.html",[],function(){return'<!-- Licensed Materials - Property of IBM\n \n IBM Cognos Products: SHARE\n \n (C) Copyright IBM Corp. 2015\n \n US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\n-->\n<div class="emptyTableContent">\n <div class = \'empty_notifications_illustration_128\'></div>\n\n <div class="emptyTableText">{{=it.text}}</div>\n</div>\n'}),define("text!bi/notifications/templates/loadingMessagesPopUp.html",[],function(){return'<!-- Licensed Materials - Property of IBM\n \n IBM Cognos Products: SHARE\n \n (C) Copyright IBM Corp. 2015\n \n US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\n-->\n\n<div class="n10n_loading_messages_popup"></div>'}),define("text!bi/notifications/templates/messagesList.html",[],function(){return'<!-- Licensed Materials - Property of IBM\n \n IBM Cognos Products: SHARE\n \n (C) Copyright IBM Corp. 2015, 2016\n \n US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\n-->\n{{~it.msgs :msg:index}}\n<div class="n10n_message" id="{{=msg.id}}" aria-label="{{=msg.label}}">\n <div class="n10n_message_inner" role="button" tabindex="0">\n <div class="n10n_message_icon">\n <span class="{{=msg.icon}}"> </span>\n </div>\n\n <div class="n10n_message_details">\n <span class="n10n_message_subject {{=msg.read}}">\n {{? msg.read === \'unread\'}}<strong>{{?}}\n {{=msg.subject}}\n {{? msg.read === \'unread\'}}</strong>{{?}}\n </span>\n <div class="n10n_message_sender">\n {{=msg.sender}}\n </div>\n <div class="n10n_message_date">\n {{=msg.date}}\n </div>\n </div>\n </div>\n <button class="btn n10n_delete_icon">\n <span class="btn-hidden-label">{{=msg.deleteLabel}}</span>\n </button>\n</div>\n{{~}}\n'}),define("bi/notifications/views/messageListView",["bi/commons/ui/View","underscore","jquery","q","bi/sharecommon/utils/simpledoT","text!bi/notifications/templates/messagesList.html","bi/sharecommon/utils/translator","bi/commons/utils/Utils","bi/notifications/app/n10nController","bi/commons/utils/ContentFormatter","moment-timezone"],function(e,t,n,i,s,a,o,r,d,l,c){var u=500,h="L",f=e.extend({init:function(e){f.inherited("init",this,arguments),n.extend(this,e),this.timezone=this.glassContext.services.userProfile.preferences.timeZoneID,this.defaultLocale=this.glassContext.services.userProfile.preferences.contentLocale||"en-us",this.KEYS={TAB:9,ENTER:13,SPACE:32,LEFT_ARROW:37,UP_ARROW:38,RIGHT_ARROW:39,DOWN_ARROW:40}},setData:function(e){this.data=e},_setEvents:function(){this.$el.find(".n10n_message").off(".n10n").on("keydown.n10n",this._handleKeyDown.bind(this)),this.$el.find(".n10n_message_inner:not(.clickBound)").addClass("clickBound").on("primaryaction",function(e){var t=e.currentTarget.parentNode.id,n=this.$el.find(e.currentTarget.parentNode);if(!n.hasClass("selected")){var i={messageId:t,messageListView:this,glassContext:this.glassContext,onHideCallback:this.clear.bind(this)};d.showNotificationContent(i,this.slideout),this._displayAsRead(n)}}.bind(this)),this.$el.find(".n10n_delete_icon:not(.clickBound)").addClass("clickBound").on("primaryaction",function(e){var t=e.currentTarget.parentNode.id,i={messageId:t,pending:!0};if(this.glassContext.services.userProfile.preferences.accessibilityFeatures)this.glassContext.appController.showMessage(o.translate("delete_notification_confirm_message"),o.translate("delete_confirm"),"info",["ok","cancel"],void 0,function(e){"ok"===e.btn&&this._completeNotificationDelete(i)}.bind(this));else{var s=n(e.currentTarget.parentNode);s.hide(u),this.glassContext.appController.showToast(o.translate("delete_notification_message"),{type:"info",btnLabel:o.translate("delete_undo"),callback:function(){i.pending=!1,this.$el.find("#"+i.messageId).show(u)}.bind(this),newestOnTop:!0,preventDuplicates:!1,timeOut:6e3,extendedTimeOut:1e3,onHidden:function(){this._completeNotificationDelete(i)}.bind(this)})}}.bind(this))},_handleKeyDown:function(e){var t=e.keyCode||e.charCode||e.which||0;if(t===this.KEYS.UP_ARROW||t===this.KEYS.DOWN_ARROW||t===this.KEYS.LEFT_ARROW||t===this.KEYS.RIGHT_ARROW){var i,s=n(e.currentTarget);switch(t){case this.KEYS.DOWN_ARROW:case this.KEYS.RIGHT_ARROW:i=s.next(),"none"==i.css("display")&&(i=i.next());break;case this.KEYS.UP_ARROW:case this.KEYS.LEFT_ARROW:i=s.prev(),"none"==i.css("display")&&(i=i.prev())}i&&i.length>0&&i.find("div.n10n_message_inner").focus(),e.preventDefault()}n(e.target.parentNode).nextAll().length<=1&&(t===this.KEYS.DOWN_ARROW||t===this.KEYS.RIGHT_ARROW)&&this.loadMessagesCallback&&"function"==typeof this.loadMessagesCallback&&this.loadMessagesCallback(this.$el.parent())},_completeNotificationDelete:function(e){var t=this.$el.find("#"+e.messageId),n={glassContext:this.glassContext};e.pending&&d.deleteNotification(e.messageId,n).done(function(){t.remove()}.bind(this))},clear:function(){this.$el.find(".n10n_message").removeClass("selected")},_displayAsRead:function(e){e.attr("aria-label",o.translate("read_notification")),e.find("strong").contents().unwrap(),e.find(".wft_message_unread_32").addClass("wft_message_read_32").removeClass("wft_message_unread_32")},_formatContent:function(){for(var e=this.$el.find(".n10n_message_subject"),t=this.$el.find(".n10n_message_date"),n=this.$el.find(".n10n_message_sender"),i=0;i<e.length;i++)e[i]&&l.middleShortenString(e[i]),l.middleShortenString(t[i]),l.middleShortenString(n[i])},_setIcon:function(){var e=this.$el.find(".n10n_delete_icon:not(:has(svg))");r.setIcon(e,"common-remove-delete",o.translate("delete_notification"))},render:function(){for(var e=[],n=this.data||[],r=o.translate("unread_notification"),d=o.translate("read_notification"),l=o.translate("delete_message_label"),u=0;u<n.length;u++)e.push({icon:n[u].unread?"wft_message_unread_32":"wft_message_read_32",subject:t.escape(n[u].subject)||"",sender:t.escape(n[u].sender)||"",date:c(n[u].created).locale(this.defaultLocale).tz(this.timezone).format(h),read:n[u].unread?"unread":"read",id:n[u].id||"",label:n[u].unread?r:d,deleteLabel:l});var f={msgs:e},g=s.simpleTemplate(a);return this.$el.append(g(f)),this._formatContent(),this._setEvents(),this._setIcon(),i(this)},appendNewMessages:function(e){for(var n=[],i=e||[],r=o.translate("unread_notification"),d=o.translate("read_notification"),l=o.translate("delete_message_label"),u=0;u<i.length;u++)n.push({icon:i[u].unread?"wft_message_unread_32":"wft_message_read_32",subject:t.escape(i[u].subject)||"",sender:t.escape(i[u].sender)||"",date:c(i[u].created).locale(this.defaultLocale).tz(this.timezone).format(h),read:i[u].unread?"unread":"read",id:i[u].id||"",label:i[u].unread?r:d,deleteLabel:l});var f={msgs:n},g=s.simpleTemplate(a);this.$el.append(g(f)),this._formatContent(),this._setEvents(),this._setIcon()},prependNewMessages:function(e){for(var n=[],i=e||[],r=o.translate("unread_notification"),d=o.translate("read_notification"),l=o.translate("delete_message_label"),u=0;u<i.length;u++)n.push({icon:i[u].unread?"wft_message_unread_32":"wft_message_read_32",subject:t.escape(i[u].subject)||"",sender:t.escape(i[u].sender)||"",date:c(i[u].created).locale(this.defaultLocale).tz(this.timezone).format(h),read:i[u].unread?"unread":"read",id:i[u].id||"",label:i[u].unread?r:d,deleteLabel:l});var f={msgs:n},g=s.simpleTemplate(a);this.$el.prepend(g(f)),this._formatContent(),this._setEvents(),this._setIcon()},focusNextMessage:function(e){var t=this.$el.children().length-1;if(t>0){var n=e.next(".n10n_message");if(1==n.length)n.find(".n10n_message_inner").focus(),e=n;else{var i=e.prev(".n10n_message");1==i.length&&(i.find(".n10n_message_inner").focus(),e=i)}}return e}});return f}),define("bi/notifications/views/notificationView",["underscore","jquery","q","bi/sharecommon/utils/simpledoT","text!bi/notifications/templates/notification.html","text!bi/notifications/templates/emptyMessageList.html","text!bi/notifications/templates/loadingMessagesPopUp.html","bi/sharecommon/utils/translator","bi/glass/app/ContentView","bi/notifications/views/messageListView","bi/commons/utils/Utils","bi/notifications/app/n10nController","../../admin/ba-graphics/dist/illustrations-js/notifications_128"],function(e,t,n,i,s,a,o,r,d,l,c,u,h){var f=!0,g=null,p=d.extend({init:function(e){p.inherited("init",this,arguments),t.extend(this,e),this.offset=0,this.prependLoading=!1,this.currentTopUnreadId="",this.currentTopReadId="",this.isShowingEmptyMessageList=!1,this.loadingAnimation=c.getLoadingAnimation(1),this.$loadingMessagePopUp=t(i.template(o)())},setFocus:function(){this.$el.find(".n10n_message_container .n10n_message:first .n10n_message_inner").focus()},_setEvents:function(){this.offset=0;var e=this.$el.find(".n10n_message_container"),t=0,n=!1;e.on("keypress",function(e){var t=e.keyCode||e.charCode||e.which||0;32==t&&e.preventDefault()}),e.scroll(function(){var i=e.scrollTop();i>t&&!n&&i>=e[0].scrollHeight-e.innerHeight()&&(n=!0,this._checkForMoreMessages(e).then(function(){n=!1})),t=i}.bind(this))},_checkForMoreMessages:function(e){return e.find(".n10n_message:last").after(this.$loadingMessagePopUp.append(this.loadingAnimation)),this.glassContext.getSvc(".Notification").then(function(e){return e.getNotifications(u.MAX_DISPLAY,this.offset)}.bind(this)).then(function(e){return g.appendNewMessages(e),this.$loadingMessagePopUp.remove(),this.offset+=e.length,!0}.bind(this))["catch"](function(){})},_loadNewMessages:function(e){function n(e,i,s){for(var o=0;o<s.length;o++){if(s[o].id===i.currentTopUnreadId){r=o;break}if(s[o].id===i.currentTopReadId){r=o;break}}return h=h.concat(s.slice(0,r)),0===h.length?(i.prependLoading=!1,void t(".n10n_loading_messages_popup:first").remove()):void(h.length<a+u.MAX_DISPLAY?(t(".n10n_loading_messages_popup:first").remove(),i.currentTopUnreadId=h[0].id,i.prependLoading=!1,g.prependNewMessages(h)):(a+=u.MAX_DISPLAY,i.glassContext.getSvc(".Notification").then(function(e){return e.getNotifications(u.MAX_DISPLAY,a)}).then(function(e){n(a,i,e)})))}var s=this.$el.find(".n10n_message_container"),a=0,r=u.MAX_DISPLAY,d=c.getLoadingAnimation(1),l=t(i.template(o)()),h=[];this.prependLoading||(s.scrollTop(0),this.prependLoading=!0,t(".n10n_message:first").before(l.append(d)),n(a,this,e))},render:function(){var e=i.template(s),n={n10n_label:r.translate("n10n_label")};return this.$el.addClass("share_message_panel"),this.$el.html(e(n)),this._setEvents(),this.glassContext.getSvc(".Notification").then(function(e){return e.getNotifications(u.MAX_DISPLAY,this.offset).then(function(n){if(!this.isShowingEmptyMessageList&&0===n.length){var s=i.template(a)({text:r.translate("empty_notification_list")});this.$el.find(".n10n_message_container").append(s),this.isShowingEmptyMessageList=!0;var o=this.$el.find(".empty_notifications_illustration_128");c.setIcon(o,h["default"].id)}return this.isShowingEmptyMessageList&&n.length>0&&(this.$el.find(".emptyTableContent").remove(),this.isShowingEmptyMessageList=!1),this.offset+=n.length,g=new l({$el:this.$el.find(".n10n_message_container"),glassContext:this.glassContext,data:n,slideout:this.slideout,loadMessagesCallback:this._checkForMoreMessages.bind(this)}),g.render(),this._getNewTopMsgIds(),f&&(e.on("notifications:deleted",this._getNewTopMsgIds.bind(this)),e.on("notifications:read",this._getNewTopMsgIds.bind(this)),e.on("notifications:new",function(e){var n=e,i=!this.currentTopUnreadId,s=!i,a=i&&e.length,o=s&&e[0].id!==this.currentTopUnreadId&&e[0].id!==this.currentTopReadId,d=a||o;d&&t("#share_message_list").length&&!this.prependLoading&&this.glassContext.appController.showToast(r.translate("toast_new_notifications"),{type:"info",onclick:function(e){e.preventDefault(),this._loadNewMessages(n)}.bind(this),timeOut:0,extendedTimeOut:0})}.bind(this)),f=!1),this}.bind(this))}.bind(this))},_getNewTopMsgIds:function(e){this.currentTopUnreadId=this.$el.find(".n10n_message:has(.unread)").first().attr("id")||"",this.currentTopReadId=this.$el.find(".n10n_message:has(.read)").first().attr("id")||""},__setNotificationViewFirstRender:function(e){f=e}});return p}),define("js/notifications/notificationsBundle",function(){});