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