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