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