cab5d26c009ff2792f7c2ee3d7a7dcea6fe77d76
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / pdpController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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
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  * ============LICENSE_END=========================================================
19  */
20 app.controller('pdpTabController', function ($scope, PolicyAppService, modalService, $modal){
21         $( "#dialog" ).hide();
22
23          $scope.isDisabled = true;
24          $scope.createPdpGroupId = false;
25          $scope.deletePdpGroupId = false;
26          $scope.editPdpGroupId = false;
27          $scope.pdpdatas = [];
28          PolicyAppService.getData('get_LockDownData').then(function(data){
29                  var j = data;
30                  $scope.data = JSON.parse(j.data);
31                  $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
32                  if($scope.lockdowndata[0].lockdown == true){
33                          $scope.isDisabled = true;
34                  }else{
35                          $scope.isDisabled = false;
36                  }
37                  console.log($scope.data);
38
39                  PolicyAppService.getData('get_UserRolesData').then(function(data) {
40                          var j = data;
41                          $scope.data = JSON.parse(j.data);
42                          console.log($scope.data);
43                          $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas);
44                          console.log($scope.userRolesDatas);
45                          if($scope.isDisabled == false){
46                                  if($scope.userRolesDatas[0] == 'super-admin' || $scope.userRolesDatas[0] == 'admin'){
47                                          $scope.createPdpGroupId = true;
48                                          $scope.deletePdpGroupId = true;
49                                          $scope.editPdpGroupId = true;
50                                  }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor'){
51                                          $scope.editPdpGroupId = true;
52                                  }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
53                                          $scope.editPdpGroupId = true;
54                                  }   
55                          } 
56
57                          PolicyAppService.getData('get_PDPGroupData').then(function(data){
58                                  var j = data;
59                                  $scope.pdpdatas = JSON.parse(j.data);
60                                  console.log($scope.pdpdatas);
61                          },function(error){
62                                  console.log("failed");
63                          });
64                  },function (error) {
65                          console.log("failed");
66                  });
67          },function(error){
68                  console.log("failed");
69          });
70                  
71         
72         $scope.addNewPDPGroupFunctionPopup = function() {
73                 $scope.editPDPGroup = null;
74                 $( "#dialog" ).dialog({
75                         modal: true
76                 });
77         };
78
79         $scope.editPDPGroup = null;
80         var dialog = null;
81         $scope.editPDPGroupFunctionPopup = function(pdpGroupData) {
82                 $scope.editPDPGroup = pdpGroupData;
83                 $( "#dialog" ).dialog({
84                         modal: true
85                 });
86         };
87
88         $scope.editPDPGroupFunctionModalPopup = function(pdpGroupData) {
89                 $scope.editPDPGroup = pdpGroupData;
90                 if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
91                         var modalInstance = $modal.open({
92                                 backdrop: 'static', keyboard: false,
93                                 templateUrl: 'show_policies_pdp_group_popup.html',
94                                 controller: 'editPDPGrouppopupController',
95                                 resolve: {
96                                         message: function () {
97                                                 var message = {
98                                                                 pdpGroupData : $scope.editPDPGroup
99                                                 };
100                                                 return message;
101                                         }                                       
102                                 }
103                         }); 
104                 }else{
105                         var modalInstance = $modal.open({
106                                 backdrop: 'static', keyboard: false,
107                                 templateUrl: 'edit_pdp_group_popup.html',
108                                 controller: 'editPDPGrouppopupController',
109                                 resolve: {
110                                         message: function () {
111                                                 var message = {
112                                                                 pdpGroupData : $scope.editPDPGroup
113                                                 };
114                                                 return message;
115                                         }                                       
116                                 }
117                         }); 
118                 }  
119                 modalInstance.result.then(function(response){
120                         console.log('response', response);
121                         $scope.pdpdatas=response.data;
122                 });
123         };
124
125         $scope.addNewPDPGroupPopUpWindow = function(editPDPGroup) {
126                 $scope.editPDPGroup = null;
127                 var modalInstance = $modal.open({
128                         backdrop: 'static', keyboard: false,
129                         templateUrl : 'add_pdp_group_popup.html',
130                         controller: 'editPDPGrouppopupController',
131                         resolve: {
132                                 message: function () {
133                                         var message = {
134                                                 data: $scope.editPDPGroup
135                                         };
136                                         return message;
137                                 }                                       
138                         }
139                 }); 
140                 modalInstance.result.then(function(response){
141                         console.log('response', response);
142                         $scope.pdpdatas=JSON.parse(response.data);
143                 });
144         };
145
146         $scope.addNewPDPGroupFunctionPopup = function() {
147                 $scope.editPDPGroup = null;
148                 $( "#dialog" ).dialog({
149                         modal: true
150                 });
151         };
152
153         $scope.removePDPGroup = function(pdpGroupData) {
154                 modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group  "+pdpGroupData.name+". Do you want to continue?",
155                                 function(){
156                         var uuu = "pdp_Group/remove_pdp_group.htm";
157                         var postData={pdpGroupData: pdpGroupData};
158                         $.ajax({
159                                 type : 'POST',
160                                 url : uuu,
161                                 dataType: 'json',
162                                 contentType: 'application/json',
163                                 data: JSON.stringify(postData),
164                                 success : function(data){
165                                         $scope.$apply(function(){$scope.pdpdata=data.data;});
166                                         $scope.pdpdatas=JSON.parse(data.data);
167                                 },
168                                 error : function(data){
169                                         console.log(data);
170                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
171                                 }
172                         });
173
174                 })
175
176         };
177 });