[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / PSGroupPolicyScopeDictGridController.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('psGroupPolicyScopeDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_GroupPolicyScopeData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
28         console.log($scope.groupPolicyScopeListDatas);
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.psGroupPolicyScopeDictionaryGrid.columnDefs[0].visible = false;
39                 $scope.gridApi.grid.refresh();
40         }else{
41                 $scope.psGroupPolicyScopeDictionaryGrid.columnDefs[0].visible = true;
42                 $scope.gridApi.grid.refresh();
43         }
44     },function(error){
45         console.log("failed");
46     });
47         
48     $scope.psGroupPolicyScopeDictionaryGrid = {
49         data : 'groupPolicyScopeListDatas',
50         enableFiltering: true,
51         columnDefs: [{
52             field: 'id', enableFiltering: false, headerCellTemplate: '' +
53             '<button id=\'New\' ng-click="grid.appScope.createNewGroupPolicyScopeWindow()" class="btn btn-success">' + 'Create</button>',
54             cellTemplate:
55             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editGroupPolicyScopeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
56             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteGroupPolicyScope(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
57         },{ field: 'groupName', displayName : 'Policy Scope Group Name', sort: { direction: 'asc', priority: 0 }},
58         { field: 'groupList', displayName : 'Policy Scope List'}
59         ],
60         onRegisterApi: function(gridApi){
61                 $scope.gridApi = gridApi;
62                 $scope.gridApi.core.refresh();
63         }
64     };
65    
66     $scope.editPSGroupPolicyScope = null;
67     $scope.createNewGroupPolicyScopeWindow = function(){
68         $scope.editPSGroupPolicyScope = null;
69         var modalInstance = $modal.open({
70                 backdrop: 'static', keyboard: false,
71             templateUrl : 'add_PSGroupPolicyScope_popup.html',
72             controller: 'editPSGroupPolicyScopeController',
73             resolve: {
74                 message: function () {
75                     var message = {
76                                 groupPolicyScopeListDatas: $scope.editPSGroupPolicyScope
77                     };
78                     return message;
79                 }
80             }
81         });
82         modalInstance.result.then(function(response){
83             console.log('response', response);
84             $scope.groupPolicyScopeListDatas=response.groupPolicyScopeListDatas;
85         });
86     };
87
88     $scope.editGroupPolicyScopeWindow = function(groupPolicyScopeListData) {
89         $scope.editPSGroupPolicyScope = groupPolicyScopeListData;
90         var modalInstance = $modal.open({
91                 backdrop: 'static', keyboard: false,
92             templateUrl : 'add_PSGroupPolicyScope_popup.html',
93             controller: 'editPSGroupPolicyScopeController',
94             resolve: {
95                 message: function () {
96                     var message = {
97                                 groupPolicyScopeListData: $scope.editPSGroupPolicyScope
98                     };
99                     return message;
100                 }
101             }
102         });
103         modalInstance.result.then(function(response){
104             console.log('response', response);
105             $scope.groupPolicyScopeListDatas = response.groupPolicyScopeListDatas;
106         });
107     };
108
109     $scope.deleteGroupPolicyScope = function(data) {
110         modalService.popupConfirmWin("Confirm","You are about to delete the Group Policy Scope  "+data.name+". Do you want to continue?",
111             function(){
112                 var uuu = "deleteDictionary/ps_dictionary/remove_GroupPolicyScope";
113                 var postData={data: data};
114                 $.ajax({
115                     type : 'POST',
116                     url : uuu,
117                     dataType: 'json',
118                     contentType: 'application/json',
119                     data: JSON.stringify(postData),
120                     success : function(data){
121                         $scope.$apply(function(){$scope.groupPolicyScopeListDatas=data.groupPolicyScopeListDatas;});
122                     },
123                     error : function(data){
124                         console.log(data);
125                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
126                     }
127                 });
128
129             })
130     };
131 });