Notification.cshtml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. @using Abp.Notifications
  2. @using ContractService.Authorization
  3. @using ContractService.Configuration
  4. @using ContractService.Views.Shared.SearchForm
  5. @using ContractService.Views.Shared.Table
  6. @{
  7. ViewBag.ActiveMenu = PermissionNames.Pages; //The menu item will be active for this page.
  8. ViewBag.Title = L("NotificationTitle");
  9. List<SelectListItem> states = new List<SelectListItem>
  10. {
  11. new SelectListItem() {Text = @"全部通知", Value = ""},
  12. new SelectListItem() {Text = L("NoRead"), Value = ((int)UserNotificationState.Unread)+""},
  13. new SelectListItem() {Text = L("HasRead"), Value = ((int)UserNotificationState.Read)+""}
  14. },
  15. names= IwbNotificationName.GetNameList() ;
  16. var table = new TableViewModel(IwbConsts.ApiAppUrl + "Notification/GetAll", ViewBag.ActiveMenu, new SearchFormViewModel(new List<SearchItem>()
  17. {
  18. new SearchItem("state", L("notificationState"), FieldType.I).SetSelectItem(states),
  19. new SearchItem("date", L("notificationDate"), FieldType.Dn)
  20. })).SetFields(new List<FieldItem>()
  21. {
  22. new FieldItem("name", L("notificationName")),
  23. new FieldItem("text", L("notificationText"), isSort: false),
  24. new FieldItem("time", L("notificationDate")),
  25. new FieldItem("notificationState", L("notificationState"), "StateFormatter", isSort: false),
  26. new FieldItem("", L("Actions"), "ActionFormatter"),
  27. });
  28. }
  29. @Html.Partial("Table/_Table", table)
  30. @section scripts{
  31. <script type="text/javascript">
  32. $(function () {
  33. LoadTable({
  34. table: 'table',
  35. responseHandler: function (res) {
  36. if (res.success) {
  37. if (res.result.items.length > 0) {
  38. var notifications = [];
  39. $.each(res.result.items, function (index, item) {
  40. notifications.push(NotificationFormat(item));
  41. });
  42. var data = JSON.parse('{"total":' + res.result.totalCount + ',"rows":' + JSON.stringify(notifications) + '}');
  43. console.log(data);
  44. return data;
  45. }
  46. } else {
  47. console.log('Table load failed');
  48. if (res.error) {
  49. if (res.error.details) {
  50. return abp.message.error(res.error.details, res.error.message);
  51. } else {
  52. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  53. return abp.message.error(res.error.message).done(function () {
  54. window.top.location.reload();
  55. });
  56. } else {
  57. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  58. }
  59. }
  60. }
  61. }
  62. return JSON.parse('{"total":0,"rows":[]}');
  63. }
  64. });
  65. $('.btn-toolbar .tool-menu').append('<button type="button" class="btn btn-default menu-btn" onclick="ReadAll()"><i class="fas fa-book-reader"></i> 全部设为已读</button><button type="button" class="btn btn-default menu-btn" onclick=" DeleteAll()"><i class="far fa-minus-square"></i> 删除全部已读</button>');
  66. });
  67. function NotificationFormat(userNotification) {
  68. var f = {
  69. id: userNotification.id,
  70. userNotificationId: userNotification.id,
  71. name: abp.localization.iwbZero("Notification_"+userNotification.notification.notificationName),
  72. text: abp.notifications.getFormattedMessageFromUserNotification(userNotification),
  73. time: moment(userNotification.notification.creationTime).format("YYYY-MM-DD HH:mm:ss"),
  74. icon: abp.userNotificationHelper.getUiIconBySeverity(userNotification.notification.severity),
  75. //notificationState: abp.notifications.getUserNotificationStateAsString(userNotification.state),
  76. notificationState: userNotification.state,
  77. data: userNotification.notification.data,
  78. url: abp.userNotificationHelper.getUrl(userNotification),
  79. isUnread: userNotification.state === abp.notifications.userNotificationState.UNREAD,
  80. timeAgo: moment(userNotification.notification.creationTime).fromNow()
  81. };
  82. return f;
  83. }
  84. function SetRead(id) {
  85. $.iwbAjax1({
  86. url:abp.appUrl+ 'Notification/SetNotificationAsRead',
  87. data:{id: id},
  88. success: function() {
  89. abp.event.trigger('app.notifications.refresh', id);
  90. RefreshTable();
  91. }
  92. });
  93. }
  94. function ReadAll() {
  95. MsgConfirm("确认全部通知设为已读吗?",
  96. "全部已读",
  97. function () {
  98. abp.userNotificationHelper.setAllAsRead(RefreshTable);
  99. });
  100. }
  101. function Delete(id) {
  102. $.iwbAjax1({
  103. url: abp.appUrl + 'Notification/DeleteNotification',
  104. data: { id: id },
  105. success: function () {
  106. abp.event.trigger('app.notifications.refresh', id);
  107. RefreshTable();
  108. }
  109. });
  110. }
  111. function DeleteAll() {
  112. MsgConfirm("确认删除全部已读通知?",
  113. "删除全部",
  114. function () {
  115. $.iwbAjax1({
  116. url: abp.appUrl + 'Notification/DeleteAllUserNotifications',
  117. data: { state: @((int)UserNotificationState.Read) },
  118. success: function () {
  119. abp.event.trigger('app.notifications.refresh');
  120. RefreshTable();
  121. }
  122. });
  123. });
  124. }
  125. </script>
  126. <script id="formatter-script">
  127. function ActionFormatter(v,r) {
  128. var icon = '<i class="fa fa-angle-double-right"></i>',
  129. readStr = '<span class="table-action" onclick="SetRead(\''+r.id+'\')">' + icon + '@(L("SetAsRead"))</span>',
  130. deleteStr = '<span class="table-action" onclick="Delete(\''+r.id+'\')">' + icon + '@(L("DeleteNotification"))</span>';
  131. var str = '';
  132. if (r.notificationState === 0) {
  133. str += readStr;
  134. }
  135. str += deleteStr;
  136. return str;
  137. }
  138. function StateFormatter(v) {
  139. var name = $('#hid-state option[value="' + v + '"]').text();
  140. if (v === 1) {
  141. return '<span class="label sm label-success">' + name + '</span>';
  142. } else
  143. return '<span class="label sm label-danger">' + name + '</span>';
  144. }
  145. </script>
  146. }
  147. <section style="display:none">
  148. @Html.DropDownList("hid-state", states)
  149. @Html.DropDownList("hid-name", names)
  150. </section>
  151. @section css{
  152. }