2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END=========================================================
20 app.controller('editRoleController' , function ($scope, PolicyAppService, $modalInstance, message){
21 if (message.editRoleData != null) {
22 $scope.label='Edit Role'
23 $scope.disableCd=true;
25 $scope.label='Add Role'
26 $scope.disableCd=false;
27 message.editRoleData = {
32 $scope.editRole = message.editRoleData;
34 $scope.activeScopes = [];
35 if (message.editRoleData != null && message.editRoleData.scope != null) {
36 if (message.editRoleData.scope.constructor === Array) {
37 $scope.activeScopes = message.editRoleData.scope;
39 $scope.activeScopes = message.editRoleData.scope.split(',');
43 PolicyAppService.getData('get_PolicyRolesScopeData').then(function (data) {
45 $scope.data = JSON.parse(j.data);
46 console.log($scope.data);
47 $scope.scopeDatas = JSON.parse($scope.data.scopeDatas);
48 console.log($scope.scopeDatas);
50 console.log("failed");
53 $scope.saveRole = function(editRoleData) {
54 var uuu = "save_NonSuperRolesData.htm";
55 editRoleData.scope = $scope.activeScopes;
56 var postData={editRoleData: editRoleData};
61 contentType: 'application/json',
62 data: JSON.stringify(postData),
63 success : function(data){
64 $scope.$apply(function(){
65 $scope.rolesDatas=data.rolesDatas;});
66 console.log($scope.rolesDatas);
67 $modalInstance.close({rolesDatas:$scope.rolesDatas});
69 error : function(data){
70 alert("Error while saving Role.");
76 $scope.createMechidScope = function(editRoleData) {
77 var uuu = "save_NewMechidScopesData";
78 editRoleData.scope = $scope.activeScopes;
79 var postData={editRoleData: editRoleData};
84 contentType: 'application/json',
85 data: JSON.stringify(postData),
86 success : function(data){
87 $scope.$apply(function(){
88 $scope.rolesDatas=data.rolesDatas;});
89 console.log($scope.rolesDatas);
90 $modalInstance.close({rolesDatas:$scope.rolesDatas});
92 error : function(data) {
93 alert("Error while Creating Mechid scopes.");
100 $scope.addScope = function(scopes) {
101 for (var i = 0; i < scopes.length; i++) {
102 if ($.inArray(scopes[i], $scope.activeScopes) === -1) {
103 $scope.activeScopes.push(scopes[i]);
107 $scope.deleteScope = function(index) {
108 $scope.activeScopes.splice(index, 1);