[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWAddressGroupDictGridController.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('addressGroupDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_AddressGroupData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
28         console.log($scope.addressGroupDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32     
33     PolicyAppService.getData('get_LockDownData').then(function(data){
34                  var j = data;
35                  $scope.data = JSON.parse(j.data);
36                  $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37                  if($scope.lockdowndata[0].lockdown == true){
38                          $scope.addressGroupDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.addressGroupDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47
48     
49     $scope.addressGroupDictionaryGrid = {
50         data : 'addressGroupDictionaryDatas',
51         enableFiltering: true,
52         exporterCsvFilename: 'AddressGroup.csv',
53         enableGridMenu: true,
54         enableSelectAll: true,
55         columnDefs: [{
56             field: 'id', enableFiltering: false, headerCellTemplate: '' +
57             '<button id=\'New\' ng-click="grid.appScope.createNewFWAddressGroupWindow()" class="btn btn-success">' + 'Create</button>',
58             cellTemplate:
59             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWAddressGroupWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
60             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWAddressGroup(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
61         },{ field: 'groupName', displayName : 'Group Name', sort: { direction: 'asc', priority: 0 }},
62             { field: 'prefixList', displayName : 'Prefix List' },
63             { field: 'description' }
64         ],
65         exporterMenuPdf: false,
66         exporterPdfDefaultStyle: {fontSize: 9},
67         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
68         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
69         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
70         exporterPdfFooter: function ( currentPage, pageCount ) {
71          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
72         },
73         exporterPdfCustomFormatter: function ( docDefinition ) {
74          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
75          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
76          return docDefinition;
77         },
78         exporterPdfOrientation: 'portrait',
79         exporterPdfPageSize: 'LETTER',
80         exporterPdfMaxGridWidth: 500,
81         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
82         onRegisterApi: function(gridApi){
83                 $scope.gridApi = gridApi;
84         }
85     };
86
87
88     $scope.editAddressGroup = null;
89     $scope.createNewFWAddressGroupWindow = function(){
90         $scope.editAddressGroup = null;
91         var modalInstance = $modal.open({
92                 backdrop: 'static', keyboard: false,
93             templateUrl : 'add_FWAddressGroup_popup.html',
94             controller: 'editFWAddressGroupController',
95             resolve: {
96                 message: function () {
97                     var message = {
98                         addressGroupDictionaryDatas: $scope.editAddressGroup
99                     };
100                     return message;
101                 }
102             }
103         });
104         modalInstance.result.then(function(response){
105             console.log('response', response);
106             $scope.addressGroupDictionaryDatas=response.addressGroupDictionaryDatas;
107         });
108     };
109
110     $scope.editFWAddressGroupWindow = function(addressGroupDictionaryData) {
111         $scope.editAddressGroup = addressGroupDictionaryData;
112         var modalInstance = $modal.open({
113                 backdrop: 'static', keyboard: false,
114             templateUrl : 'add_FWAddressGroup_popup.html',
115             controller: 'editFWAddressGroupController',
116             resolve: {
117                 message: function () {
118                     var message = {
119                         addressGroupDictionaryData: $scope.editAddressGroup
120                     };
121                     return message;
122                 }
123             }
124         });
125         modalInstance.result.then(function(response){
126             console.log('response', response);
127             $scope.addressGroupDictionaryDatas = response.addressGroupDictionaryDatas;
128         });
129     };
130
131     $scope.deleteFWAddressGroup = function(data) {
132         modalService.popupConfirmWin("Confirm","You are about to delete the Address Group  "+data.groupName+". Do you want to continue?",
133             function(){
134                 var uuu = "deleteDictionary/fw_dictionary/remove_AddressGroup";
135                 var postData={data: data};
136                 $.ajax({
137                     type : 'POST',
138                     url : uuu,
139                     dataType: 'json',
140                     contentType: 'application/json',
141                     data: JSON.stringify(postData),
142                     success : function(data){
143                         $scope.$apply(function(){$scope.addressGroupDictionaryDatas=data.addressGroupDictionaryDatas;});
144                     },
145                     error : function(data){
146                         console.log(data);
147                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
148                     }
149                 });
150
151             })
152     };
153 });