| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- var abp = abp || {};
- abp.userNotificationHelper = abp.userNotificationHelper || {};
- abp.userNotificationHelper.getUrl = function (userNotification) {
- switch (userNotification.notification.notificationName) {
- case 'KeyPointAlarm':
- case 'KeyPointExpire':
- var contractNo = userNotification.notification.data.contractNo;
- return "/LegalCase/ContractDetail/" + contractNo;
- default:
- return '#';
- }
- //switch (userNotification.notification.notificationName) {
- // case 'App.NewUserRegistered':
- // return '/AppAreaName/users?filterText=' + userNotification.notification.data.properties.emailAddress;
- // case 'App.NewTenantRegistered':
- // return '/AppAreaName/tenants?filterText=' + userNotification.notification.data.properties.tenancyName;
- // case 'App.DownloadInvalidImportUsers':
- // return '/File/DownloadTempFile?fileToken=' + userNotification.notification.data.properties.fileToken +
- // '&fileType=' + userNotification.notification.data.properties.fileType +
- // '&fileName=' + userNotification.notification.data.properties.fileName;
- // //Add your custom notification names to navigate to a URL when user clicks to a notification.
- //}
- };
- abp.userNotificationHelper.getUiIconBySeverity = function (severity) {
- switch (severity) {
- case abp.notifications.severity.SUCCESS:
- return 'fa fa-check bg-success';
- case abp.notifications.severity.WARN:
- return 'fa fa-exclamation bg-warning';
- case abp.notifications.severity.ERROR:
- return 'fa fa-bolt bg-danger';
- case abp.notifications.severity.FATAL:
- return 'fa fa-bomb bg-danger';
- case abp.notifications.severity.INFO:
- default:
- return 'fa fa-info bg-primary';
- }
- };
- abp.userNotificationHelper.format = function (userNotification, truncateText) {
- moment.locale(lang);
- var formatted = {
- userNotificationId: userNotification.id,
- text: abp.notifications.getFormattedMessageFromUserNotification(userNotification),
- time: moment(userNotification.notification.creationTime).format("YYYY-MM-DD HH:mm:ss"),
- icon: abp.userNotificationHelper.getUiIconBySeverity(userNotification.notification.severity),
- state: abp.notifications.getUserNotificationStateAsString(userNotification.state),
- data: userNotification.notification.data,
- url: abp.userNotificationHelper.getUrl(userNotification),
- isUnread: userNotification.state === abp.notifications.userNotificationState.UNREAD,
- timeAgo: moment(userNotification.notification.creationTime).fromNow()
- };
- if (truncateText || truncateText === undefined) {
- formatted.text = abp.utils.truncateStringWithPostfix(formatted.text, 100);
- }
- return formatted;
- };
- abp.userNotificationHelper.show = function (userNotification) {
- //Application notification
- abp.notifications.showUiNotifyForUserNotification(userNotification, {
- 'onclick': function () {
- //Take action when user clicks to live toastr notification
- var url = abp.userNotificationHelper.getUrl(userNotification);
- if (url) {
- location.href = url;
- }
- }
- });
- var text = abp.notifications.getFormattedMessageFromUserNotification(userNotification);
- //Desktop notification
- Push.create("系统通知", {
- body: text,
- icon: abp.appPath + 'Content/Image/logo.png',
- timeout: 6000,
- onClick: function () {
- window.focus();
- this.close();
- }
- });
- };
- abp.userNotificationHelper.setAllAsRead = function (callback) {
- $.iwbAjax4({
- url: abp.appUrl + 'Notification/SetAllNotificationsAsRead',
- success: function () {
- abp.event.trigger('app.notifications.refresh');
- callback && callback();
- }
- });
- };
- abp.userNotificationHelper.setAsRead = function (userNotificationId, callback) {
- $.iwbAjax4({
- url: abp.appUrl + 'Notification/SetNotificationAsRead',
- data: { id: userNotificationId },
- success: function () {
- abp.event.trigger('app.notifications.read', userNotificationId);
- callback && callback(userNotificationId);
- }
- });
- };
- abp.notifications.messageFormatters["ContractService.CommonManager.Notifications.KeyPointNotificationData"] = function (userNotification) {
- var data = userNotification.notification.data;
- return '<strong class="ml-1 mr-1">[{0}]</strong>合同的<strong class="ml-1 mr-1">[{1}]</strong>关键点需要在<strong class="ml-1 mr-1">[{2}]</strong>处理 <span class="ml-2 {3}" data-url="{5}" data-id="{6}" onclick="abp.userNotificationHelper.setAsRead(\'{6}\', function () {document.location.href = \'{5}\';})">立即处理{4}</span>'
- .format(data.contractName,
- data.keyPointName,
- new Date(data.expireDate).format("yyyy-MM-dd"),
- data.isAlarm ? "text-iwb" : "text-danger",
- data.isAlarm ? '' : '<strong class="text-danger">(已过期)</strong>',
- abp.userNotificationHelper.getUrl(userNotification),
- userNotification.id
- );
- }
- $(function () {
- //Notification handler
- function bindNotificationEvents() {
- $('#SetAllNotificationsAsRead').click(function (e) {
- e.preventDefault();
- e.stopPropagation();
- abp.userNotificationHelper.setAllAsRead(function () {
- loadNotifications();
- });
- });
- $('.set-read').click(function (e) {
- e.preventDefault();
- e.stopPropagation();
- var notificationId = $(this).closest('.notification-item').data("notification-id");
- if (notificationId) {
- abp.userNotificationHelper.setAsRead(notificationId, function () {
- loadNotifications();
- });
- }
- });
- $('div.notification-url').click(function () {
- var url = $(this).data('url');
- var notificationId = $(this).closest('.notification-item').data("notification-id");
- if (notificationId) {
- abp.userNotificationHelper.setAsRead(notificationId, function () {
- document.location.href = url;
- });
- }
-
- });
- }
- function loadNotifications() {
- $.iwbAjax4({
- url: abp.appUrl + 'Notification/getUserNotifications',
- data: { maxResultCount: 5 },
- success: function (result) {
- result.notifications = [];
- result.unreadMessageExists = result.unreadCount > 0;
- $.each(result.items, function (index, item) {
- result.notifications.push(abp.userNotificationHelper.format(item,0));
- });
- var $li = $('#header_notification_bar');
- var rendered = NotificationsFormatter(result);
- $li.html(rendered);
- bindNotificationEvents();
- if (result.unreadCount > 0) {
- $.blinkTitle.stop();
- $.blinkTitle.start();
- } else {
- $.blinkTitle.stop();
- }
- }
- });
- }
- function NotificationsFormatter(data) {
- var str = '';
- str += '<a class="nav-link" data-toggle="dropdown" href="#"><i class="fa fa-bell text-warning"></i>{0}</a>'.format(
- data.unreadCount
- ? '<span class="bg-danger navbar-badge" style="top: 0px;border-radius: 50%;width: 15px;height: 15px;line-height: 10px;">{0}</span>'.format(data.unreadCount)
- : '');
- str += '<div class="dropdown-menu notification-menu dropdown-menu-right">';
- str += '<span class="dropdown-header">{0} {1}</span>'.format(
- data.unreadCount,
- abp.localization.iwbZero('NewNotifications'));
- if (data.notifications && data.notifications.length) {
-
- data.notifications.forEach(function(v) {
- str += NotificationFormatter(v);
- });
- str += '<div class="dropdown-divider"></div>';
- str += '<div class="row m-2">';
- if (data.unreadCount) {
- str += '<div class="text-center col-6"><a href = "" id = "SetAllNotificationsAsRead" >{0}</a ></div >'
- .format(
- abp.localization.iwbZero('SetAllAsRead'));
- }
- str += '<div class="text-center col-6"><div class="text-center"><a href="/BaseSystem/Notification">{0}</a ></div></div>'.format(
- abp.localization.iwbZero('SeeAllNotifications'));
- str += '</div>';
- } else {
- str += ' <span class="notification-empty-text p-3">{0}</span >'.format(
- abp.localization.iwbZero('ThereIsNoNotification'));
- }
- str += '</div>';
- return str;
- }
- function NotificationFormatter(data) {
- var str = '<div class="dropdown-divider" ></div>';
- str += '<div class="notification-item {1} {2}" data-url="{0}" data-notification-id="{3}">'.format(data.url,
- data.isUnread ? 'user-notification-item-unread' : 'read',
- data.url ? 'notification-url' : '');
- str += '<div class="item-icon"><i class="{0}" ></i></div><div class="item-text">{1}</div><div class="item-time text-muted ">{2}</div>'
- .format(data.icon, data.text, data.timeAgo);
- str += '</div>';
- return str;
- }
- abp.event.on('abp.notifications.received', function (userNotification) {
- abp.userNotificationHelper.show(userNotification);
- loadNotifications();
- });
- abp.event.on('app.notifications.refresh', function () {
- loadNotifications();
- });
- abp.event.on('app.notifications.read', function () {
- loadNotifications();
- });
- loadNotifications();
- });
|