changeplan.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('changeplanCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_configure_data", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_configure_data) {
  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. //remote data
  44. $scope.gridOptions.columnDefs = [
  45. { name:'category', displayName:'分类', width:100,enableFiltering:false},
  46. { name:'emergency', displayName:'紧急度', width:100,enableFiltering:false},
  47. { name:'influence', displayName:'影响度', width:140, enableFiltering:false},
  48. { name:'source', displayName:'事件来源', width:100, enableFiltering:false},
  49. { name:'closecode', displayName:'关闭代码', width:100, enableFiltering:false},
  50. // { name:'parent.title', displayName:'服务级别协议', width:100,enableFiltering:false},
  51. // { name:'parent.title', displayName:'业务规则', width:100,enableFiltering:false},
  52. // { name:'role', cellTemplate:'<div class="ui-grid-cell-contents">{{grid.appScope.transferRole(row.entity.role)}}</div>', displayName:'角色', width:140},
  53. { name:'编辑', cellTemplate:'<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  54. '<i class="fa fa-pencil-square-o"/></a>' , width:100,enableFiltering:false}
  55. //'<div class="links cl-effect-1">' +
  56. // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>'+
  57. // '</div>' , width:100, enableFiltering:false}
  58. ];
  59. $scope.saveData = function(data){
  60. var modelData = {
  61. model : {
  62. menu : data
  63. }
  64. };
  65. // console.log("modelData="+JSON.stringify(modelData));
  66. $state.go('app.system.form_editor',{formKey:'system_edit_navmanager', service:'api_configure_data',model : JSON.stringify(modelData)}
  67. );
  68. };
  69. // $scope.addData = function(){
  70. // $state.go('app.system.form',{formKey:'system_edit_navmanager', service:'api_configure_data',}
  71. // );
  72. // }
  73. $scope.removeData = function(){
  74. var rmvList = [];
  75. angular.forEach($scope.selected.items,function(item){
  76. rmvList.push(item.id);
  77. });
  78. if(rmvList.length>0){
  79. api_configure_data.rmvData('menu',rmvList).then(function(response){
  80. if(response.data){
  81. SweetAlert.swal({
  82. title: "删除成功!",
  83. type: "success",
  84. confirmButtonColor: "#007AFF"
  85. },function(){
  86. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  87. $scope.selected = {
  88. items:[]
  89. };
  90. });
  91. }else{
  92. SweetAlert.swal({
  93. title: "操作异常!",
  94. text: "系统异常,请稍后重试,或者联系管理员!",
  95. type: "error"
  96. });
  97. }
  98. })
  99. }
  100. }
  101. $scope.selected = {
  102. items:[]
  103. }
  104. $scope.editted = {
  105. items:[]
  106. }
  107. $scope.gridOptions.onRegisterApi = function(gridApi){
  108. $scope.gridApi = gridApi;
  109. gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  110. console.log(rowEntity);
  111. });
  112. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  113. var filtersData = $scope.memoryfilterData;
  114. filtersData.idx=newPage-1;
  115. filtersData.sum=pageSize;
  116. $scope.refreshData('expand-right',filtersData);
  117. });
  118. gridApi.selection.on.rowSelectionChanged($scope, function(scope){
  119. var j=0;
  120. for(var i=0;i<=scope.grid.appScope.selected.items.length;i++){
  121. if(scope.grid.appScope.selected.items[i]==scope.entity){
  122. j++;
  123. break;
  124. }
  125. }
  126. // console.log("j="+j)
  127. if(j==1){
  128. scope.grid.appScope.selected.items.splice(i,1);
  129. }else{
  130. scope.grid.appScope.selected.items.push(scope.entity)
  131. }
  132. //console.log("scope.grid.appScope.selected.items="+JSON.stringify(scope.grid.appScope.selected.items));
  133. //console.log("scope.entity="+JSON.stringify(scope.entity));
  134. });
  135. gridApi.core.on.filterChanged( $scope, function() {
  136. var grid = this.grid;
  137. var filtersData = {
  138. idx:0,
  139. sum:10
  140. };
  141. angular.forEach(grid.columns,function(item){
  142. if(item.enableFiltering){
  143. if(angular.isDefined(item.filters[0].term)&&item.filters[0].term!=''){
  144. if(angular.isUndefined(filtersData['menu'])){
  145. filtersData['menu']={};
  146. }
  147. filtersData['menu'][item.field]=item.filters[0].term;
  148. }
  149. }
  150. });
  151. // $scope.memoryfilterData = filterData
  152. $scope.refreshData('expand-right', filtersData);
  153. });
  154. };
  155. var defaultFilterData = {
  156. "idx":0,
  157. "sum":10
  158. };
  159. $scope.memoryfilterData = {
  160. "idx":0,
  161. "sum":10
  162. }
  163. $scope.ldloading = {};
  164. $scope.refreshData = function(style,filterData){
  165. $scope.ldloading[style.replace('-', '_')] = true;
  166. if(angular.isUndefined(filterData)){
  167. filterData = defaultFilterData;
  168. }
  169. if(angular.isDefined($scope.searchTypes)){
  170. filterData['searchType'] = $scope.searchTypes;
  171. }
  172. $scope.myData = [];
  173. api_configure_data.fetchDataList('menu',filterData).then(function(data){
  174. var myData = Restangular.stripRestangular(data);
  175. $scope.gridOptions.totalItems = myData.totalNum;
  176. $scope.myData = myData.list;
  177. $scope.ldloading[style.replace('-', '_')] = false;
  178. },function(){
  179. $scope.ldloading[style.replace('-', '_')] = false;
  180. });
  181. };
  182. $scope.refreshData('expand-right', defaultFilterData);
  183. }]);