priorityCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('priorityCtrl', ["$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: 'item',
  33. displayName: '序号',
  34. width: 50,
  35. enableFiltering: false
  36. },
  37. { name: 'name', displayName: '优先级', width: '15%', enableFiltering: false },
  38. { name: 'description', displayName: '优先级描述', width: '55%', enableFiltering: false },
  39. {
  40. name: '编辑',
  41. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  42. '<a ng-click="grid.appScope.saveData(row.entity)" class="bianjifont">编辑</a>' +
  43. '</div></div>',
  44. enableFiltering: false
  45. },
  46. ];
  47. $scope.saveData = function(selectdata) {
  48. var modalInstance = $modal.open({
  49. templateUrl: 'assets/views/system/tpl/systempriority.html',
  50. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  51. $scope.prioritydata = {};
  52. $scope.prioritydata = selectdata;
  53. $scope.cancel = function() {
  54. $modalInstance.dismiss('cancel');
  55. };
  56. $scope.savercode = function(prioritydata) {
  57. if (prioritydata.name && prioritydata.name != "") {
  58. var fildata = { "priority": { "id": prioritydata.id, "level": prioritydata.level, "name": prioritydata.name, "description": prioritydata.description } }
  59. api_bpm_data.updData('priority', fildata).then(function(response) {
  60. if (response) {
  61. if (response.status == 200) {
  62. SweetAlert.swal({
  63. title: "修改成功!",
  64. type: "success"
  65. }, function() {
  66. })
  67. } else {
  68. scope.refreshData('expand-right', defaultFilterData);
  69. SweetAlert.swal({
  70. title: "修改失败!",
  71. type: "error"
  72. })
  73. }
  74. }
  75. })
  76. $modalInstance.close();
  77. } else {
  78. scope.refreshData('expand-right', defaultFilterData);
  79. SweetAlert.swal({
  80. title: "修改失败!",
  81. text: "优先级未填",
  82. type: "error"
  83. })
  84. }
  85. }
  86. },
  87. resolve: {
  88. scope: function() {
  89. return $scope;
  90. }
  91. }
  92. });
  93. }
  94. $scope.addData = function() {
  95. var modalInstance = $modal.open({
  96. templateUrl: 'assets/views/system/tpl/systempriority.html',
  97. controller: function($scope, $modalInstance, api_bpm_data) {
  98. $scope.cancel = function() {
  99. $modalInstance.dismiss('cancel');
  100. };
  101. $scope.savercode = function(prioritydata) {
  102. if (prioritydata.name && prioritydata.name != "") {
  103. $modalInstance.close(prioritydata);
  104. } else {
  105. SweetAlert.swal({
  106. title: "新增失败!",
  107. text: "优先级未填",
  108. type: "error"
  109. })
  110. }
  111. };
  112. }
  113. });
  114. modalInstance.result.then(function(selectedItem) {
  115. // console.log('selectedItem='+JSON.stringify(selectedItem));
  116. if (selectedItem) {
  117. var fildata = { "priority": { "level": selectedItem.level, "name": selectedItem.name, "description": selectedItem.description } }
  118. api_bpm_data.addData('priority', fildata).then(function(response) {
  119. if (response) {
  120. if (response.status == 200) {
  121. SweetAlert.swal({
  122. title: "新增成功!",
  123. type: "success"
  124. }, function() {
  125. $scope.refreshData('expand-right', defaultFilterData);
  126. })
  127. } else {
  128. SweetAlert.swal({
  129. title: "新增失败!",
  130. type: "error"
  131. })
  132. }
  133. }
  134. })
  135. }
  136. });
  137. }
  138. $scope.removeData = function() {
  139. var modalInstance = $modal.open({
  140. templateUrl: 'assets/views/delete.html',
  141. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  142. var rmvList = [scope.selected.items.id]
  143. $scope.title = '优先级删除';
  144. $scope.connect = '确定要删除此优先级?';
  145. $scope.ok = function() {
  146. $modalInstance.close(rmvList);
  147. };
  148. $scope.cancel = function() {
  149. $modalInstance.dismiss('cancel');
  150. };
  151. },
  152. size: 'sm',
  153. resolve: {
  154. scope: function() {
  155. return $scope;
  156. }
  157. }
  158. });
  159. modalInstance.result.then(function(selectedItem) {
  160. if (selectedItem) {
  161. if (selectedItem.length > 0) {
  162. api_bpm_data.rmvData('priority', selectedItem).then(function(response) {
  163. if (response.status == 200) {
  164. SweetAlert.swal({
  165. title: "删除成功!",
  166. type: "success",
  167. confirmButtonColor: "#007AFF"
  168. }, function() {
  169. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  170. $scope.selected = {
  171. items: []
  172. };
  173. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  174. $scope.gridApi.grid.selection.selectedCount = 0;
  175. });
  176. } else {
  177. SweetAlert.swal({
  178. title: "操作异常!",
  179. text: "系统异常,请稍后重试,或者联系管理员!",
  180. type: "error"
  181. });
  182. }
  183. })
  184. }
  185. // }
  186. }
  187. })
  188. }
  189. $scope.selected = {
  190. items: []
  191. }
  192. $scope.editted = {
  193. items: []
  194. }
  195. $scope.gridOptions.onRegisterApi = function(gridApi) {
  196. $scope.gridApi = gridApi;
  197. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  198. // console.log(rowEntity);
  199. // });
  200. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  201. var filtersData = $scope.memoryfilterData;
  202. filtersData.idx = newPage - 1;
  203. filtersData.sum = pageSize;
  204. defaultFilterData = filtersData;
  205. $scope.refreshData('expand-right', filtersData);
  206. });
  207. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  208. scope.grid.appScope.selected.items = scope.entity
  209. });
  210. };
  211. var defaultFilterData = {
  212. "idx": 0,
  213. "sum": 10
  214. };
  215. $scope.memoryfilterData = {
  216. "idx": 0,
  217. "sum": 10
  218. }
  219. $scope.ldloading = {};
  220. $scope.refreshData = function(style, filterData) {
  221. $scope.ldloading[style.replace('-', '_')] = true;
  222. if (angular.isUndefined(filterData)) {
  223. filterData = defaultFilterData;
  224. }
  225. $scope.myData = [];
  226. $scope.selected = { items: [] };
  227. if ($scope.gridApi) {
  228. $scope.gridApi.grid.selection.selectedCount = 0;
  229. }
  230. api_bpm_data.fetchDataList('priority', filterData).then(function(data) {
  231. var myData = Restangular.stripRestangular(data);
  232. $scope.gridOptions.totalItems = myData.totalNum;
  233. $scope.myData = myData.list;
  234. for (var i = 0; i < $scope.myData.length; i++) {
  235. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  236. }
  237. $scope.ldloading[style.replace('-', '_')] = false;
  238. }, function() {
  239. $scope.ldloading[style.replace('-', '_')] = false;
  240. });
  241. };
  242. $scope.refreshData('expand-right', defaultFilterData);
  243. }]);