Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / SafePolicyWarningDictGridController.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('safePolicyWarningDictGridController', function ($scope, SafePolicyService,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                 SafePolicyService.getSafePolicyWarningDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.safePolicyWarningDatas = JSON.parse($scope.data.safePolicyWarningDatas);
37                 console.log($scope.safePolicyWarningDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41                 
42         });
43         
44     $scope.safePolicyWarningDictionaryGrid = {
45         data : 'safePolicyWarningDatas',
46         enableFiltering: true,
47         columnDefs: [{
48             field: 'id', enableFiltering: false, headerCellTemplate: '' +
49             '<button id=\'New\' ng-click="grid.appScope.createNewSafePolicyWarningWindow()" class="btn btn-success">' + 'Create</button>',
50             cellTemplate:
51             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editSafePolicyWarningWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
52             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteSafePolicyWarning(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
53         },{ field: 'name', displayName : 'Safe Policy Warning Name'},
54         { field: 'riskType', displayName : 'Risk Type'},{ field: 'message', displayName : 'Message'}
55         ],
56         onRegisterApi: function(gridApi){
57                 $scope.gridApi = gridApi;
58                 $scope.gridApi.core.refresh();
59         }
60     };
61    
62     $scope.editSafePolicyWarning = null;
63     $scope.createNewSafePolicyWarningWindow = function(){
64         $scope.editSafePolicyWarning = null;
65         var modalInstance = $modal.open({
66                 backdrop: 'static', keyboard: false,
67             templateUrl : 'add_SafePolicyWarning_popup.html',
68             controller: 'editSafePolicyWarningController',
69             resolve: {
70                 message: function () {
71                     var message = {
72                                 safePolicyWarningDatas: $scope.editSafePolicyWarningScope
73                     };
74                     return message;
75                 }
76             }
77         });
78         modalInstance.result.then(function(response){
79             console.log('response', response);
80             $scope.safePolicyWarningDatas=response.safePolicyWarningDatas;
81         });
82     };
83
84     $scope.editSafePolicyWarningWindow = function(safePolicyWarningData) {
85         $scope.editSafePolicyWarning = safePolicyWarningData;
86         var modalInstance = $modal.open({
87                 backdrop: 'static', keyboard: false,
88             templateUrl : 'add_SafePolicyWarning_popup.html',
89             controller: 'editSafePolicyWarningController',
90             resolve: {
91                 message: function () {
92                     var message = {
93                                 safePolicyWarningData: $scope.editSafePolicyWarning
94                     };
95                     return message;
96                 }
97             }
98         });
99         modalInstance.result.then(function(response){
100             console.log('response', response);
101             $scope.groupPolicyScopeListDatas = response.safePolicyWarningData;
102         });
103     };
104
105     $scope.deleteSafePolicyWarning = function(data) {
106         modalService.popupConfirmWin("Confirm","You are about to delete the Safe Policy Warning  "+data.name+". Do you want to continue?",
107             function(){
108                 var uuu = papUrl + "/ecomp/sp_dictionary/remove_SafePolicyWarning.htm";
109                 var postData={data: data};
110                 $.ajax({
111                     type : 'POST',
112                     url : uuu,
113                     dataType: 'json',
114                     contentType: 'application/json',
115                     data: JSON.stringify(postData),
116                     success : function(data){
117                         $scope.$apply(function(){$scope.safePolicyWarningDatas=data.safePolicyWarningDatas;});
118                     },
119                     error : function(data){
120                         console.log(data);
121                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
122                     }
123                 });
124
125             })
126     };
127 });