groupCtrl.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('groupListCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data","api_login", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data,api_login) {
  6. $scope.langs=i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser=$rootScope.user;
  10. //$scope.allright=false;
  11. //$scope.allrightnot=true;
  12. $scope.gridOptions = {};
  13. $scope.gridOptions.data = 'myData';
  14. $scope.gridOptions.enableColumnResizing = true;
  15. $scope.gridOptions.enableFiltering = true;
  16. $scope.gridOptions.enableGridMenu = false;
  17. $scope.gridOptions.enableRowSelection = true;
  18. $scope.gridOptions.showGridFooter = true;
  19. $scope.gridOptions.showColumnFooter = false;
  20. $scope.gridOptions.fastWatch = true;
  21. $scope.gridOptions.useExternalFiltering=true;
  22. $scope.gridOptions.useExternalPagination = true;
  23. $scope.gridOptions.paginationPageSizes = [10];
  24. $scope.gridOptions.paginationPageSize = 10;
  25. $scope.gridOptions.multiSelect = true;
  26. //$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>";
  27. $scope.gridOptions.rowIdentity = function(row) {
  28. return row.id;
  29. };
  30. $scope.gridOptions.getRowIdentity = function(row) {
  31. return row.id;
  32. };
  33. $scope.transferRole = function(roles){
  34. var tempValue="";
  35. angular.forEach(roles,function(item){
  36. if(tempValue!=""){
  37. tempValue = tempValue + "/";
  38. }
  39. tempValue = tempValue + item.role;
  40. })
  41. return tempValue;
  42. }
  43. $scope.transferStatus = function(flag){
  44. return (flag==0)?"有效":"无效";
  45. }
  46. //remote data
  47. $scope.gridOptions.columnDefs = [
  48. { name:'area', displayName:'区域', width:100,enableFiltering:false},
  49. { name:'place', displayName:'地点', width:100,enableFiltering:false}, { name:'worktime', displayName:'工作时间', width:140, enableFiltering:false},
  50. { name:'dept.dept', displayName:'部门', width:100, enableFiltering:false},
  51. { name:'group', displayName:'组织信息', width:100, enableFiltering:false},
  52. { name:'parent.title', displayName:'服务级别协议', width:100,enableFiltering:false},
  53. { name:'parent.title', displayName:'业务规则', width:100,enableFiltering:false},
  54. { name:'编辑', cellTemplate:'<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  55. '<i class="fa fa-pencil-square-o"/></a>' , width:100,enableFiltering:false}
  56. ];
  57. $scope.refresh = function(style,filterData){
  58. var filtersData = {
  59. "assignee":$rootScope.user.id,
  60. "candidateGroups":$rootScope.user.group[0].id,
  61. idx:0,
  62. sum:10
  63. };
  64. $scope.gridOptions.refresh();
  65. $scope.refreshData('expand-right',filtersData);
  66. };
  67. $scope.resetpassword = function(id){
  68. var modalInstance = $modal.open({
  69. templateUrl: 'assets/views/system/getright.html',
  70. controller: function($scope, $modalInstance ){
  71. var data
  72. $scope.ok = function() {
  73. $modalInstance.dismiss('cancel');
  74. api_login.resetpwd(id).then(function(response){
  75. var myData = Restangular.stripRestangular(response);
  76. console.log("myData="+JSON.stringify(myData));
  77. if(response.status==200){
  78. SweetAlert.swal({
  79. title: "重置成功!",
  80. type: "success",
  81. confirmButtonColor: "#007AFF"
  82. });
  83. }else{
  84. SweetAlert.swal({
  85. title: "操作异常!",
  86. text: "系统异常,请稍后重试,或者联系管理员!",
  87. type: "error"
  88. });
  89. }
  90. })
  91. };
  92. $scope.cancel = function() {
  93. $modalInstance.dismiss('cancel');
  94. };
  95. }
  96. })
  97. }
  98. $scope.saveData = function(data){
  99. var modelData = {
  100. model : {
  101. user : data
  102. }
  103. };
  104. console.log("modelData="+JSON.stringify(modelData));
  105. $state.go('app.system.form',{formKey:'system_edit', service:'api_user_data',model : JSON.stringify(modelData)}
  106. );
  107. };
  108. $scope.addData = function(){
  109. $state.go('app.system.form',{formKey:'system_groupdesign', service:'api_user_data'}
  110. );
  111. }
  112. $scope.removeData = function(){
  113. var rmvList = [];
  114. angular.forEach($scope.selected.items,function(item){
  115. rmvList.push(item.id);
  116. });
  117. if(rmvList.length>0){
  118. api_user_data.rmvData('user',rmvList).then(function(response){
  119. if(response.data){
  120. SweetAlert.swal({
  121. title: "删除成功!",
  122. type: "success",
  123. confirmButtonColor: "#007AFF"
  124. },function(){
  125. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  126. $scope.selected = {
  127. items:[]
  128. };
  129. });
  130. }else{
  131. SweetAlert.swal({
  132. title: "操作异常!",
  133. text: "系统异常,请稍后重试,或者联系管理员!",
  134. type: "error"
  135. });
  136. }
  137. })
  138. }
  139. }
  140. $scope.selected = {
  141. items:[]
  142. }
  143. $scope.editted = {
  144. items:[]
  145. }
  146. $scope.gridOptions.onRegisterApi = function(gridApi){
  147. $scope.gridApi = gridApi;
  148. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  149. // // console.log(rowEntity);
  150. // });
  151. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  152. var filtersData = $scope.memoryfilterData;
  153. filtersData.idx=newPage-1;
  154. filtersData.sum=pageSize;
  155. $rootScope['idx']=newPage;
  156. $scope.refreshData('expand-right',filtersData);
  157. });
  158. gridApi.selection.on.rowSelectionChanged($scope, function(scope){
  159. var j=0;
  160. for(var i=0;i<=scope.grid.appScope.selected.items.length;i++){
  161. if(scope.grid.appScope.selected.items[i]==scope.entity){
  162. j++;
  163. break;
  164. }
  165. }
  166. // console.log("j="+j)
  167. if(j==1){
  168. scope.grid.appScope.selected.items.splice(i,1);
  169. }else{
  170. scope.grid.appScope.selected.items.push(scope.entity)
  171. }
  172. });
  173. gridApi.core.on.filterChanged( $scope, function() {
  174. var grid = this.grid;
  175. var filtersData = {
  176. idx:0,
  177. sum:10
  178. };
  179. angular.forEach(grid.columns,function(item){
  180. if(item.enableFiltering){
  181. if(angular.isDefined(item.filters[0].term)&&item.filters[0].term!=''){
  182. if(angular.isUndefined(filtersData['user'])){
  183. filtersData['user']={};
  184. }
  185. filtersData['user']['flag']=-1;
  186. filtersData['user'][item.field]=item.filters[0].term;
  187. }
  188. }
  189. });
  190. $scope.memoryfilterData = filtersData;
  191. $scope.refreshData('expand-right', filtersData);
  192. });
  193. };
  194. var defaultFilterData = {
  195. "idx":0,
  196. "sum":10
  197. };
  198. $scope.memoryfilterData = {
  199. "idx":0,
  200. "sum":10
  201. }
  202. if($rootScope['cmdbs']!='user'){$rootScope.idx=1}
  203. if(angular.isDefined($rootScope.idx)&&$rootScope.cmdbs!="false"){
  204. $rootScope.cmdbs='user';
  205. defaultFilterData.idx=$rootScope.idx-1;
  206. }
  207. $scope.ldloading = {};
  208. $scope.refreshData = function(style,filterData){
  209. // $scope.ldloading[style.replace('-', '_')] = true;
  210. // if(angular.isUndefined(filterData)){
  211. // defaultFilterData.idx=$rootScope.idx-1;
  212. // filterData = defaultFilterData;
  213. // }
  214. // if(angular.isDefined($scope.searchTypes)){
  215. // filterData['searchType'] = $scope.searchTypes;
  216. // }
  217. // $scope.myData = [];
  218. // filterData['flag']=-1;
  219. // console.log("filterData="+JSON.stringify(filterData))
  220. // api_user_data.fetchDataList('user',filterData).then(function(data){
  221. // var myData = Restangular.stripRestangular(data);
  222. // $scope.gridOptions.totalItems = myData.totalNum;
  223. // $scope.myData = myData.list;
  224. // $scope.ldloading[style.replace('-', '_')] = false;
  225. // // console.log("$scope.myData="+JSON.stringify($scope.myData))
  226. // },function(){
  227. // $scope.ldloading[style.replace('-', '_')] = false;
  228. // });
  229. };
  230. // $scope.refreshData('expand-right', defaultFilterData);
  231. }]);