Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / controllers / rolefunctionpopupController.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 var rolefunctionpopupController =  function ($scope, modalService, $modalInstance, message, $http,AdminService){
21                                 if(message.availableRoleFunction==null) {
22                                         $scope.label='Add Role Function';
23                                         var tempText = "";
24                                 }
25                                 else{
26                                         $scope.label='Edit Role Function'
27                                         $scope.disableCd=true;
28                                         var tempText = new String(message.availableRoleFunction.name);
29                                         $scope.editRoleFunction = message.availableRoleFunction; 
30                                 }
31                                 
32                                 $scope.tempText = tempText;
33                                 
34                                 $scope.saveRoleFunction = function(availableRoleFunction) {
35                                           var uuu = "role_function_list/saveRoleFunction.htm";
36                                           var postData={availableRoleFunction: availableRoleFunction};
37
38                                           if(availableRoleFunction==null){
39                                                         modalService.showFailure("Warning",  "Please enter valid role function details.");
40                                           }
41                                           var exists = false;
42                                           for(x in message.availableRoleFunctions){
43                                                   console.log(message.availableRoleFunctions[x].name);
44                                                         if(message.availableRoleFunctions[x].name==availableRoleFunction.name){
45                                                                 modalService.showFailure("Warning",  "Role Function already exists.");
46                                                                 exists = true;
47                                                                 availableRoleFunction.name = $scope.tempText;
48                                                         }
49                                           }
50                                           
51                                           if(!exists && availableRoleFunction.name.trim() != '' && availableRoleFunction.code.trim() != ''){
52                                       $http.post(uuu, JSON.stringify(postData)).then(function(res){
53                                           console.log("data");
54 //                                        console.log(res.data);
55 //                                        $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions;
56                                           AdminService.getRoleFunctionList().then(function(data){
57                                                         
58                                                         var j = data;
59                                                         $scope.data = JSON.parse(j.data);
60                                                         $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);
61                                                         
62                                                         //$scope.resetMenu();
63                                                         $modalInstance.close();
64                                                 },function(error){
65                                                         console.log("failed");
66                                                         reloadPageOnce();
67                                                         $modalInstance.close();                                                 
68                                                 });
69                                           
70                                           
71                                       });                                                 
72                                                   
73                                                   
74                                                   
75                                                   
76                                                 }
77                                 };
78                                           
79                                           
80                                         
81                                 $scope.close = function() { 
82                                         $modalInstance.close();
83                                 };
84 }