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