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('rolepopupController', function ($scope, role, roleId, confirmBoxService, $http, $state, availableRoles, conf, availableRoleFunctions,ngDialog){
\r
23 console.log($scope.role);
\r
24 if($scope.role.childRoles==null){
\r
25 $scope.role.childRoles=[];
\r
28 $scope.ociavailableRoles=availableRoles;
\r
29 console.log($scope.ociavailableRoles);
\r
31 $scope.availableRoles=[];
\r
32 if($scope.ociavailableRoles)
\r
33 $.each($scope.ociavailableRoles, function(i, a){
\r
34 var availableRole = a;
\r
35 availableRole.selected = false;
\r
36 if($scope.role.childRoles){
\r
37 $.each($scope.role.childRoles, function(j, b){
\r
39 availableRole.selected = true;
\r
43 $scope.availableRoles.push(availableRole);
\r
46 $scope.ociavailableRoleFunctions = availableRoleFunctions;
\r
47 console.log($scope.ociavailableRoleFunctions);
\r
48 $scope.availableRoleFunctions = [];
\r
49 if($scope.ociavailableRoleFunctions)
\r
50 $.each($scope.ociavailableRoleFunctions, function(i, a){
\r
51 var availableRoleFunction = a;
\r
52 availableRoleFunction.selected = false;
\r
53 $.each($scope.role.roleFunctions, function(j, b){
\r
54 if(a.code === b.code) {
\r
55 availableRoleFunction.selected = true;
\r
58 $scope.availableRoleFunctions.push(availableRoleFunction);
\r
60 //$scope.resetMenu();
\r
62 $scope.toggleRoleFunction = function(selected,availableRoleFunction) {
\r
63 //alert('toggleRole: '+selected);
\r
66 //remove role function
\r
68 var index = $scope.role.roleFunctions.indexOf(availableRoleFunction);
\r
70 $scope.role.roleFunctions.splice(index, 1);
\r
73 var uuu = conf.api.toggleRoleRoleFunction + "?role_id=" + roleId;
\r
74 confirmBoxService.confirm("You are about to remove the role function "+availableRoleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?").then(
\r
75 function(confirmed){
\r
77 var postData={roleFunction:availableRoleFunction};
\r
78 $http.post(uuu, postData).then(
\r
79 function(response) {
\r
80 $scope.role= response.data.role;
\r
82 function(response) {
\r
83 confirmBoxService.showInformation("Error while saving.");
\r
92 availableRoleFunction.selected=!availableRoleFunction.selected;
\r
99 contentType: 'application/json',
\r
100 data: JSON.stringify(postData),
\r
101 success : function(data){
\r
102 $scope.$apply(function(){$scope.role=data.role;});
\r
104 error : function(data){
\r
105 modalService.showFailure("Fail","Error while saving.");
\r
112 //add role function
\r
114 $scope.role.roleFunctions.push(availableRoleFunction);
\r
117 var uuu = conf.api.addRoleRoleFunction + "?role_id=" + roleId;
\r
119 confirmBoxService.confirm("You are about to add the role function "+availableRoleFunction.name+" to the role for "+$scope.role.name+". Do you want to continue?").then(
\r
120 function(confirmed){
\r
122 var postData={roleFunction:availableRoleFunction};
\r
123 $http.post(uuu,postData).then( function(response) {
\r
124 $scope.role=response.data.role;
\r
128 confirmBoxService.showInformation("Error while saving.");
\r
131 availableRoleFunction.selected=!availableRoleFunction.selected;
\r
138 contentType: 'application/json',
\r
139 data: JSON.stringify(postData),
\r
140 success : function(data){
\r
141 $scope.$apply(function(){$scope.role=data.role;});
\r
143 error : function(data){
\r
144 modalService.showFailure("Fail","Error while saving.");
\r
151 availableRoleFunction.selected=!availableRoleFunction.selected;
\r
159 $scope.toggleChildRole = function(selected,availableRole) {
\r
160 //alert('toggleRole: '+selected);
\r
165 var index = $scope.role.childRoles.indexOf(availableRole);
\r
167 $scope.role.childRoles.splice(index, 1);
\r
170 var uuu = conf.api.toggleRoleChildRole +"?role_id=" + roleId;
\r
172 confirmBoxService.confirm("You are about to remove the child role "+availableRole.name+" from the role for "+$scope.role.name+". Do you want to continue?").then(
\r
173 function(confirmed){
\r
176 var postData={childRole:availableRole};
\r
177 $http.post(uuu,postData).then(function(response) {
\r
178 $scope.role=response.data.role;
\r
181 confirmBoxService.showInformation("Error while saving.");
\r
184 availableRole.selected=false;
\r
191 contentType: 'application/json',
\r
192 data: JSON.stringify(postData),
\r
193 success : function(data){
\r
194 console.log('role',data.role);
\r
195 $scope.$apply(function(){$scope.role=data.role;});
\r
197 error : function(data){
\r
198 modalService.showFailure("Fail","Error while saving.");
\r
207 $scope.role.childRoles.push(availableRole);
\r
210 var uuu = conf.api.addRoleChildRole +"?role_id=" + roleId;
\r
212 confirmBoxService.confirm("You are about to add the child role "+availableRole.name+" to the role for "+$scope.role.name+". Do you want to continue?").then(
\r
213 function(confirmed){
\r
215 var postData={childRole:availableRole};
\r
216 $http.post(uuu,postData).then(function(response) {
\r
217 $scope.role=response.data.role;
\r
220 confirmBoxService.showInformation("Error while saving.");
\r
223 availableRole.selected=false;
\r
229 contentType: 'application/json',
\r
230 data: JSON.stringify(postData),
\r
231 success : function(data){
\r
232 $scope.$apply(function(){$scope.role=data.role;});
\r
234 error : function(data){
\r
235 modalService.showFailure("Fail","Error while saving.");
\r
245 $scope.close = function() {
\r
246 console.log('role', $scope.role);
\r
247 //$modalInstance.close({role:$scope.role});
\r
248 this.closeThisDialog(true);
\r