[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / role / rolefunctionpopupController.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 app.controller('rolefunctionpopupController', function ($scope, confirmBoxService, message, $http,RoleService, conf, isEditing){\r
21                                 if(message.availableRoleFunction==null) {\r
22                                         $scope.label='Add Role Function';\r
23                                         var tempText = "";\r
24                                 }\r
25                                 else{\r
26                                         $scope.label='Edit Role Function'\r
27                                         $scope.disableCd=true;\r
28                                         var tempText = new String(message.availableRoleFunction.name);\r
29                                         $scope.editRoleFunction = angular.copy(message.availableRoleFunction);\r
30                                 }\r
31                                 \r
32                                 $scope.tempText = tempText;\r
33                                 $scope.isEditing = isEditing;\r
34                                 \r
35                                 $scope.saveRoleFunction = function(availableRoleFunction) {\r
36                                           var uuu = conf.api.saveRoleFunction;\r
37                                           var postData={availableRoleFunction: availableRoleFunction};\r
38 \r
39                                           if(availableRoleFunction==null){\r
40                                                   confirmBoxService.showInformation("Please enter valid role function details.");\r
41                                           }\r
42                                           var exists = false,x;\r
43                                           for(x in message.availableRoleFunctions){\r
44                                                   console.log(message.availableRoleFunctions[x].name);\r
45                                                         if(message.availableRoleFunctions[x].name==availableRoleFunction.name){\r
46                                                                 confirmBoxService.showInformation("Role Function already exists.");\r
47                                                                 exists = true;\r
48                                                                 availableRoleFunction.name = $scope.tempText;\r
49                                                                 break;\r
50                                                         } \r
51                                                         if(!isEditing){\r
52                                                                 if (message.availableRoleFunctions[x].code == availableRoleFunction.code) {\r
53                                                                         confirmBoxService.showInformation("Code already exists. Please create a role function with a different code to proceed.");\r
54                                                                         exists = true;\r
55                                                                         availableRoleFunction.name = $scope.tempText;\r
56                                                                         break;\r
57                                                                 }\r
58                                                         }\r
59                                           }\r
60                                           \r
61                                           if(!exists && availableRoleFunction.name.trim() != '' && availableRoleFunction.code.trim() != ''){\r
62                                       $http.post(uuu, JSON.stringify(postData)).then(function(res){\r
63                                           console.log("data");\r
64 //                                        console.log(res.data);\r
65 //                                        $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions;\r
66                                           RoleService.getRoleFunctionList().then(function(data){\r
67                                                         \r
68                                                         var j = data;\r
69                                                         $scope.data = JSON.parse(j.data);\r
70                                                         $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);\r
71                                                         \r
72                                                         //$scope.resetMenu();\r
73                                                         $scope.closeThisDialog({result: true, availableRoleFunctions: $scope.availableRoleFunctions });\r
74                                                 },function(error){\r
75                                                         console.log("failed");\r
76                                                         //reloadPageOnce();\r
77                                                         $scope.closeThisDialog(true);                                           \r
78                                                 });\r
79                                           \r
80                                           \r
81                                       });                                                 \r
82                                                   \r
83                                                   \r
84                                                   \r
85                                                   \r
86                                                 }\r
87                                 };\r
88                                           \r
89                                           \r
90                                         \r
91                                 $scope.close = function() { \r
92                                         this.closeThisDialog(true);\r
93                                 };\r
94 }\r
95 );\r