Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-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
21 /**
22  */
23 app.controller('vnfTypeDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){
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             CLDictionaryService.getVnfTypeDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);
37                 console.log($scope.vnfTypeDictionaryDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41             
42         });
43
44     $scope.vnfTypeDictionaryGrid = {
45         data : 'vnfTypeDictionaryDatas',
46         enableFiltering: true,
47         exporterCsvFilename: 'VNFType.csv',
48         enableGridMenu: true,
49         enableSelectAll: true,
50         columnDefs: [{
51             field: 'id', enableFiltering: false, headerCellTemplate: '' +
52             '<button id=\'New\' ng-click="grid.appScope.createNewVnfTypeWindow()" class="btn btn-success">' + 'Create</button>',
53             cellTemplate:
54             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editVnfTypeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
55             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteVnfType(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
56         },
57             { field: 'vnftype', displayName : 'VNF Type'},
58             { field: 'description'},
59             {field: 'userCreatedBy.userName', displayName : 'Created By'},
60             {field: 'userModifiedBy.userName', displayName : 'Modified By'},
61             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' },
62             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
63         ],
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.editVnfType = null;
86     $scope.createNewVnfTypeWindow = function(){
87         $scope.editVnfType = null;
88         var modalInstance = $modal.open({
89                 backdrop: 'static', keyboard: false,
90             templateUrl : 'add_vnfType_popup.html',
91             controller: 'editVnfTypeController',
92             resolve: {
93                 message: function () {
94                     var message = {
95                         vnfTypeDictionaryDatas: $scope.editVnfType
96                     };
97                     return message;
98                 }
99             }
100         });
101         modalInstance.result.then(function(response){
102             console.log('response', response);
103             $scope.vnfTypeDictionaryDatas=response.vnfTypeDictionaryDatas;
104         });
105     };
106
107     $scope.editVnfTypeWindow = function(vnfTypeDictionaryData) {
108         $scope.editVnfType = vnfTypeDictionaryData;
109         var modalInstance = $modal.open({
110                 backdrop: 'static', keyboard: false,
111             templateUrl : 'add_vnfType_popup.html',
112             controller: 'editVnfTypeController',
113             resolve: {
114                 message: function () {
115                     var message = {
116                         vnfTypeDictionaryData: $scope.editVnfType
117                     };
118                     return message;
119                 }
120             }
121         });
122         modalInstance.result.then(function(response){
123             console.log('response', response);
124             $scope.vnfTypeDictionaryDatas = response.vnfTypeDictionaryDatas;
125         });
126     };
127
128     $scope.deleteVnfType = function(data) {
129         var uuu = "searchDictionary.htm";
130         var postData={data: data, type: "attribute"};
131         var searchString = "\n";
132         $.ajax({
133                 type : 'POST',
134                 url : uuu,
135                 dataType: 'json',
136                 contentType: 'application/json',
137                 data: JSON.stringify(postData),
138                 success : function(resultList){
139                         $scope.$apply(function(){
140                                 $scope.list =resultList.result;});
141                         $scope.searchData = JSON.stringify(resultList.result);
142                         $scope.searchDatas = JSON.parse($scope.searchData);        
143                         $scope.success = true;
144                         var i;
145                         if($scope.searchDatas.length > 0){
146                                 for(i = 0 ; i < $scope.searchDatas.length; i++){
147                                         searchString += $scope.searchDatas[i].name + "\n";
148                                 }       
149                         }else{
150                                 searchString += "No Policies is Using this Value"
151                         }
152
153                         console.log($scope.list);
154                         if($scope.success){
155                                 modalService.popupConfirmWin("Confirm","You are about to delete the Vnf Type Dictionary Item  "+data.vnftype+". \n "+searchString+" \n Do you want to continue?",
156                                                 function(){
157                                         var uuu = papUrl + "/ecomp/cl_dictionary/remove_vnfType.htm";
158                                         var postData={data: data};
159                                         $.ajax({
160                                                 type : 'POST',
161                                                 url : uuu,
162                                                 dataType: 'json',
163                                                 contentType: 'application/json',
164                                                 data: JSON.stringify(postData),
165                                                 success : function(data){
166                                                         $scope.$apply(function(){$scope.vnfTypeDictionaryDatas=data.vnfTypeDictionaryDatas;});
167                                                 },
168                                                 error : function(data){
169                                                         console.log(data);
170                                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
171                                                 }
172                                         });
173
174                                 })}
175                 },
176                 error : function(data){
177                         alert("Error while Searching.");
178                 }
179         });
180     };
181 });