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.");
96 contentType: 'application/json',
97 data: JSON.stringify(postData),
98 success : function(data){
99 $scope.$apply(function(){$scope.role=data.role;});
101 error : function(data){
102 modalService.showFailure("Fail","Error while saving.");
106 }).catch(function(err) {
107 availableRoleFunction.selected=!availableRoleFunction.selected;
108 $log.error('roleListController::confirmBoxService.confirm error:', err);
115 $scope.role.roleFunctions.push(availableRoleFunction);
118 var uuu = conf.api.addRoleRoleFunction + "?role_id=" + roleId;
120 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(
123 var postData={roleFunction:availableRoleFunction};
124 $http.post(uuu,postData).then( function(response) {
125 $scope.role=response.data.role;
129 confirmBoxService.showInformation("Error while saving.");
136 contentType: 'application/json',
137 data: JSON.stringify(postData),
138 success : function(data){
139 $scope.$apply(function(){$scope.role=data.role;});
141 error : function(data){
142 modalService.showFailure("Fail","Error while saving.");
149 availableRoleFunction.selected=!availableRoleFunction.selected;
151 }).catch(function(err) {
152 availableRoleFunction.selected=!availableRoleFunction.selected;
153 $log.error('roleListController::confirmBoxService.confirm error:', err);
160 $scope.toggleChildRole = function(selected,availableRole) {
161 //alert('toggleRole: '+selected);
166 var index = $scope.role.childRoles.indexOf(availableRole);
168 $scope.role.childRoles.splice(index, 1);
171 var uuu = conf.api.toggleRoleChildRole +"?role_id=" + roleId;
173 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(
177 var postData={childRole:availableRole};
178 $http.post(uuu,postData).then(function(response) {
179 $scope.role=response.data.role;
182 confirmBoxService.showInformation("Error while saving.");
185 }).catch(function(err) {
186 availableRole.selected=!availableRole.selected;
187 $log.error('roleListController::confirmBoxService.confirm error:', err);
193 contentType: 'application/json',
194 data: JSON.stringify(postData),
195 success : function(data){
196 console.log('role',data.role);
197 $scope.$apply(function(){$scope.role=data.role;});
199 error : function(data){
200 modalService.showFailure("Fail","Error while saving.");
209 $scope.role.childRoles.push(availableRole);
212 var uuu = conf.api.addRoleChildRole +"?role_id=" + roleId;
214 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(
217 var postData={childRole:availableRole};
218 $http.post(uuu,postData).then(function(response) {
219 $scope.role=response.data.role;
222 confirmBoxService.showInformation("Error while saving.");
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.");
239 }).catch(function(err) {
240 availableRole.selected=!availableRole.selected;
241 $log.error('roleListController::confirmBoxService.confirm error:', err);
248 $scope.close = function() {
249 console.log('role', $scope.role);
250 //$modalInstance.close({role:$scope.role});
251 this.closeThisDialog(true);