Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / controllers / role-list-controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 app.controller('roleListController', function ($scope,AdminService,modalService){
21         
22         AdminService.getRoles().then(function(data){
23                 
24                 var j = data;
25                 $scope.data = JSON.parse(j.data);
26                 $scope.availableRoles =JSON.parse($scope.data.availableRoles);
27         
28                 //$scope.resetMenu();
29         
30         },function(error){
31                 console.log("failed");
32                 reloadPageOnce();
33         });
34         
35         //console.log($scope.availableRoles);
36                 $scope.toggleRole = function(selected,availableRole) {
37                                 //alert('toggleRole: '+selected);
38                                 var toggleType = null;
39                                 if(selected) {
40                                         toggleType = "activate";
41                                 } else {
42                                         toggleType = "inactivate";
43                                 }
44                                 
45                                 modalService.popupConfirmWinWithCancel("Confirm","You are about to "+toggleType+" the test role "+availableRole.name+". Do you want to continue?",
46                                         function(){
47                                             var uuu = "role_list/toggleRole";
48                                                                 
49                                                                 var postData={role:availableRole};
50                                                                   $.ajax({
51                                                                          type : 'POST',
52                                                                          url : uuu,
53                                                                          dataType: 'json',
54                                                                          contentType: 'application/json',
55                                                                          data: JSON.stringify(postData),
56                                                                          success : function(data){
57                                                                                 console.log(data);
58                                                                                 $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); 
59                                                                                 console.log($scope.availableRoles);
60                                                                          },
61                                                                          error : function(data){
62                                                                                  console.log(data);
63                                                                                  modalService.showFailure("Fail","Error while saving.");
64                                                                          }
65                                                                   });
66                                         
67                         },
68                         function(){
69                                 availableRole.active=!availableRole.active;
70                         })
71                                 
72                                   
73                 };
74
75                 $scope.removeRole = function(role) {
76                         
77                         modalService.popupConfirmWin("Confirm","You are about to delete the role "+role.name+". Do you want to continue?",
78                                 function(){
79                                                         var uuu = "role_list/removeRole";
80                                                           var postData={role:role};
81                                                           $.ajax({
82                                                                  type : 'POST',
83                                                                  url : uuu,
84                                                                  dataType: 'json',
85                                                                  contentType: 'application/json',
86                                                                  data: JSON.stringify(postData),
87                                                                  success : function(data){
88                                                                         $scope.$apply(function(){$scope.availableRoles=data.availableRoles;});  
89                                                                  },
90                                                                  error : function(data){
91                                                                          console.log(data);
92                                                                          modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
93                                                                  }
94                                                           });
95                                 
96                 })
97                 
98                         
99                 };
100                 
101
102 });