Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / AutoPushTabController / RemovePDPGroupPoliciesController.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 /**
22  */
23 var removeGroupPoliciesController =  function ($scope, $modalInstance, message, Notification){
24     if(message.selectedPdpGroupData !=null){
25         $scope.label='Remove PDP Group Policies'
26         $scope.disableCd=true;
27     }
28     $scope.policies = message.selectedPdpGroupData.policies;
29     $scope.pdpGroupData = message.selectedPdpGroupData;
30
31     $scope.removePoliciesGrid = {
32         data : 'policies',
33         enableFiltering: true,
34         columnDefs: [
35             { field: 'root', displayName : 'Root', width : '10%'},
36             { field: 'name', displayName : 'Name' },
37             { field: 'version' , width : '10%'},
38             { field: 'id' }
39         ]
40     };
41
42     $scope.removePoliciesGrid.onRegisterApi = function(gridApi){
43         //set gridApi on scope
44         $scope.gridApi = gridApi;
45         gridApi.selection.on.rowSelectionChanged($scope,function(row){
46             var msg = 'row selected ' + row.isSelected;
47         });
48
49         gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){
50             var msg = 'rows changed ' + rows.length;
51         });
52     };
53
54     $scope.removePolicies = function() {
55         $scope.removeGroupData = [];
56         angular.forEach($scope.gridApi.selection.getSelectedRows(), function (data, index) {
57                 $scope.removeGroupData.push(data);    
58         });
59         var uuu = "auto_Push/remove_GroupPolicies.htm";
60         var postData={data: $scope.removeGroupData,
61                         activePdpGroup : $scope.pdpGroupData};
62         $.ajax({
63             type : 'POST',
64             url : uuu,
65             dataType: 'json',
66             contentType: 'application/json',
67             data: JSON.stringify(postData),
68             success : function(data){
69                 $scope.$apply(function(){
70                     $scope.data=data.data;});
71                 console.log($scope.data);
72                 $modalInstance.close({data:$scope.data});
73                 Notification.success("Policy Removed Successfully");
74             },
75             error : function(data){
76                 Notification.error("Error Occured while removing Policy");
77             }
78         });
79
80     };
81
82     $scope.close = function() {
83         $modalInstance.close();
84     };
85 }