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