msg.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. myApp.controller("msg", ["$scope", "$http", "NgTableParams", "$timeout", function ($scope, $http, NgTableParams, $timeout) {
  2. window.hub.stop();
  3. var self = this;
  4. $scope.currentPage = 1;
  5. $scope.paginationConf = {
  6. currentPage: $scope.currentPage ||1,
  7. itemsPerPage: 10,
  8. pagesLength: 25,
  9. perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200],
  10. rememberPerPage: 'perPageItems',
  11. onChange: function () {
  12. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  13. }
  14. };
  15. this.GetPageData = function(page, size) {
  16. $http.post("/msg/GetPendingMsgs", {
  17. page,
  18. size
  19. }).then(function(res) {
  20. $scope.paginationConf.totalItems = res.data.TotalCount;
  21. $("div[ng-table-pagination]").remove();
  22. self.tableParams = new NgTableParams({
  23. count: 50000
  24. }, {
  25. filterDelay: 0,
  26. dataset: res.data.Data
  27. });
  28. });
  29. };
  30. self.del = function(row) {
  31. swal({
  32. title: "确认删除这条留言吗?",
  33. text: row.Title,
  34. showCancelButton: true,
  35. confirmButtonColor: "#DD6B55",
  36. confirmButtonText: "确定",
  37. cancelButtonText: "取消",
  38. showLoaderOnConfirm: true,
  39. animation: true,
  40. allowOutsideClick: false
  41. }).then(function() {
  42. $scope.request("/msg/delete", {
  43. id: row.Id
  44. }, function(data) {
  45. window.notie.alert({
  46. type: 1,
  47. text: data.Message,
  48. time: 4
  49. });
  50. });
  51. _.remove(self.tableParams.settings().dataset, function(item) {
  52. return row === item;
  53. });
  54. self.tableParams.reload().then(function(data) {
  55. if (data.length === 0 && self.tableParams.total() > 0) {
  56. self.tableParams.page(self.tableParams.page() - 1);
  57. self.tableParams.reload();
  58. }
  59. });
  60. }, function() {
  61. }).catch(swal.noop);
  62. }
  63. self.pass = function(row) {
  64. $scope.request("/msg/pass", row, function(data) {
  65. window.notie.alert({
  66. type: 1,
  67. text: data.Message,
  68. time: 4
  69. });
  70. self.stats = [];
  71. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  72. });
  73. }
  74. }]);
  75. myApp.controller("msgs", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  76. window.hub.stop();
  77. var self = this;
  78. $scope.currentPage = 1;
  79. $scope.paginationConf = {
  80. currentPage: $scope.currentPage || 1,
  81. itemsPerPage: 10,
  82. pagesLength: 25,
  83. perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200],
  84. rememberPerPage: 'perPageItems',
  85. onChange: function () {
  86. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  87. }
  88. };
  89. this.GetPageData = function (page, size) {
  90. $http.post("/msg/GetInternalMsgs", {
  91. page,
  92. size
  93. }).then(function (res) {
  94. $scope.paginationConf.totalItems = res.data.TotalCount;
  95. $scope.Messages = res.data.Data;
  96. });
  97. };
  98. $scope.MarkRead= function() {
  99. var id = _.max($scope.Messages, m => m.Id).Id;
  100. $http.post("/msg/MarkRead", {
  101. id
  102. }).then(function(res) {
  103. var data = res.data;
  104. if (data.Success) {
  105. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  106. }
  107. });
  108. }
  109. $scope.toggleRead= function(id,checked) {
  110. if (checked) {
  111. $http.post("/msg/read", {
  112. id
  113. }).then(function(res) {
  114. });
  115. } else {
  116. $http.post("/msg/unread", {
  117. id
  118. }).then(function(res) {
  119. });
  120. }
  121. }
  122. $scope.clearMsgs = function() {
  123. swal({
  124. title: '确定清除已读消息?',
  125. text: "即将彻底清除已读消息,不可恢复!",
  126. type: 'warning',
  127. showCancelButton: true,
  128. confirmButtonColor: '#3085d6',
  129. cancelButtonColor: '#d33',
  130. confirmButtonText: '确定!',
  131. cancelButtonText: '取消',
  132. preConfirm: function() {
  133. return new Promise(function(resolve) {
  134. $http.post("/msg/ClearMsgs").then(function(res) {
  135. var data = res.data;
  136. resolve(data);
  137. });
  138. });
  139. },
  140. allowOutsideClick: false
  141. }).then(function (data) {
  142. if (data.Success) {
  143. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  144. }
  145. }).catch(swal.noop);
  146. }
  147. }]);