Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / actionPolicyDictGridController.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 var Actiontype = ["REST"];
21 app.controller('actionPolicyDictGridController', function ($scope,modalService, $modal, uiGridConstants,Grid, PolicyAppService){
22         $( "#dialog" ).hide();
23         $scope.type = Actiontype;
24
25         PolicyAppService.getData('getDictionary/get_ActionPolicyDictData').then(function (data) {
26                 var j = data;
27                 $scope.data = JSON.parse(j.data);
28                 console.log($scope.data);
29                 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
30                 console.log($scope.actionPolicyDictionaryDatas);
31         }, function (error) {
32                 console.log("failed");
33         });
34
35
36         PolicyAppService.getData('get_LockDownData').then(function(data){
37                 var j = data;
38                 $scope.data = JSON.parse(j.data);
39                 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
40                 if($scope.lockdowndata[0].lockdown == true){
41                         $scope.actionPolicyDictionaryGrid.columnDefs[0].visible = false;
42                         $scope.gridApi.grid.refresh();
43                 }else{
44                         $scope.actionPolicyDictionaryGrid.columnDefs[0].visible = true;
45                         $scope.gridApi.grid.refresh();
46                 }
47         },function(error){
48                 console.log("failed");
49         });
50
51         $scope.actionPolicyDictionaryGrid = {
52                         enableFiltering: true,
53                         data: 'actionPolicyDictionaryDatas',
54                         exporterCsvFilename: 'ActionPolicyDictionary.csv',
55                         enableGridMenu: true,
56                         enableSelectAll: true,
57                         columnDefs: [{
58                                 field: 'id',
59                                 enableFiltering: false,
60                                 headerCellTemplate: '' +
61                                 '<button id=\'New\' ng-click="grid.appScope.createNewActionPolicyDictWindow()" class="btn btn-success">' + 'Create</button>',
62                                 cellTemplate: '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editActionPolicyDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
63                                 '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteActionPolicyDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',
64                                 width: '8%'
65                         },
66                         {field: 'attributeName', displayName: 'Attribute Name', sort: { direction: 'asc', priority: 0 }},
67                         {field: 'type'},
68                         {field: 'url'},
69                         {field: 'method'},
70                         {field: 'header', displayName: 'Headers'},
71                         {field: 'description'},
72                         {field: 'userCreatedBy.userName', displayName: 'Created By'},
73                         {field: 'userModifiedBy.userName', displayName: 'Modified By'},
74                         {field: 'createdDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
75                         {field: 'modifiedDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
76                         ],
77                         exporterMenuPdf: false,
78                         exporterPdfDefaultStyle: {fontSize: 9},
79                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
80                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
81                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
82                         exporterPdfFooter: function ( currentPage, pageCount ) {
83                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
84                         },
85                         exporterPdfCustomFormatter: function ( docDefinition ) {
86                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
87                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
88                                 return docDefinition;
89                         },
90                         exporterPdfOrientation: 'portrait',
91                         exporterPdfPageSize: 'LETTER',
92                         exporterPdfMaxGridWidth: 500,
93                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
94                         onRegisterApi: function(gridApi){
95                                 $scope.gridApi = gridApi;
96                         }
97         };
98
99
100         $scope.editActionPolicyName = null;
101         $scope.createNewActionPolicyDictWindow = function () {
102                 $scope.editActionPolicyName = null;
103                 var modalInstance = $modal.open({
104                         backdrop: 'static', keyboard: false,
105                         templateUrl: 'add_actionPolicyDict_popup.html',
106                         controller: 'editActionPolicyDictController',
107                         resolve: {
108                                 message: function () {
109                                         var message = {
110                                                         actionPolicyDictionaryDatas: $scope.editActionPolicyName
111                                         };
112                                         return message;
113                                 }
114                         }
115                 });
116                 modalInstance.result.then(function (response) {
117                         console.log('response', response);
118                         $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
119                 });
120         };
121
122         $scope.editActionPolicyDictWindow = function (actionPolicyDictionaryData) {
123                 $scope.editActionPolicyName = actionPolicyDictionaryData;
124                 var modalInstance = $modal.open({
125                         backdrop: 'static', keyboard: false,
126                         templateUrl: 'add_actionPolicyDict_popup.html',
127                         controller: 'editActionPolicyDictController',
128                         resolve: {
129                                 message: function () {
130                                         var message = {
131                                                         actionPolicyDictionaryData: $scope.editActionPolicyName
132                                         };
133                                         return message;
134                                 }
135                         }
136                 });
137                 modalInstance.result.then(function (response) {
138                         console.log('response', response);
139                         $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
140                 });
141         };
142
143         $scope.deleteActionPolicyDict = function (data) {
144                 modalService.popupConfirmWin("Confirm", "You are about to delete the Action Policy Dictionary Item  " + data.attributeName + ". Do you want to continue?",
145                                 function () {
146                         var uuu = "deleteDictionary/action_dictionary/remove_actionPolicyDict";
147                         var postData = {data: data};
148                         $.ajax({
149                                 type: 'POST',
150                                 url: uuu,
151                                 dataType: 'json',
152                                 contentType: 'application/json',
153                                 data: JSON.stringify(postData),
154                                 success: function (data) {
155                                         $scope.$apply(function () {
156                                                 $scope.actionPolicyDictionaryDatas = data.actionPolicyDictionaryDatas;
157                                         });
158                                 },
159                                 error: function (data) {
160                                         console.log(data);
161                                         modalService.showFailure("Fail", "Error while deleting: " + data.responseText);
162                                 }
163                         });
164
165                 })
166         };
167 });