Notification.cshtml 6.2 KB

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