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('roleController', function ($scope, modalService, $modal, AdminService,$routeParams){
21 //$scope.role=${role};
22 //console.log($scope.role.roleFunctions);
24 $( "#dialogRoleFunction" ).hide();
25 $( "#dialogChildRole" ).hide();
27 //$scope.ociavailableRoleFunctions=${availableRoleFunctions};
29 AdminService.getRole($routeParams.roleId).then(function(data){
32 $scope.data = JSON.parse(j.data);
34 $scope.role =JSON.parse($scope.data.role);
35 console.log($scope.role);
37 $scope.ociavailableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);
38 console.log($scope.ociavailableRoleFunctions);
39 $scope.availableRoleFunctions=[];
41 if($scope.ociavailableRoleFunctions)
42 $.each($scope.ociavailableRoleFunctions, function(i, a){
43 var availableRoleFunction = a;
44 availableRoleFunction.selected = false;
45 $.each($scope.role.roleFunctions, function(j, b){
46 if(a.code === b.code) {
47 availableRoleFunction.selected = true;
50 $scope.availableRoleFunctions.push(availableRoleFunction);
54 $scope.ociavailableRoles=JSON.parse($scope.data.availableRoles);
55 console.log($scope.ociavailableRoles);
56 console.log("testing roles if exist");
57 $scope.availableRoles=[];
59 if($scope.ociavailableRoles)
60 $.each($scope.ociavailableRoles, function(i, a){
61 var availableRole = a;
62 availableRole.selected = false;
63 if($scope.role.childRoles){
64 $.each($scope.role.childRoles, function(j, b){
66 availableRole.selected = true;
70 $scope.availableRoles.push(availableRole);
75 console.log("failed");
79 $scope.saveRole = function() {
81 for(x in $scope.availableRoles){
82 console.log($scope.availableRoles[x].name);
83 if($scope.availableRoles[x].name==$scope.role.name){
84 modalService.showFailure("Warning", "Role already exists.");
86 //$modalInstance.close({availableRoleFunctions:message.availableRoleFunctions});
90 var uuu = "role/saveRole.htm?role_id="+$routeParams.roleId;
91 var postData={role: $scope.role, childRoles: $scope.role.childRoles, roleFunctions : $scope.role.roleFunctions};
96 contentType: 'application/json',
97 data: JSON.stringify(postData),
98 success : function(data){
99 modalService.showSuccess("Success","Update Successful.");
101 error : function(data){
103 modalService.showFailure("Fail","Error while saving.");
110 $scope.addNewRoleFunctionModalPopup = function() {
111 var modalInstance = $modal.open({
112 templateUrl: 'role_functions_popup.html',
113 controller: 'rolepopupController',
116 roleId: function () {
117 return $routeParams.roleId;
122 availableRoles: function () {
123 return $scope.ociavailableRoles;
125 availableRoleFunctions: function () {
126 return $scope.ociavailableRoleFunctions;
130 modalInstance.result.then(function(response){
131 console.log('response', response);
132 $scope.role=response.role;
136 $scope.addNewChildRoleModalPopup = function() {
137 var modalInstance = $modal.open({
138 templateUrl: 'child_roles_popup.html',
139 controller: 'rolepopupController',
142 roleId: function () {
143 return $routeParams.roleId;
148 availableRoles: function () {
149 return $scope.ociavailableRoles;
151 availableRoleFunctions: function () {
152 return $scope.ociavailableRoleFunctions;
156 modalInstance.result.then(function(response){
157 console.log('response', response);
158 $scope.role=response.role;
164 $scope.removeRoleFunction = function(roleFunction) {
165 modalService.popupConfirmWin("Confirm","You are about to remove the role function "+roleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?",
167 var uuu = "role/removeRoleFunction.htm?role_id=" + $routeParams.roleId;
168 var postData={roleFunction:roleFunction};
173 contentType: 'application/json',
174 data: JSON.stringify(postData),
175 success : function(data){
176 $scope.$apply(function(){
177 $scope.role=data.role;
178 $.each($scope.availableRoleFunctions, function(k, c){
179 if(c.code === roleFunction.code) {
186 error : function(data){
187 modalService.showFailure("Fail","Error while saving.");
195 $scope.removeChildRole = function(childRole) {
196 modalService.popupConfirmWin("Confirm","You are about to remove the child role "+childRole.name+" from the role for "+$scope.role.name+". Do you want to continue?",
198 var uuu = "role/removeChildRole.htm?role_id=" + $routeParams.roleId;
199 var postData={childRole:childRole};
204 contentType: 'application/json',
205 data: JSON.stringify(postData),
206 success : function(data){
207 $scope.$apply(function(){
208 $scope.role=data.role;
209 $.each($scope.availableRoles, function(k, c){
210 if(c.id === childRole.id) {
217 error : function(data){
218 modalService.showFailure("Fail","Error while saving.");