[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / CLPepOptionsDictGridController.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('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                         exporterFieldCallback: function(grid, row, col, input) {
84                                 if( col.name == 'createdDate' || col.name == 'modifiedDate') {
85                                         var date = new Date(input);
86                                         return date.toString("yyyy-MM-dd HH:MM:ss a");
87                                 } else {
88                                         return input;
89                                 }
90                         },
91                         exporterPdfOrientation: 'portrait',
92                         exporterPdfPageSize: 'LETTER',
93                         exporterPdfMaxGridWidth: 500,
94                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
95                         onRegisterApi: function(gridApi){
96                                 $scope.gridApi = gridApi;
97                         }
98         };
99
100         $scope.editPEPOptions = null;
101         $scope.createNewPEPOptionsWindow = function(){
102                 $scope.editOnapName = null;
103                 var modalInstance = $modal.open({
104                         backdrop: 'static', keyboard: false,
105                         templateUrl : 'add_PEPOptions_popup.html',
106                         controller: 'editPEPOptionsController',
107                         resolve: {
108                                 message: function () {
109                                         var message = {
110                                                         pepOptionsDictionaryDatas: $scope.editPEPOptions
111                                         };
112                                         return message;
113                                 }
114                         }
115                 });
116                 modalInstance.result.then(function(response){
117                         console.log('response', response);
118                         $scope.pepOptionsDictionaryDatas=response.pepOptionsDictionaryDatas;
119                 });
120         };
121
122         $scope.editPEPOptionsWindow = function(pepOptionsDictionaryData) {
123                 $scope.editPEPOptions = pepOptionsDictionaryData;
124                 var modalInstance = $modal.open({
125                         backdrop: 'static', keyboard: false,
126                         templateUrl : 'add_PEPOptions_popup.html',
127                         controller: 'editPEPOptionsController',
128                         resolve: {
129                                 message: function () {
130                                         var message = {
131                                                         pepOptionsDictionaryData: $scope.editPEPOptions
132                                         };
133                                         return message;
134                                 }
135                         }
136                 });
137                 modalInstance.result.then(function(response){
138                         console.log('response', response);
139                         $scope.pepOptionsDictionaryDatas = response.pepOptionsDictionaryDatas;
140                 });
141         };
142
143         $scope.deletePEPOptions = function(data) {
144                 var uuu = "searchDictionary";
145                 var postData={data: data, type: "pepOptions"};
146                 var searchString = "\n";
147                 $.ajax({
148                         type : 'POST',
149                         url : uuu,
150                         dataType: 'json',
151                         contentType: 'application/json',
152                         data: JSON.stringify(postData),
153                         success : function(resultList){
154                                 $scope.$apply(function(){
155                                         $scope.list =resultList.result;});
156                                 $scope.searchData = JSON.stringify(resultList.result);
157                                 $scope.searchDatas = JSON.parse($scope.searchData);        
158                                 $scope.success = true;
159                                 var i;
160                                 if($scope.searchDatas.length > 0){
161                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
162                                                 searchString += $scope.searchDatas[i] + "\n";
163                                         }       
164                                 }else{
165                                         searchString += "No Policies is Using this Value"
166                                 }
167
168                                 console.log($scope.list);
169                                 if($scope.success){
170                                         modalService.popupConfirmWin("Confirm","You are about to delete the PEP Options :  "+data.pepName+". \n "+searchString+" \n  Do you want to continue?",
171                                                         function(){
172                                                 var uuu = "deleteDictionary/cl_dictionary/remove_pepOptions";
173                                                 var postData={data: data};
174                                                 $.ajax({
175                                                         type : 'POST',
176                                                         url : uuu,
177                                                         dataType: 'json',
178                                                         contentType: 'application/json',
179                                                         data: JSON.stringify(postData),
180                                                         success : function(data){
181                                                                 $scope.$apply(function(){$scope.pepOptionsDictionaryDatas=data.pepOptionsDictionaryDatas;});
182                                                         },
183                                                         error : function(data){
184                                                                 console.log(data);
185                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
186                                                         }
187                                                 });
188
189                                         })}
190                         },
191                         error : function(data){
192                                 alert("Error while Searching.");
193                         }
194                 });
195         };
196
197 });