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 var rolepopupController = function ($scope, $modalInstance, role, roleId, availableRoles, availableRoleFunctions,AdminService,modalService){
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 = "role/removeRoleFunction.htm?role_id=" + roleId;
74 modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role function "+availableRoleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?",
76 var postData={roleFunction:availableRoleFunction};
81 contentType: 'application/json',
82 data: JSON.stringify(postData),
83 success : function(data){
84 $scope.$apply(function(){$scope.role=data.role;});
86 error : function(data){
87 modalService.showFailure("Fail","Error while saving.");
93 availableRoleFunction.selected=!availableRoleFunction.selected;
99 $scope.role.roleFunctions.push(availableRoleFunction);
102 var uuu = "role/addRoleFunction.htm?role_id=" + roleId;
104 modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role function "+availableRoleFunction.name+" to the role for "+$scope.role.name+". Do you want to continue?",
106 var postData={roleFunction:availableRoleFunction};
111 contentType: 'application/json',
112 data: JSON.stringify(postData),
113 success : function(data){
114 $scope.$apply(function(){$scope.role=data.role;});
116 error : function(data){
117 modalService.showFailure("Fail","Error while saving.");
123 availableRoleFunction.selected=!availableRoleFunction.selected;
130 $scope.toggleChildRole = function(selected,availableRole) {
131 //alert('toggleRole: '+selected);
136 var index = $scope.role.childRoles.indexOf(availableRole);
138 $scope.role.childRoles.splice(index, 1);
141 var uuu = "role/removeChildRole.htm?role_id=" + roleId;
143 modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the child role "+availableRole.name+" from the role for "+$scope.role.name+". Do you want to continue?",
145 var postData={childRole:availableRole};
150 contentType: 'application/json',
151 data: JSON.stringify(postData),
152 success : function(data){
153 console.log('role',data.role);
154 $scope.$apply(function(){$scope.role=data.role;});
156 error : function(data){
157 modalService.showFailure("Fail","Error while saving.");
163 availableRole.selected=true;
169 $scope.role.childRoles.push(availableRole);
172 var uuu = "role/addChildRole.htm?role_id=" + roleId;
174 modalService.popupConfirmWinWithCancel("Confirm","You are about to add the child role "+availableRole.name+" to the role for "+$scope.role.name+". Do you want to continue?",
176 var postData={childRole:availableRole};
181 contentType: 'application/json',
182 data: JSON.stringify(postData),
183 success : function(data){
184 $scope.$apply(function(){$scope.role=data.role;});
186 error : function(data){
187 modalService.showFailure("Fail","Error while saving.");
193 availableRole.selected=false;
200 $scope.close = function() {
201 console.log('role', $scope.role);
202 $modalInstance.close({role:$scope.role});