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,$log){
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;
35 $scope.goToUrl = function(roleIdVal) {
36 $state.go("root.role", {"roleId":roleIdVal});
38 $scope.toggleRole = function(selected,availableRole) {
39 var toggleType = null;
41 toggleType = "activate";
43 toggleType = "inactivate";
45 if((availableRole.id == "1") || (availableRole.id =="999"))
47 confirmBoxService.showInformation(availableRole.name+" role cannot be disabled");
48 availableRole.active=!availableRole.active
51 confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then(
55 var uuu = conf.api.toggleRole;
57 var postData={role:availableRole};
58 $http.post(uuu, postData).then(function(response) {
59 var data = response.data;
60 if (typeof data === 'object') {
61 $log.debug('data:'+data);
62 $scope.availableRoles=data.availableRoles;
63 $log.debug('role::availableRoles:'+$scope.availableRoles);
68 }, function(response) {
69 debug.log('response:'+response);
70 availableRole.active=!availableRole.active;
71 confirmBoxService.showInformation("Error while saving.");
76 }) .catch(function(err) {
77 $log.error('roleListController::confirmBoxService.confirm error:', err);
78 availableRole.active=!availableRole.active;
84 $scope.removeRole = function(role) {
86 confirmBoxService.confirm("You are about to delete the role "+role.name+". Do you want to continue?").then(
88 var uuu = conf.api.removeRole;
89 var postData={role:role};
93 $http.post(uuu, postData).then(function(response) {
94 var data = response.data;
95 if (typeof data === 'object') {
96 $scope.availableRoles=data.availableRoles;
101 }, function(response) {
102 $log.debug('response:'+response.data);
103 confirmBoxService.showInformation("Error while deleting: "+ data.responseText);