adminRoleCtrl.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('adminRoleListCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "$modal", "$window", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data","api_solution", function ($rootScope, $scope, $state, $timeout, $interval, $modal, $window, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data,api_solution) {
  6. $scope.langs=i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser=$rootScope.user;
  10. var _ = $window._;
  11. //$scope.allright=false;
  12. //$scope.allrightnot=true;
  13. $scope.gridOptions = {};
  14. $scope.gridOptions.data = 'myData';
  15. $scope.gridOptions.enableColumnResizing = true;
  16. $scope.gridOptions.enableFiltering = false;
  17. $scope.gridOptions.enableGridMenu = false;
  18. $scope.gridOptions.enableRowSelection = true;
  19. $scope.gridOptions.showGridFooter = true;
  20. $scope.gridOptions.showColumnFooter = false;
  21. $scope.gridOptions.fastWatch = 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.transfertype = function(roletype){
  44. return (roletype==0)?"登录角色":"流程角色";
  45. }
  46. //remote data
  47. $scope.gridOptions.columnDefs = [
  48. { name:'role', displayName:'角色名', width:150},
  49. { name:'rolecode', displayName:'角色代码', width:150},
  50. { name:'roletype', displayName:'角色类型', cellTemplate:'<div class="ui-grid-cell-contents">{{grid.appScope.transfertype(row.entity.roletype)}}</div>', width:150,enableFiltering:false},
  51. { name:'操作', cellTemplate:'<a class="btn btn-sm btn-info" ng-hide="row.entity.roletype" ' +
  52. 'ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  53. '<i class="fa fa-pencil-square-o"/></a> '
  54. // '<a class="btn btn-sm btn-info" ' +
  55. // 'ng-click="grid.appScope.resetrole(row.entity.id)" tooltip="角色权限">' +
  56. // '<i class="ti-hummer"/></a>'
  57. , width:100,enableFiltering:false}
  58. //'<div class="links cl-effect-1">' +
  59. // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>'+
  60. // '</div>' , width:100, enableFiltering:false}
  61. ];
  62. $scope.resetrole = function(id){
  63. var modalInstance = $modal.open({
  64. templateUrl: 'assets/views/system/user/resetrole.html',
  65. // controller: function($scope, $modalInstance, isCreate, Alert){
  66. // var apple_selected, tree, treedata_avm, treedata_geography;
  67. // $scope.my_tree_handler = function (branch) {
  68. // var _ref;
  69. // $scope.output = branch.label;
  70. // if ((_ref = branch.data) != null ? _ref.description :void 0) {
  71. // return $scope.output += '(' + branch.data.description + ')';
  72. // }
  73. // };
  74. // apple_selected = function (branch) {
  75. // return $scope.output = branch.label;
  76. // console.log("branch.label="+branch.label)
  77. // };
  78. // treedata_avm = [{
  79. // label: 'Animal',
  80. // children: [{
  81. // label: 'Dog',
  82. // data: {
  83. // description: "man's best friend"
  84. // }
  85. // }, {
  86. // label: 'Cat',
  87. // data: {
  88. // description: "Felis catus"
  89. // }
  90. // }, {
  91. // label: 'Hippopotamus',
  92. // data: {
  93. // description: "hungry, hungry"
  94. // }
  95. // }, {
  96. // label: 'Chicken',
  97. // children: ['White Leghorn', 'Rhode Island Red', 'Jersey Giant']
  98. // }]
  99. // }, {
  100. // label: 'Vegetable',
  101. // data: {
  102. // definition: "A plant or part of a plant used as food, typically as accompaniment to meat or fish, such as a cabbage, potato, carrot, or bean.",
  103. // data_can_contain_anything: true
  104. // },
  105. // onSelect: function (branch) {
  106. // return $scope.output = "Vegetable: " + branch.data.definition;
  107. // },
  108. // children: [{
  109. // label: 'Oranges'
  110. // }, {
  111. // label: 'Apples',
  112. // children: [{
  113. // label: 'Granny Smith',
  114. // onSelect: apple_selected
  115. // }, {
  116. // label: 'Red Delicous',
  117. // onSelect: apple_selected
  118. // }, {
  119. // label: 'Fuji',
  120. // onSelect: apple_selected
  121. // }]
  122. // }]
  123. // }, {
  124. // label: 'Mineral',
  125. // children: [{
  126. // label: 'Rock',
  127. // children: ['Igneous', 'Sedimentary', 'Metamorphic']
  128. // }, {
  129. // label: 'Metal',
  130. // children: ['Aluminum', 'Steel', 'Copper']
  131. // }, {
  132. // label: 'Plastic',
  133. // children: [{
  134. // label: 'Thermoplastic',
  135. // children: ['polyethylene', 'polypropylene', 'polystyrene', ' polyvinyl chloride']
  136. // }, {
  137. // label: 'Thermosetting Polymer',
  138. // children: ['polyester', 'polyurethane', 'vulcanized rubber', 'bakelite', 'urea-formaldehyde']
  139. // }]
  140. // }]
  141. // }];
  142. // treedata_geography = [{
  143. // label: 'North America',
  144. // children: [{
  145. // label: 'Canada',
  146. // children: ['Toronto', 'Vancouver']
  147. // }, {
  148. // label: 'USA',
  149. // children: ['New York', 'Los Angeles']
  150. // }, {
  151. // label: 'Mexico',
  152. // children: ['Mexico City', 'Guadalajara']
  153. // }]
  154. // }, {
  155. // label: 'South America',
  156. // children: [{
  157. // label: 'Venezuela',
  158. // children: ['Caracas', 'Maracaibo']
  159. // }, {
  160. // label: 'Brazil',
  161. // children: ['Sao Paulo', 'Rio de Janeiro']
  162. // }, {
  163. // label: 'Argentina',
  164. // children: ['Buenos Aires', 'Cordoba']
  165. // }]
  166. // }];
  167. // $scope.my_data = treedata_avm;
  168. // $scope.try_changing_the_tree_data = function () {
  169. // if ($scope.my_data === treedata_avm) {
  170. // return $scope.my_data = treedata_geography;
  171. // } else {
  172. // return $scope.my_data = treedata_avm;
  173. // }
  174. // };
  175. // $scope.my_tree = tree = {};
  176. // $scope.try_async_load = function () {
  177. // $scope.my_data = [];
  178. // $scope.doing_async = true;
  179. // return $timeout(function () {
  180. // if (Math.random() < 0.5) {
  181. // $scope.my_data = treedata_avm;
  182. // } else {
  183. // $scope.my_data = treedata_geography;
  184. // }
  185. // $scope.doing_async = false;
  186. // return tree.expand_all();
  187. // }, 1000);
  188. // };
  189. // $scope.ok = function() {
  190. // $modalInstance.close($scope.entity);
  191. // };
  192. // $scope.cancel = function() {
  193. // $modalInstance.dismiss('cancel');
  194. // };
  195. // },
  196. // size:'lg',
  197. // resolve: {
  198. // isCreate: function(){
  199. // return flag;
  200. // },
  201. // Alert: function(){
  202. // return SweetAlert;
  203. // }
  204. // }
  205. // });
  206. // modalInstance.result.then(function(selectedItem) {
  207. // if(selectedItem){
  208. // // console.log("selectedItem=")
  209. // }
  210. // });
  211. // }
  212. controller: function($scope, $modalInstance, APIService, uploader,tree_data, currentUser){
  213. var typeName;
  214. $scope.tree_handler = function (branch) {
  215. $scope.showknowledgeType = true;
  216. $scope.entity.typeName = branch.label;
  217. $scope.entity.typeId = branch.id;
  218. console.log(branch);
  219. };
  220. $scope.uploader = uploader;
  221. var loadData = function(){
  222. $scope.visions=[];
  223. $scope.solutionDowpath = APIService.getSolutionDowpath().getRequestedUrl();
  224. APIService.findSolutionById(id).then(function(response){
  225. var datas=response.data;
  226. $scope.visions=datas;
  227. console.log(' datas='+JSON.stringify( datas));
  228. var data={};
  229. for(var i=0;i<datas.length-1;i++){
  230. if(id==datas[i].id){
  231. data=datas[i];
  232. }
  233. }
  234. });
  235. }
  236. loadData();
  237. $scope.options = {
  238. language: 'zh-cn',
  239. allowedContent: true,
  240. entities: false
  241. };
  242. $scope.uploader = uploader;
  243. $scope.onReady = function () {
  244. // ...
  245. };
  246. $scope.ok = function() {
  247. $modalInstance.close($scope.entity);
  248. };
  249. $scope.cancel = function() {
  250. $modalInstance.dismiss('cancel');
  251. };
  252. },
  253. size:'lg',
  254. resolve: {
  255. APIService: function(){
  256. return api_solution;
  257. },
  258. uploader: function(){
  259. return $scope.uploader;
  260. },
  261. tree_data: function(){
  262. return angular.copy($scope.tree_data);
  263. },
  264. currentUser: function(){
  265. return loginUser.id;
  266. }
  267. }
  268. });
  269. modalInstance.result.then(function(selectedItem) {
  270. if(selectedItem){
  271. }
  272. });
  273. }
  274. $scope.addData = function(){
  275. $state.go('app.system.form_role',{formKey:'system_edit_role', service:'api_user_data'}
  276. );
  277. }
  278. $scope.saveData = function(entity){
  279. var modelData = {
  280. model : {
  281. role : entity
  282. }
  283. };
  284. console.log("modelData="+JSON.stringify(modelData));
  285. $state.go('app.system.form_role',{formKey:'system_edit_role', service:'api_user_data', model : JSON.stringify(modelData)}
  286. );
  287. };
  288. $scope.addDataExtra = function(){
  289. var addIndex = -1;
  290. angular.forEach($scope.myData,function(item,index){
  291. if(angular.isUndefined(item.id)){
  292. addIndex = index;
  293. }
  294. });
  295. if(addIndex!=-1){
  296. SweetAlert.swal({
  297. title: "警告!",
  298. text: "新增操作会丢失未提交的新增数据,请先进行保存操作!",
  299. type: "warning",
  300. cancelButtonText: "取消",
  301. showCancelButton: true,
  302. confirmButtonColor: "#DD6B55",
  303. confirmButtonText: "继续"
  304. },function (isConfirm) {
  305. if (isConfirm) {
  306. $scope.myData.splice(addIndex,1);
  307. //$scope.myData.push({'role':'新角色','rolecode':'new rolecode'});
  308. }
  309. });
  310. }else{
  311. $scope.myData.push({'role':"新角色",'rolecode':"rolecode"});
  312. }
  313. }
  314. $scope.afterAddData = function(data){
  315. api_user_data.addData('role',data).then(function(response){
  316. if(response.data){
  317. SweetAlert.swal({
  318. title: "增加成功!",
  319. type: "success",
  320. confirmButtonColor: "#007AFF"
  321. },function(){
  322. $scope.refreshData('expand-right', defaultFilterData);
  323. });
  324. }else{
  325. SweetAlert.swal({
  326. title: "操作异常!",
  327. text: "系统异常,请稍后重试,或者联系管理员!",
  328. type: "error"
  329. });
  330. }
  331. })
  332. }
  333. $scope.removeData = function(){
  334. var rmvList = [];
  335. angular.forEach($scope.selected.items,function(item){
  336. rmvList.push(item.id);
  337. });
  338. if(rmvList.length>0){
  339. api_user_data.rmvData('role',rmvList).then(function(response){
  340. if(response.data){
  341. SweetAlert.swal({
  342. title: "删除成功!",
  343. type: "success",
  344. confirmButtonColor: "#007AFF"
  345. },function(){
  346. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  347. $scope.selected = {
  348. items:[]
  349. };
  350. });
  351. }else{
  352. SweetAlert.swal({
  353. title: "操作异常!",
  354. text: "系统异常,请稍后重试,或者联系管理员!",
  355. type: "error"
  356. });
  357. }
  358. })
  359. }
  360. }
  361. $scope.saveDataExtra = function(data){
  362. var postData = {
  363. 'role':data
  364. }
  365. api_user_data.addData('role',postData).then(function(response){
  366. if(response.data){
  367. SweetAlert.swal({
  368. title: "操作成功!",
  369. type: "success",
  370. confirmButtonColor: "#007AFF"
  371. },function(){
  372. var flag = angular.isDefined(data.id);
  373. var saveIndex = -1;
  374. angular.forEach($scope.myData,function(item,index){
  375. if(item.id==data.id){
  376. saveIndex = index;
  377. }
  378. if(flag&&item.id==data.id){
  379. saveIndex = index;
  380. }else if(angular.isUndefined(item.id)){
  381. saveIndex = index;
  382. }
  383. });
  384. if(saveIndex!=-1){
  385. $scope.myData[saveIndex]=response.data;
  386. //if(flag){
  387. $scope.modified.items = []; //_.reject($scope.modified.items, function(o){ return o.id==data.id;})
  388. //$scope.modified.items.splice(data,1)
  389. //}
  390. }
  391. });
  392. }else{
  393. SweetAlert.swal({
  394. title: "操作异常!",
  395. text: "系统异常,请稍后重试,或者联系管理员!",
  396. type: "error"
  397. });
  398. }
  399. })
  400. }
  401. $scope.isModify = function(entity){
  402. var ret = false;
  403. if(angular.isUndefined(entity.id)){
  404. ret = true;
  405. }else{
  406. angular.forEach($scope.modified.items,function(item){
  407. if(item.id==entity.id){
  408. ret = true;
  409. }
  410. });
  411. }
  412. return ret;
  413. }
  414. $scope.selected = {
  415. items:[]
  416. }
  417. $scope.modified = {
  418. items:[]
  419. }
  420. $scope.gridOptions.onRegisterApi = function(gridApi){
  421. $scope.gridApi = gridApi;
  422. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  423. // if(newValue == oldValue) return;
  424. // $scope.modified.items.push(rowEntity);
  425. // });
  426. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  427. var filtersData = $scope.memoryfilterData;
  428. filtersData.idx=newPage-1;
  429. filtersData.sum=pageSize;
  430. $scope.refreshData('expand-right',filtersData);
  431. });
  432. gridApi.selection.on.rowSelectionChanged($scope, function(scope){
  433. var j=0;
  434. for(var i=0;i<=scope.grid.appScope.selected.items.length;i++){
  435. if(scope.grid.appScope.selected.items[i]==scope.entity){
  436. j++;
  437. break;
  438. }
  439. }
  440. // console.log("j="+j)
  441. if(j==1){
  442. scope.grid.appScope.selected.items.splice(i,1);
  443. }else{
  444. scope.grid.appScope.selected.items.push(scope.entity)
  445. }
  446. });
  447. gridApi.core.on.filterChanged( $scope, function() {
  448. var grid = this.grid;
  449. var filtersData = {
  450. idx:0,
  451. sum:10
  452. };
  453. angular.forEach(grid.columns,function(item){
  454. if(item.enableFiltering){
  455. if(angular.isDefined(item.filters[0].term)&&item.filters[0].term!=''){
  456. if(angular.isUndefined(filtersData['role'])){
  457. filtersData['role']={};
  458. }
  459. filtersData['role'][item.field]=item.filters[0].term;
  460. }
  461. }
  462. });
  463. $scope.memoryfilterData = filterData
  464. $scope.refreshData('expand-right', filtersData);
  465. });
  466. };
  467. var defaultFilterData = {
  468. "idx":0,
  469. "sum":10
  470. };
  471. $scope.memoryfilterData = {
  472. "idx":0,
  473. "sum":10
  474. }
  475. $scope.ldloading = {};
  476. $scope.roleright="";
  477. $scope.refreshData = function(style,filterData){
  478. $scope.ldloading[style.replace('-', '_')] = true;
  479. if(angular.isUndefined(filterData)){
  480. filterData = defaultFilterData;
  481. }
  482. $scope.myData = [];
  483. api_user_data.fetchDataList('role',filterData).then(function(data){
  484. var myData = Restangular.stripRestangular(data);
  485. // console.log("myData="+JSON.stringify(myData.list))
  486. // if($scope.myData.list.)
  487. $scope.gridOptions.totalItems = myData.totalNum;
  488. $scope.myData = myData.list;
  489. $scope.ldloading[style.replace('-', '_')] = false;
  490. },function(){
  491. $scope.ldloading[style.replace('-', '_')] = false;
  492. });
  493. };
  494. $scope.refreshData('expand-right', defaultFilterData);
  495. }]);