[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / pdpGroupPopUpController.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('editPDPGrouppopupController' ,  function ($scope, $modalInstance, message, modalService, $modal, Notification){
21         if(message.pdpGroupData==null)
22                 $scope.label='Add New PDP Group'
23                         else{
24                                 $scope.label='Edit PDP Group'
25                                 $scope.disableCd=true;
26                                 $scope.policies = message.pdpGroupData.policies;
27                         $scope.pdps = message.pdpGroupData.pdps;
28                         $scope.selectedPdp = message.pdpGroupData;
29                         }
30         $scope.editPDPGroup = message.pdpGroupData;
31
32         $scope.policiesGrid = {
33                 data : 'policies',
34                 enableFiltering: true,
35                 columnDefs: [
36                         { field: 'root', displayName : 'Root', width : '10%'},
37                         { field: 'name', displayName : 'Name' },
38                         { field: 'version' , width : '10%'},
39                         { field: 'id' }
40                 ]
41         };
42
43         $scope.pdpsGrid = {
44                 data : 'pdps',
45                 enableFiltering: true,
46                 columnDefs: [{
47                         field: 'id', enableFiltering: false, headerCellTemplate: '' +
48                         '<button id=\'New\' ng-click="grid.appScope.createNewPDPInGroup()" class="btn btn-success">' + 'Create PDP</button>',
49                         cellTemplate:
50                         '<button  type="button"  class="btn btn-primary" ng-click="grid.appScope.editPDPInGroup(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
51                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deletePDPFromGroup(row.entity)" ><i class="fa fa-trash-o"></i></button> '+
52                         '<button  type="button"  class="btn btn-success" ng-click="grid.appScope.statusOfPDP(row.entity.status)" >Status</button>',  width: '25%'
53                 },
54                         { field: 'id', displayName : 'PDP URL'},
55                         { field: 'jmxPort', displayName : 'JMX Port' , width : '10%' },
56                         { field: 'name' , displayName : 'PDP Name'},
57                         { field: 'description' }
58                 ]
59         };
60
61         $scope.createNewPDPInGroup = function(pdpInGroup) {
62                 $scope.pdpInGroup = null;
63                 var modalInstance = $modal.open({
64                         backdrop: 'static', keyboard: false,
65                         templateUrl : 'create_newPDP_InGroup.html',
66                         controller: 'pdpInGroupController',
67                         resolve: {
68                                 message: function () {
69                                         var message = {
70                                                 data: $scope.pdpInGroup,
71                                                 activePDP : $scope.selectedPdp
72                                         };
73                                         return message;
74                                 }
75                         }
76                 });
77                 modalInstance.result.then(function(response){
78                         console.log('response', response);
79                         $scope.data=response.data;
80                 });
81         };
82
83         $scope.editPDPInGroup = function(pdpInGroup) {
84                 $scope.editPDPInGroupData = pdpInGroup;
85                 var modalInstance = $modal.open({
86                         backdrop: 'static', keyboard: false,
87                         templateUrl: 'create_newPDP_InGroup.html',
88                         controller: 'pdpInGroupController',
89                         resolve: {
90                                 message: function () {
91                                         var message = {
92                                                 pdpInGroup : $scope.editPDPInGroupData,
93                                                 activePDP : $scope.selectedPdp
94                                         };
95                                         return message;
96                                 }
97                         }
98                 });
99                 modalInstance.result.then(function(response){
100                         console.log('response', response);
101                         $scope.data=response.data;
102                 });
103         };
104
105         $scope.deletePDPFromGroup = function(data){
106                 modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group :  "+data.name+". Do you want to continue?",
107                         function(){
108                                 var uuu = "pdp_Group/remove_pdpFromGroup.htm";
109                                 var postData={data: data,
110                                                 activePDP : $scope.selectedPdp};
111                                 $.ajax({
112                                         type : 'POST',
113                                         url : uuu,
114                                         dataType: 'json',
115                                         contentType: 'application/json',
116                                         data: JSON.stringify(postData),
117                                         success : function(data){
118                                                 $scope.$apply(function(){$scope.data=data.data;});
119                                                 Notification.success("PDP Group Deleted Successfully");
120                                         },
121                                         error : function(data){
122                                                 console.log(data);
123                                                 Notification.error("Error Occured While Deleting a PDP Group")
124                                                 //modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
125                                         }
126                                 });
127
128                         })
129         };
130
131         $scope.statusOfPDP = function(status){
132                 $scope.pdpStatus = status;
133                 console.log($scope.pdpStatus);
134                 var modalInstance = $modal.open({
135                         backdrop: 'static', keyboard: false,
136                         templateUrl: 'pdpGroupStatusWindow.html',
137                         controller: 'pdpGroupStatusController',
138                         resolve: {
139                                 message: function () {
140                                         var message = {
141                                                 status : $scope.pdpStatus,
142                                                 policies : $scope.policies
143                                         };
144                                         return message;
145                                 }
146                         }
147                 });
148                 modalInstance.result.then(function(response){
149                         console.log('response', response);
150                         $scope.data=response.data;
151                 });
152         };
153
154         $scope.savePDPGroup = function(pdpGroupData) {
155                 var uuu = "pdp_Group/save_pdp_group.htm";
156                 var postData={pdpGroupData: pdpGroupData};
157                 $.ajax({
158                         type : 'POST',
159                         url : uuu,
160                         dataType: 'json',
161                         contentType: 'application/json',
162                         data: JSON.stringify(postData),
163                         success : function(data){
164                                 $scope.$apply(function(){
165                                 $scope.data=data.data;});
166                                 console.log($scope.data);
167                                 $modalInstance.close({data:$scope.data});
168                         },
169                         error : function(data){
170                                 alert("Error while saving.");
171                         }
172                 });
173         };
174
175         $scope.close = function() {
176                 $modalInstance.close();
177         };
178 });