2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 app.controller('rolepopupController', function ($scope, role, roleId, confirmBoxService, $http, $state, availableRoles, conf, availableRoleFunctions,ngDialog){
41 console.log($scope.role);
42 if($scope.role.childRoles==null){
43 $scope.role.childRoles=[];
46 $scope.ociavailableRoles=availableRoles;
47 console.log($scope.ociavailableRoles);
49 $scope.availableRoles=[];
50 if($scope.ociavailableRoles)
51 $.each($scope.ociavailableRoles, function(i, a){
52 var availableRole = a;
53 availableRole.selected = false;
54 if($scope.role.childRoles){
55 $.each($scope.role.childRoles, function(j, b){
57 availableRole.selected = true;
61 $scope.availableRoles.push(availableRole);
64 $scope.ociavailableRoleFunctions = availableRoleFunctions;
65 console.log($scope.ociavailableRoleFunctions);
66 $scope.availableRoleFunctions = [];
67 if($scope.ociavailableRoleFunctions)
68 $.each($scope.ociavailableRoleFunctions, function(i, a){
69 var availableRoleFunction = a;
70 availableRoleFunction.selected = false;
71 $.each($scope.role.roleFunctions, function(j, b){
72 if(a.code === b.code) {
73 availableRoleFunction.selected = true;
76 $scope.availableRoleFunctions.push(availableRoleFunction);
80 $scope.toggleRoleFunction = function(selected,availableRoleFunction) {
81 //alert('toggleRole: '+selected);
84 //remove role function
86 var index = $scope.role.roleFunctions.indexOf(availableRoleFunction);
88 $scope.role.roleFunctions.splice(index, 1);
91 var uuu = conf.api.toggleRoleRoleFunction + "?role_id=" + roleId;
92 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(
95 availableRoleFunction.id = roleId;
96 var index = $scope.role.roleFunctions.indexOf(availableRoleFunction);
98 $scope.role.roleFunctions.splice(index, 1);
102 }).catch(function(err) {
103 availableRoleFunction.selected=!availableRoleFunction.selected;
104 $log.error('roleListController::confirmBoxService.confirm error:', err);
111 $scope.role.roleFunctions.push(availableRoleFunction);
114 var uuu = conf.api.addRoleRoleFunction + "?role_id=" + roleId;
116 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(
119 availableRoleFunction.id = roleId;
120 $scope.role.roleFunctions.push(availableRoleFunction);
123 }).catch(function(err) {
124 availableRoleFunction.selected=!availableRoleFunction.selected;
125 $log.error('roleListController::confirmBoxService.confirm error:', err);
132 $scope.toggleChildRole = function(selected,availableRole) {
133 //alert('toggleRole: '+selected);
138 var index = $scope.role.childRoles.indexOf(availableRole);
140 $scope.role.childRoles.splice(index, 1);
143 var uuu = conf.api.toggleRoleChildRole +"?role_id=" + roleId;
145 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(
149 var postData={childRole:availableRole};
150 $http.post(uuu,postData).then(function(response) {
151 $scope.role=response.data.role;
154 confirmBoxService.showInformation("Error while saving.");
157 }).catch(function(err) {
158 availableRole.selected=!availableRole.selected;
159 $log.error('roleListController::confirmBoxService.confirm error:', err);
166 $scope.role.childRoles.push(availableRole);
169 var uuu = conf.api.addRoleChildRole +"?role_id=" + roleId;
171 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(
174 var postData={childRole:availableRole};
175 $http.post(uuu,postData).then(function(response) {
176 $scope.role=response.data.role;
179 confirmBoxService.showInformation("Error while saving.");
183 }).catch(function(err) {
184 availableRole.selected=!availableRole.selected;
185 $log.error('roleListController::confirmBoxService.confirm error:', err);
192 $scope.close = function() {
193 console.log('role', $scope.role);
194 //$modalInstance.close({role:$scope.role});
195 this.closeThisDialog(true);