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