Fixed the Policy API issues and Bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / CLVnfTypeDictGridController.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 app.controller('vnfTypeDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_VNFTypeData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);
28         console.log($scope.vnfTypeDictionaryDatas);
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.vnfTypeDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.vnfTypeDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47         
48     $scope.vnfTypeDictionaryGrid = {
49         data : 'vnfTypeDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'VNFType.csv',
52         enableGridMenu: true,
53         enableSelectAll: true,
54         columnDefs: [{
55             field: 'id', enableFiltering: false, headerCellTemplate: '' +
56             '<button id=\'New\' ng-click="grid.appScope.createNewVnfTypeWindow()" class="btn btn-success">' + 'Create</button>',
57             cellTemplate:
58             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editVnfTypeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteVnfType(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60         },
61             { field: 'vnftype', displayName : 'VNF Type', sort: { direction: 'asc', priority: 0 }},
62             { field: 'description'},
63             {field: 'userCreatedBy.userName', displayName : 'Created By'},
64             {field: 'userModifiedBy.userName', displayName : 'Modified By'},
65             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' },
66             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
67         ],
68         exporterMenuPdf: false,
69         exporterPdfDefaultStyle: {fontSize: 9},
70         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
71         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
72         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
73         exporterPdfFooter: function ( currentPage, pageCount ) {
74          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
75         },
76         exporterPdfCustomFormatter: function ( docDefinition ) {
77          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
78          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
79          return docDefinition;
80         },
81         exporterPdfOrientation: 'portrait',
82         exporterPdfPageSize: 'LETTER',
83         exporterPdfMaxGridWidth: 500,
84         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
85         onRegisterApi: function(gridApi){
86                 $scope.gridApi = gridApi;
87         }
88     };
89
90     $scope.editVnfType = null;
91     $scope.createNewVnfTypeWindow = function(){
92         $scope.editVnfType = null;
93         var modalInstance = $modal.open({
94                 backdrop: 'static', keyboard: false,
95             templateUrl : 'add_vnfType_popup.html',
96             controller: 'editVnfTypeController',
97             resolve: {
98                 message: function () {
99                     var message = {
100                         vnfTypeDictionaryDatas: $scope.editVnfType
101                     };
102                     return message;
103                 }
104             }
105         });
106         modalInstance.result.then(function(response){
107             console.log('response', response);
108             $scope.vnfTypeDictionaryDatas=response.vnfTypeDictionaryDatas;
109         });
110     };
111
112     $scope.editVnfTypeWindow = function(vnfTypeDictionaryData) {
113         $scope.editVnfType = vnfTypeDictionaryData;
114         var modalInstance = $modal.open({
115                 backdrop: 'static', keyboard: false,
116             templateUrl : 'add_vnfType_popup.html',
117             controller: 'editVnfTypeController',
118             resolve: {
119                 message: function () {
120                     var message = {
121                         vnfTypeDictionaryData: $scope.editVnfType
122                     };
123                     return message;
124                 }
125             }
126         });
127         modalInstance.result.then(function(response){
128             console.log('response', response);
129             $scope.vnfTypeDictionaryDatas = response.vnfTypeDictionaryDatas;
130         });
131     };
132
133     $scope.deleteVnfType = function(data) {
134         var uuu = "searchDictionary";
135         var postData={data: data, type: "attribute"};
136         var searchString = "\n";
137         $.ajax({
138                 type : 'POST',
139                 url : uuu,
140                 dataType: 'json',
141                 contentType: 'application/json',
142                 data: JSON.stringify(postData),
143                 success : function(resultList){
144                         $scope.$apply(function(){
145                                 $scope.list =resultList.result;});
146                         $scope.searchData = JSON.stringify(resultList.result);
147                         $scope.searchDatas = JSON.parse($scope.searchData);        
148                         $scope.success = true;
149                         var i;
150                         if($scope.searchDatas.length > 0){
151                                 for(i = 0 ; i < $scope.searchDatas.length; i++){
152                                         searchString += $scope.searchDatas[i] + "\n";
153                                 }       
154                         }else{
155                                 searchString += "No Policies is Using this Value"
156                         }
157
158                         console.log($scope.list);
159                         if($scope.success){
160                                 modalService.popupConfirmWin("Confirm","You are about to delete the Vnf Type Dictionary Item  "+data.vnftype+". \n "+searchString+" \n Do you want to continue?",
161                                                 function(){
162                                         var uuu = "deleteDictionary/cl_dictionary/remove_vnfType";
163                                         var postData={data: data};
164                                         $.ajax({
165                                                 type : 'POST',
166                                                 url : uuu,
167                                                 dataType: 'json',
168                                                 contentType: 'application/json',
169                                                 data: JSON.stringify(postData),
170                                                 success : function(data){
171                                                         $scope.$apply(function(){$scope.vnfTypeDictionaryDatas=data.vnfTypeDictionaryDatas;});
172                                                 },
173                                                 error : function(data){
174                                                         console.log(data);
175                                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
176                                                 }
177                                         });
178
179                                 })}
180                 },
181                 error : function(data){
182                         alert("Error while Searching.");
183                 }
184         });
185     };
186 });