Resolved the Policy GUI Javascript issues
[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         enableSelectAll: true,
52         columnDefs: [{
53             field: 'id', enableFiltering: false, headerCellTemplate: '' +
54             '<button id=\'New\' ng-click="grid.appScope.createNewRiskType()" class="btn btn-success">' + 'Create</button>',
55             cellTemplate:
56             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editRiskTypeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
57             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteRiskType(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
58         },
59             { field: 'riskName', displayName : 'Risk Type Name', sort: { direction: 'asc', priority: 0 } },
60             { field: 'description', width: '20%' },
61             {field: 'userCreatedBy.userName', displayName : 'Created By'},
62             {field: 'userModifiedBy.userName', displayName : 'Modified By' },
63             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
64             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
65         ],
66         enableColumnResize : true,
67         onRegisterApi: function(gridApi){
68                 $scope.gridApi = gridApi;
69                 $scope.gridApi.core.refresh();
70         }
71     };
72
73     $scope.editRiskType = null;
74     $scope.createNewRiskType = function(){
75         $scope.editRiskType = null;
76         var modalInstance = $modal.open({
77                 backdrop: 'static', keyboard: false,
78             templateUrl : 'add_riskType_popup.html',
79             controller: 'editRiskTypeController',
80             resolve: {
81                 message: function () {
82                     var message = {
83                         riskTypeDictionaryDatas: $scope.editRiskType
84                     };
85                     return message;
86                 }
87             }
88         });
89         modalInstance.result.then(function(response){
90             console.log('response', response);
91             $scope.riskTypeDictionaryDatas=response.riskTypeDictionaryDatas;
92         });
93     };
94
95     $scope.editRiskTypeWindow = function(riskTypeDictionaryData) {
96         $scope.editRiskType = riskTypeDictionaryData;
97         var modalInstance = $modal.open({
98                 backdrop: 'static', keyboard: false,
99             templateUrl : 'add_riskType_popup.html',
100             controller: 'editRiskTypeController',
101             resolve: {
102                 message: function () {
103                     var message = {
104                         riskTypeDictionaryData: $scope.editRiskType
105                     };
106                     return message;
107                 }
108             }
109         });
110         modalInstance.result.then(function(response){
111             console.log('response', response);
112             $scope.riskTypeDictionaryDatas = response.riskTypeDictionaryData;
113         });
114     };
115
116     $scope.deleteRiskType = function(data) {
117         modalService.popupConfirmWin("Confirm","You are about to delete the Onap Name  "+data.riskType+". Do you want to continue?",
118             function(){
119                 var uuu = "deleteDictionary/sp_dictionary/remove_riskType";
120                 var postData={data: data};
121                 $.ajax({
122                     type : 'POST',
123                     url : uuu,
124                     dataType: 'json',
125                     contentType: 'application/json',
126                     data: JSON.stringify(postData),
127                     success : function(data){
128                         $scope.$apply(function(){$scope.riskTypeDictionaryDatas=data.riskTypeDictionaryDatas;});
129                     },
130                     error : function(data){
131                         console.log(data);
132                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
133                     }
134                 });
135
136             })
137     };
138
139 });