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