[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / EnforcerTypeDictGridController.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('enforcerDictGridController', function ($scope, PolicyAppService,modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_EnforcerTypeData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.enforcerDictionaryDatas = JSON.parse($scope.data.enforcerDictionaryDatas);
28         console.log($scope.enforcerDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32
33     $scope.enforcerDictionaryGrid = {
34         data : 'enforcerDictionaryDatas',
35         enableFiltering: true,
36         columnDefs: [{
37             field: 'id', enableFiltering: false, headerCellTemplate: '' +
38             '<button id=\'New\' ng-click="grid.appScope.createNewEnforcerTypeWindow()" class="btn btn-success">' + 'Create</button>',
39             cellTemplate:
40             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editEnforcerTypeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
41             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteEnforcerType(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
42         },{ field: 'enforcingType', displayName : 'Enforcing Type', sort: { direction: 'asc', priority: 0 }},
43             { field: 'script' , displayName : 'Script'},
44             {field: 'connectionQuery', displayName : 'Connection Query' },
45             {field: 'valueQuery', displayName : 'Value Query'}
46         ]
47     };
48
49     $scope.editEnforcerType = null;
50     $scope.createNewEnforcerTypeWindow = function(){
51         $scope.editEnforcerType = null;
52         var modalInstance = $modal.open({
53                 backdrop: 'static', keyboard: false,
54             templateUrl : 'add_EnforcerType_popup.html',
55             controller: 'editEnforcerTypeController',
56             resolve: {
57                 message: function () {
58                     var message = {
59                         enforcerDictionaryDatas: $scope.editEnforcerType
60                     };
61                     return message;
62                 }
63             }
64         });
65         modalInstance.result.then(function(response){
66             console.log('response', response);
67             $scope.enforcerDictionaryDatas=response.enforcerDictionaryDatas;
68         });
69     };
70
71     $scope.editEnforcerTypeWindow = function(enforcerDictionaryData) {
72         $scope.editEnforcerType = enforcerDictionaryData;
73         var modalInstance = $modal.open({
74                 backdrop: 'static', keyboard: false,
75             templateUrl : 'add_EnforcerType_popup.html',
76             controller: 'editEnforcerTypeController',
77             resolve: {
78                 message: function () {
79                     var message = {
80                         enforcerDictionaryData: $scope.editEnforcerType
81                     };
82                     return message;
83                 }
84             }
85         });
86         modalInstance.result.then(function(response){
87             console.log('response', response);
88             $scope.enforcerDictionaryDatas = response.enforcerDictionaryDatas;
89         });
90     };
91
92     $scope.deleteEnforcerType = function(data) {
93         modalService.popupConfirmWin("Confirm","You are about to delete the Enforcing Type  "+data.enforcingType+". Do you want to continue?",
94             function(){
95                 var uuu = "deleteDictionary/enforcer_dictionary/remove_enforcer";
96                 var postData={data: data};
97                 $.ajax({
98                     type : 'POST',
99                     url : uuu,
100                     dataType: 'json',
101                     contentType: 'application/json',
102                     data: JSON.stringify(postData),
103                     success : function(data){
104                         $scope.$apply(function(){$scope.enforcerDictionaryDatas=data.enforcerDictionaryDatas;});
105                     },
106                     error : function(data){
107                         console.log(data);
108                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
109                     }
110                 });
111
112             })
113     };
114 });