2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 app.controller('roleListController', function ($scope,RoleService,confirmBoxService,conf,$state,$http){
21 $scope.showSpinner = true;
23 RoleService.getRoles().then(function(data){
24 $scope.showSpinner = true;
26 $scope.data = JSON.parse(j.data);
27 $scope.availableRoles =JSON.parse($scope.data.availableRoles);
28 $scope.showSpinner = false;
32 console.log("failed");
37 $scope.goToUrl = function(roleIdVal) {
38 $state.go("root.role", {"roleId":roleIdVal});
40 //console.log($scope.availableRoles);
41 $scope.toggleRole = function(selected,availableRole) {
42 //alert('toggleRole: '+selected);
43 var toggleType = null;
45 toggleType = "activate";
47 toggleType = "inactivate";
50 confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then(
54 var uuu = conf.api.toggleRole;
56 var postData={role:availableRole};
57 $http.post(uuu, postData).then(function(response) {
58 var data = response.data;
59 if (typeof data === 'object') {
61 $scope.availableRoles=data.availableRoles;
62 console.log($scope.availableRoles);
67 }, function(response) {
68 console.log(response.data);
69 availableRole.active=!availableRole.active;
70 confirmBoxService.showInformation("Error while saving.");
78 contentType: 'application/json',
79 data: JSON.stringify(postData),
80 success : function(data){
82 $scope.$apply(function(){$scope.availableRoles=data.availableRoles;});
83 console.log($scope.availableRoles);
85 error : function(data){
87 availableRole.active=!availableRole.active;
88 confirmBoxService.showInformation("Error while saving.");
94 availableRole.active=!availableRole.active;
100 // availableRole.active=!availableRole.active;
106 $scope.removeRole = function(role) {
108 confirmBoxService.confirm("You are about to delete the role "+role.name+". Do you want to continue?").then(
110 var uuu = conf.api.removeRole;
111 var postData={role:role};
116 contentType: 'application/json',
117 data: JSON.stringify(postData),
118 success : function(data){
119 $scope.$apply(function(){$scope.availableRoles=data.availableRoles;});
121 error : function(data){
123 confirmBoxService.showInformation("Error while deleting: "+ data.responseText);
128 $http.post(uuu, postData).then(function(response) {
129 var data = response.data;
130 if (typeof data === 'object') {
131 $scope.availableRoles=data.availableRoles;
136 }, function(response) {
137 console.log(response.data);
138 confirmBoxService.showInformation("Error while deleting: "+ data.responseText);