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