[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / RiskTypeDictGridController.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('riskTypeDictGridController', function ($scope, PolicyAppService, modalService, $modal, uiGridConstants,Grid){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_RiskTypeData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
28         console.log($scope.riskTypeDictionaryDatas);
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.riskTypeDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.riskTypeDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47     
48     $scope.riskTypeDictionaryGrid = {
49         data : 'riskTypeDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'RiskType.csv',
52         enableGridMenu: true,
53         enableSelectAll: true,
54         columnDefs: [{
55             field: 'id', enableFiltering: false, headerCellTemplate: '' +
56             '<button id=\'New\' ng-click="grid.appScope.createNewRiskType()" class="btn btn-success">' + 'Create</button>',
57             cellTemplate:
58             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editRiskTypeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteRiskType(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60         },
61             { field: 'riskName', displayName : 'Risk Type Name', sort: { direction: 'asc', priority: 0 } },
62             { field: 'description', width: '20%' },
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         enableColumnResize : true,
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         exporterFieldCallback: function(grid, row, col, input) {
82                         if( col.name == 'createdDate' || col.name == 'modifiedDate') {
83                                 var date = new Date(input);
84                                 return date.toString("yyyy-MM-dd HH:MM:ss a");
85                         } else {
86                                 return input;
87                         }
88                 },
89         exporterPdfOrientation: 'portrait',
90         exporterPdfPageSize: 'LETTER',
91         exporterPdfMaxGridWidth: 500,
92         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
93         onRegisterApi: function(gridApi){
94                 $scope.gridApi = gridApi;
95         }
96     };
97
98
99     $scope.editRiskType = null;
100     $scope.createNewRiskType = function(){
101         $scope.editRiskType = null;
102         var modalInstance = $modal.open({
103                 backdrop: 'static', keyboard: false,
104             templateUrl : 'add_riskType_popup.html',
105             controller: 'editRiskTypeController',
106             resolve: {
107                 message: function () {
108                     var message = {
109                         riskTypeDictionaryDatas: $scope.editRiskType
110                     };
111                     return message;
112                 }
113             }
114         });
115         modalInstance.result.then(function(response){
116             console.log('response', response);
117             $scope.riskTypeDictionaryDatas=response.riskTypeDictionaryDatas;
118         });
119     };
120
121     $scope.editRiskTypeWindow = function(riskTypeDictionaryData) {
122         $scope.editRiskType = riskTypeDictionaryData;
123         var modalInstance = $modal.open({
124                 backdrop: 'static', keyboard: false,
125             templateUrl : 'add_riskType_popup.html',
126             controller: 'editRiskTypeController',
127             resolve: {
128                 message: function () {
129                     var message = {
130                         riskTypeDictionaryData: $scope.editRiskType
131                     };
132                     return message;
133                 }
134             }
135         });
136         modalInstance.result.then(function(response){
137             console.log('response', response);
138             $scope.riskTypeDictionaryDatas = response.riskTypeDictionaryData;
139         });
140     };
141
142     $scope.deleteRiskType = function(data) {
143         modalService.popupConfirmWin("Confirm","You are about to delete the Onap Name  "+data.riskType+". Do you want to continue?",
144             function(){
145                 var uuu = "deleteDictionary/sp_dictionary/remove_riskType";
146                 var postData={data: data};
147                 $.ajax({
148                     type : 'POST',
149                     url : uuu,
150                     dataType: 'json',
151                     contentType: 'application/json',
152                     data: JSON.stringify(postData),
153                     success : function(data){
154                         $scope.$apply(function(){$scope.riskTypeDictionaryDatas=data.riskTypeDictionaryDatas;});
155                     },
156                     error : function(data){
157                         console.log(data);
158                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
159                     }
160                 });
161
162             })
163     };
164
165 });