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