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';
26 $scope.label='Edit Role Function'
27 $scope.disableCd=true;
28 var tempText = new String(message.availableRoleFunction.name);
29 $scope.editRoleFunction = angular.copy(message.availableRoleFunction);
32 $scope.tempText = tempText;
33 $scope.isEditing = isEditing;
35 $scope.saveRoleFunction = function(availableRoleFunction) {
36 var uuu = conf.api.saveRoleFunction;
37 var postData={availableRoleFunction: availableRoleFunction};
39 if(availableRoleFunction==null){
40 confirmBoxService.showInformation("Please enter valid role function details.");
43 for(x in message.availableRoleFunctions){
44 console.log(message.availableRoleFunctions[x].name);
45 if(message.availableRoleFunctions[x].name==availableRoleFunction.name){
46 confirmBoxService.showInformation("Role Function already exists.");
48 availableRoleFunction.name = $scope.tempText;
52 if (message.availableRoleFunctions[x].code == availableRoleFunction.code) {
53 confirmBoxService.showInformation("Code already exists. Please create a role function with a different code to proceed.");
55 availableRoleFunction.name = $scope.tempText;
61 if(!exists && availableRoleFunction.name.trim() != '' && availableRoleFunction.code.trim() != ''){
62 $http.post(uuu, JSON.stringify(postData)).then(function(res){
64 // console.log(res.data);
65 // $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions;
66 RoleService.getRoleFunctionList().then(function(data){
69 $scope.data = JSON.parse(j.data);
70 $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);
73 $scope.closeThisDialog({result: true, availableRoleFunctions: $scope.availableRoleFunctions });
75 console.log("failed");
77 $scope.closeThisDialog(true);
91 $scope.close = function() {
92 this.closeThisDialog(true);