[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWServiceGroupDictGridController.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('serviceGroupDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_ServiceGroupData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas);
28         console.log($scope.serviceGroupDictionaryDatas);
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.serviceGroupDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.serviceGroupDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47
48     $scope.serviceGroupDictionaryGrid = {
49         data : 'serviceGroupDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'ServiceGroup.csv',
52         enableGridMenu: true,
53         enableSelectAll: true,
54         columnDefs: [{
55             field: 'id', enableFiltering: false, headerCellTemplate: '' +
56             '<button id=\'New\' ng-click="grid.appScope.createNewFWServiceGroupWindow()" class="btn btn-success">' + 'Create</button>',
57             cellTemplate:
58             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWServiceGroupWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWServiceGroup(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60         },{ field: 'groupName', displayName : 'Group Name', sort: { direction: 'asc', priority: 0 }},
61             { field: 'serviceList', displayName : 'Service List' }
62         ],
63         exporterMenuPdf: false,
64         exporterPdfDefaultStyle: {fontSize: 9},
65         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
66         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
67         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
68         exporterPdfFooter: function ( currentPage, pageCount ) {
69          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
70         },
71         exporterPdfCustomFormatter: function ( docDefinition ) {
72          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
73          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
74          return docDefinition;
75         },
76         exporterPdfOrientation: 'portrait',
77         exporterPdfPageSize: 'LETTER',
78         exporterPdfMaxGridWidth: 500,
79         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
80         onRegisterApi: function(gridApi){
81                 $scope.gridApi = gridApi;
82         }
83     };
84
85     $scope.editServiceGroup = null;
86     $scope.createNewFWServiceGroupWindow = function(){
87         $scope.editServiceGroup = null;
88         var modalInstance = $modal.open({
89                 backdrop: 'static', keyboard: false,
90             templateUrl : 'add_fwServiceGroup_popup.html',
91             controller: 'editFWServiceGroupController',
92             resolve: {
93                 message: function () {
94                     var message = {
95                         serviceGroupDictionaryDatas: $scope.editServiceGroup
96                     };
97                     return message;
98                 }
99             }
100         });
101         modalInstance.result.then(function(response){
102             console.log('response', response);
103             $scope.serviceGroupDictionaryDatas=response.serviceGroupDictionaryDatas;
104         });
105     };
106
107     $scope.editFWServiceGroupWindow = function(serviceGroupDictionaryData) {
108         $scope.editServiceGroup = serviceGroupDictionaryData;
109         var modalInstance = $modal.open({
110                 backdrop: 'static', keyboard: false,
111             templateUrl : 'add_fwServiceGroup_popup.html',
112             controller: 'editFWServiceGroupController',
113             resolve: {
114                 message: function () {
115                     var message = {
116                         serviceGroupDictionaryData: $scope.editServiceGroup
117                     };
118                     return message;
119                 }
120             }
121         });
122         modalInstance.result.then(function(response){
123             console.log('response', response);
124             $scope.serviceGroupDictionaryDatas = response.serviceGroupDictionaryDatas;
125         });
126     };
127
128     $scope.deleteFWServiceGroup = function(data) {
129         modalService.popupConfirmWin("Confirm","You are about to delete the Service Group:  "+data.groupName+". Do you want to continue?",
130             function(){
131                 var uuu = "deleteDictionary/fw_dictionary/remove_serviceGroup";
132                 var postData={data: data};
133                 $.ajax({
134                     type : 'POST',
135                     url : uuu,
136                     dataType: 'json',
137                     contentType: 'application/json',
138                     data: JSON.stringify(postData),
139                     success : function(data){
140                         $scope.$apply(function(){$scope.serviceGroupDictionaryDatas=data.serviceGroupDictionaryDatas;});
141                     },
142                     error : function(data){
143                         console.log(data);
144                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
145                     }
146                 });
147
148             })
149     };
150
151 });