incidentsourceCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('incidentsourceCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_data) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. $scope.gridOptions = {};
  11. $scope.gridOptions.data = 'myData';
  12. $scope.gridOptions.enableColumnResizing = true;
  13. $scope.gridOptions.enableFiltering = true;
  14. $scope.gridOptions.enableGridMenu = false;
  15. $scope.gridOptions.enableRowSelection = true;
  16. $scope.gridOptions.showGridFooter = true;
  17. $scope.gridOptions.showColumnFooter = false;
  18. $scope.gridOptions.fastWatch = true;
  19. $scope.gridOptions.useExternalFiltering = true;
  20. $scope.gridOptions.useExternalPagination = true;
  21. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  22. $scope.gridOptions.paginationPageSize = 10;
  23. $scope.gridOptions.multiSelect = false;
  24. //$scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  25. $scope.gridOptions.rowIdentity = function(row) {
  26. return row.id;
  27. };
  28. $scope.gridOptions.getRowIdentity = function(row) {
  29. return row.id;
  30. };
  31. $scope.gridOptions.columnDefs = [{
  32. name: '编辑',
  33. cellTemplate: '<div><div class="links cl-effect-1 ui-grid-cell-contents" ><a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  34. '<i class="fa fa-pencil-square-o"></i></a></div></div>',
  35. width: 60,
  36. enableFiltering: false
  37. },
  38. { name: 'source', displayName: '事件来源', width: 100, enableFiltering: false },
  39. { name: 'code', displayName: '来源关联', width: 300, enableFiltering: false }
  40. // {
  41. // name: '修改',
  42. // cellTemplate: '<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  43. // '<i class="fa fa-pencil-square-o"/></a>',
  44. // width: 100,
  45. // enableFiltering: false
  46. // }
  47. ];
  48. $scope.saveData = function(selectdata) {
  49. var modalInstance = $modal.open({
  50. templateUrl: 'assets/views/system/tpl/systemsource.html',
  51. controller: function($scope, $modalInstance, api_bpm_data) {
  52. $scope.sourcedata = {};
  53. $scope.sourcedata = selectdata;
  54. $scope.options = {
  55. language: 'zh-cn',
  56. allowedContent: true,
  57. entities: false
  58. };
  59. $scope.cancel = function() {
  60. $modalInstance.dismiss('cancel');
  61. };
  62. $scope.savercode = function(sourcedata) {
  63. var fildata = { "incidentsource": { "id": sourcedata.id, "source": sourcedata.source, "code": sourcedata.code } }
  64. api_bpm_data.updData('incidentsource', fildata).then(function(response) {
  65. if (response) {
  66. if (response.status == 200) {
  67. SweetAlert.swal({
  68. title: "修改成功!",
  69. type: "success"
  70. }, function() {
  71. // $scope.refreshData('expand-right', defaultFilterData);
  72. })
  73. } else {
  74. SweetAlert.swal({
  75. title: "修改失败!",
  76. type: "error"
  77. })
  78. }
  79. }
  80. })
  81. $modalInstance.close();
  82. }
  83. }
  84. });
  85. }
  86. $scope.addData = function() {
  87. console.log($scope.selected)
  88. var modalInstance = $modal.open({
  89. templateUrl: 'assets/views/system/tpl/systemsource.html',
  90. controller: function($scope, $modalInstance, api_bpm_data) {
  91. $scope.options = {
  92. language: 'zh-cn',
  93. allowedContent: true,
  94. entities: false
  95. };
  96. $scope.cancel = function() {
  97. $modalInstance.dismiss('cancel');
  98. };
  99. $scope.savercode = function(sourcedata) {
  100. $modalInstance.close(sourcedata);
  101. };
  102. }
  103. });
  104. modalInstance.result.then(function(selectedItem) {
  105. console.log('selectedItem=' + JSON.stringify(selectedItem));
  106. if (selectedItem) {
  107. var fildata = { "incidentsource": { "source": selectedItem.source, "code": selectedItem.code } }
  108. api_bpm_data.addData('incidentsource', fildata).then(function(response) {
  109. if (response) {
  110. if (response.status == 200) {
  111. SweetAlert.swal({
  112. title: "新增成功!",
  113. type: "success"
  114. }, function() {
  115. $scope.refreshData('expand-right', defaultFilterData);
  116. })
  117. } else {
  118. SweetAlert.swal({
  119. title: "新增失败!",
  120. type: "error"
  121. })
  122. }
  123. }
  124. })
  125. }
  126. });
  127. }
  128. $scope.removeData = function() {
  129. var modalInstance = $modal.open({
  130. templateUrl: 'assets/views/delete.html',
  131. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  132. var rmvList = [scope.selected.items.id]
  133. $scope.ok = function() {
  134. $modalInstance.close(rmvList);
  135. // }
  136. };
  137. $scope.cancel = function() {
  138. $modalInstance.dismiss('cancel');
  139. };
  140. },
  141. size: 'sm',
  142. resolve: {
  143. scope: function() {
  144. return $scope;
  145. }
  146. }
  147. });
  148. modalInstance.result.then(function(selectedItem) {
  149. if (selectedItem) {
  150. if (selectedItem.length > 0) {
  151. api_bpm_data.rmvData('incidentsource', selectedItem).then(function(response) {
  152. if (response.status == 200) {
  153. SweetAlert.swal({
  154. title: "删除成功!",
  155. type: "success",
  156. confirmButtonColor: "#007AFF"
  157. }, function() {
  158. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  159. $scope.selected = {
  160. items: []
  161. };
  162. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  163. $scope.gridApi.grid.selection.selectedCount = 0;
  164. });
  165. } else {
  166. SweetAlert.swal({
  167. title: "操作异常!",
  168. text: "系统异常,请稍后重试,或者联系管理员!",
  169. type: "error"
  170. });
  171. }
  172. })
  173. }
  174. }
  175. })
  176. }
  177. // $scope.removeData = function(){
  178. // var rmvList = [$scope.selected.items.id]
  179. // if(rmvList.length>0){
  180. // api_bpm_data.rmvData('incidentsource',rmvList).then(function(response){
  181. // if(response.status==200){
  182. // SweetAlert.swal({
  183. // title: "删除成功!",
  184. // type: "success",
  185. // confirmButtonColor: "#007AFF"
  186. // },function(){
  187. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  188. // $scope.selected = {
  189. // items:[]
  190. // };
  191. // });
  192. // }else{
  193. // SweetAlert.swal({
  194. // title: "操作异常!",
  195. // text: "系统异常,请稍后重试,或者联系管理员!",
  196. // type: "error"
  197. // });
  198. // }
  199. // })
  200. // }
  201. // }
  202. $scope.selected = {
  203. items: []
  204. }
  205. $scope.editted = {
  206. items: []
  207. }
  208. $scope.gridOptions.onRegisterApi = function(gridApi) {
  209. $scope.gridApi = gridApi;
  210. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  211. // console.log(rowEntity);
  212. // });
  213. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  214. var filtersData = $scope.memoryfilterData;
  215. filtersData.idx = newPage - 1;
  216. filtersData.sum = pageSize;
  217. $scope.refreshData('expand-right', filtersData);
  218. });
  219. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  220. scope.grid.appScope.selected.items = scope.entity
  221. });
  222. };
  223. var defaultFilterData = {
  224. "idx": 0,
  225. "sum": 10
  226. };
  227. $scope.memoryfilterData = {
  228. "idx": 0,
  229. "sum": 1000
  230. }
  231. $scope.ldloading = {};
  232. $scope.refreshData = function(style, filterData) {
  233. $scope.ldloading[style.replace('-', '_')] = true;
  234. if (angular.isUndefined(filterData)) {
  235. filterData = defaultFilterData;
  236. }
  237. $scope.myData = [];
  238. $scope.selected = { items: [] };
  239. if ($scope.gridApi) {
  240. $scope.gridApi.grid.selection.selectedCount = 0;
  241. }
  242. api_bpm_data.fetchDataList('incidentsource', filterData).then(function(data) {
  243. var myData = Restangular.stripRestangular(data);
  244. $scope.gridOptions.totalItems = myData.totalNum;
  245. $scope.myData = myData.list;
  246. $scope.ldloading[style.replace('-', '_')] = false;
  247. }, function() {
  248. $scope.ldloading[style.replace('-', '_')] = false;
  249. });
  250. };
  251. $scope.refreshData('expand-right', defaultFilterData);
  252. }]);