Included Policy GUI Enhancements and validations
[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                          getPDPGroups();
57                  },function (error) {
58                          console.log("failed");
59                  });
60          },function(error){
61                  console.log("failed");
62          });
63                  
64         
65         $scope.addNewPDPGroupFunctionPopup = function() {
66                 $scope.editPDPGroup = null;
67                 $( "#dialog" ).dialog({
68                         modal: true
69                 });
70         };
71
72         $scope.editPDPGroup = null;
73         $scope.editPDPGroupFunctionPopup = function(pdpGroupData) {
74                 $scope.editPDPGroup = pdpGroupData;
75                 $( "#dialog" ).dialog({
76                         modal: true
77                 });
78         };
79
80         $scope.editPDPGroupFunctionModalPopup = function(pdpGroupData) {
81                 $scope.editPDPGroup = pdpGroupData;
82                 var modalInstance;
83                 if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
84                         modalInstance = $modal.open({
85                                 backdrop: 'static', keyboard: false,
86                                 templateUrl: 'show_policies_pdp_group_popup.html',
87                                 controller: 'editPDPGrouppopupController',
88                                 resolve: {
89                                         message: function () {
90                                                 var message = {
91                                                                 pdpGroupData : $scope.editPDPGroup
92                                                 };
93                                                 return message;
94                                         }                                       
95                                 }
96                         }); 
97                 }else{
98                         modalInstance = $modal.open({
99                                 backdrop: 'static', keyboard: false,
100                                 templateUrl: 'edit_pdp_group_popup.html',
101                                 controller: 'editPDPGrouppopupController',
102                                 resolve: {
103                                         message: function () {
104                                                 var message = {
105                                                                 pdpGroupData : $scope.editPDPGroup
106                                                 };
107                                                 return message;
108                                         }                                       
109                                 }
110                         }); 
111                 }  
112                 modalInstance.result.then(function(response){
113                         console.log('response', response);
114                         getPDPGroups();
115                 });
116         };
117
118         function getPDPGroups(){
119                 PolicyAppService.getData('get_PDPGroupData').then(function(data){
120                         var j = data;
121                         $scope.pdpdatas = JSON.parse(j.data);
122                         console.log($scope.pdpdatas);
123                 },function(error){
124                         console.log("failed");
125                 });
126         }
127         
128         $scope.addNewPDPGroupPopUpWindow = function(editPDPGroup) {
129                 $scope.editPDPGroup = null;
130                 var modalInstance = $modal.open({
131                         backdrop: 'static', keyboard: false,
132                         templateUrl : 'add_pdp_group_popup.html',
133                         controller: 'editPDPGrouppopupController',
134                         resolve: {
135                                 message: function () {
136                                         var message = {
137                                                 data: $scope.editPDPGroup
138                                         };
139                                         return message;
140                                 }                                       
141                         }
142                 }); 
143                 modalInstance.result.then(function(response){
144                         console.log('response', response);
145                         $scope.pdpdatas=JSON.parse(response.data);
146                 });
147         };
148
149         $scope.addNewPDPGroupFunctionPopup = function() {
150                 $scope.editPDPGroup = null;
151                 $( "#dialog" ).dialog({
152                         modal: true
153                 });
154         };
155
156         $scope.removePDPGroup = function(pdpGroupData) {
157                 modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group  "+pdpGroupData.name+". Do you want to continue?",
158                                 function(){
159                         var uuu = "pdp_Group/remove_pdp_group.htm";
160                         var postData={pdpGroupData: pdpGroupData};
161                         $.ajax({
162                                 type : 'POST',
163                                 url : uuu,
164                                 dataType: 'json',
165                                 contentType: 'application/json',
166                                 data: JSON.stringify(postData),
167                                 success : function(response){
168                                         $scope.$apply(function(){$scope.pdpdatas=JSON.parse(response.data);});
169                                 },
170                                 error : function(data){
171                                         console.log(data);
172                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
173                                 }
174                         });
175
176                 })
177
178         };
179 });