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