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