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('rolefunctionpopupController',function($scope, confirmBoxService, message, $http,RoleService, conf, isEditing) {
21 if (message.availableRoleFunction == null) {
22 $scope.label = 'Add Role Function';
25 $scope.label = 'Edit Role Function'
26 $scope.disableCd = true;
27 var tempText = new String(message.availableRoleFunction.name);
28 $scope.editRoleFunction = angular.copy(message.availableRoleFunction);
31 $scope.tempText = tempText;
32 $scope.isEditing = isEditing;
34 $scope.saveRoleFunction = function(availableRoleFunction) {
35 confirmBoxService.confirm(
36 "You are about to Create the role function "+ availableRoleFunction.name+ ". Do you want to continue?")
37 .then(function(confirmed) {
40 var uuu = conf.api.saveRoleFunction;
41 var postData = availableRoleFunction;
43 if (availableRoleFunction == null) {
44 confirmBoxService.showInformation("Please enter valid role function details.");
46 var exists = false, x;
47 for (x in message.availableRoleFunctions) {
48 console.log(message.availableRoleFunctions[x].name);
49 if (message.availableRoleFunctions[x].name == availableRoleFunction.name) {
50 confirmBoxService.showInformation("Role Function already exists.");
52 availableRoleFunction.name = $scope.tempText;
56 if (message.availableRoleFunctions[x].code == availableRoleFunction.code) {
57 confirmBoxService.showInformation("Code already exists. Please create a role function with a different code to proceed.");
59 availableRoleFunction.name = $scope.tempText;
65 if (!exists&& availableRoleFunction.name.trim() != ''&& availableRoleFunction.code.trim() != '') {
66 $http.post(uuu,JSON.stringify(postData)).then(function(res) {
67 $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions;
68 RoleService.getRoleFunctionList().then(
72 $scope.data = JSON.parse(j.data);
73 $scope.availableRoleFunctions = JSON.parse($scope.data.availableRoleFunctions);
75 // $scope.resetMenu();
76 /*$scope.closeThisDialog({
78 availableRoleFunctions : $scope.availableRoleFunctions
80 $scope.$dismiss({result : true,availableRoleFunctions : $scope.availableRoleFunctions});
83 console.log("failed");
85 //$scope.closeThisDialog(true);
86 $scope.$dismiss('cancel');
94 $scope.close = function() {
95 this.closeThisDialog(true);