[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / role / role-list-controller.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 app.controller('roleListController', function ($scope,RoleService,confirmBoxService,conf,$state,$http){\r
21         $scope.showSpinner = true;\r
22         \r
23         RoleService.getRoles().then(function(data){\r
24                 $scope.showSpinner = true;\r
25                 var j = data;\r
26                 $scope.data = JSON.parse(j.data);\r
27                 $scope.availableRoles =JSON.parse($scope.data.availableRoles);\r
28                 $scope.showSpinner = false;\r
29                 //$scope.resetMenu();\r
30         \r
31         },function(error){\r
32                 console.log("failed");\r
33                 //reloadPageOnce();\r
34         });\r
35         \r
36         \r
37                 $scope.goToUrl = function(roleIdVal) {\r
38                         $state.go("root.role", {"roleId":roleIdVal});\r
39                 }       \r
40         //console.log($scope.availableRoles);\r
41                 $scope.toggleRole = function(selected,availableRole) {\r
42                                 //alert('toggleRole: '+selected);\r
43                                 var toggleType = null;\r
44                                 if(selected) {\r
45                                         toggleType = "activate";\r
46                                 } else {\r
47                                         toggleType = "inactivate";\r
48                                 }\r
49                                 \r
50                                 confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then(\r
51                                         function(confirmed){\r
52                                                 \r
53                                                  if(confirmed) {\r
54                                             var uuu = conf.api.toggleRole;\r
55                                                                 \r
56                                                                 var postData={role:availableRole};\r
57                                                                 $http.post(uuu, postData).then(function(response) {\r
58                                                                         var data = response.data;\r
59                                                                         if (typeof data === 'object') {\r
60                                                                                 console.log(data);\r
61                                                                                 $scope.availableRoles=data.availableRoles; \r
62                                                                                 console.log($scope.availableRoles);\r
63                                                                         } else {\r
64                                                                                 //\r
65                                                                         }\r
66 \r
67                                                                 }, function(response) {\r
68                                                                         console.log(response.data);\r
69                                                                         availableRole.active=!availableRole.active;\r
70                                                                         confirmBoxService.showInformation("Error while saving.");\r
71                                                                 });\r
72                                                                 \r
73                                                                 /*\r
74                                                                   $.ajax({\r
75                                                                          type : 'POST',\r
76                                                                          url : uuu,\r
77                                                                          dataType: 'json',\r
78                                                                          contentType: 'application/json',\r
79                                                                          data: JSON.stringify(postData),\r
80                                                                          success : function(data){\r
81                                                                                 console.log(data);\r
82                                                                                 $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); \r
83                                                                                 console.log($scope.availableRoles);\r
84                                                                          },\r
85                                                                          error : function(data){\r
86                                                                                  console.log(data);\r
87                                                                                  availableRole.active=!availableRole.active;\r
88                                                                                  confirmBoxService.showInformation("Error while saving.");\r
89                                                                          }\r
90                                                                   });\r
91                                                                   */\r
92                                                  }\r
93                                                  else {\r
94                                                          availableRole.active=!availableRole.active;\r
95                                                  }\r
96                                         \r
97                         });\r
98                         //,\r
99                         //function(){\r
100                     //          availableRole.active=!availableRole.active;\r
101                         //})\r
102                                 \r
103                                   \r
104                 };\r
105 \r
106                 $scope.removeRole = function(role) {\r
107                         \r
108                         confirmBoxService.confirm("You are about to delete the role "+role.name+". Do you want to continue?").then(\r
109                                 function(confirmed){\r
110                                                         var uuu = conf.api.removeRole;\r
111                                                           var postData={role:role};\r
112                                                   /*      $.ajax({\r
113                                                                  type : 'POST',\r
114                                                                  url : uuu,\r
115                                                                  dataType: 'json',\r
116                                                                  contentType: 'application/json',\r
117                                                                  data: JSON.stringify(postData),\r
118                                                                  success : function(data){\r
119                                                                         $scope.$apply(function(){$scope.availableRoles=data.availableRoles;});  \r
120                                                                  },\r
121                                                                  error : function(data){\r
122                                                                          console.log(data);\r
123                                                                          confirmBoxService.showInformation("Error while deleting: "+ data.responseText);\r
124                                                                  }\r
125                                                           }); */\r
126                                                           \r
127                                                           \r
128                                                           $http.post(uuu, postData).then(function(response) {\r
129                                                                         var data = response.data;\r
130                                                                         if (typeof data === 'object') {\r
131                                                                                 $scope.availableRoles=data.availableRoles; \r
132                                                                         } else {\r
133                                                                                 //\r
134                                                                         }\r
135 \r
136                                                                 }, function(response) {\r
137                                                                         console.log(response.data);\r
138                                                                         confirmBoxService.showInformation("Error while deleting: "+ data.responseText);\r
139                                                                 });\r
140                                 \r
141                 });\r
142                 \r
143                         \r
144                 };\r
145                 \r
146 \r
147 });\r