Resolved the Policy GUI Javascript issues
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / actionPolicyDictGridController.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 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: 'body', visible : false},
72                         {field: 'description'},
73                         {field: 'userCreatedBy.userName', displayName: 'Created By'},
74                         {field: 'userModifiedBy.userName', displayName: 'Modified By'},
75                         {field: 'createdDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
76                         {field: 'modifiedDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
77                         ],
78                         exporterMenuPdf: false,
79                         exporterPdfDefaultStyle: {fontSize: 9},
80                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
81                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
82                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
83                         exporterPdfFooter: function ( currentPage, pageCount ) {
84                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
85                         },
86                         exporterPdfCustomFormatter: function ( docDefinition ) {
87                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
88                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
89                                 return docDefinition;
90                         },
91                         exporterFieldCallback: function(grid, row, col, input) {
92                          if( col.name == 'createdDate' || col.name == 'modifiedDate') {
93                                  var date = new Date(input);
94                                  return date.toString("yyyy-MM-dd HH:MM:ss a");
95                          } else {
96                                  return input;
97                          }
98                     },
99                         exporterPdfOrientation: 'portrait',
100                         exporterPdfPageSize: 'LETTER',
101                         exporterPdfMaxGridWidth: 500,
102                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
103                         onRegisterApi: function(gridApi){
104                                 $scope.gridApi = gridApi;
105                         }
106         };
107
108
109         $scope.editActionPolicyName = null;
110         $scope.createNewActionPolicyDictWindow = function () {
111                 $scope.editActionPolicyName = null;
112                 var modalInstance = $modal.open({
113                         backdrop: 'static', keyboard: false,
114                         templateUrl: 'add_actionPolicyDict_popup.html',
115                         controller: 'editActionPolicyDictController',
116                         resolve: {
117                                 message: function () {
118                                         var message = {
119                                                         actionPolicyDictionaryDatas: $scope.editActionPolicyName
120                                         };
121                                         return message;
122                                 }
123                         }
124                 });
125                 modalInstance.result.then(function (response) {
126                         console.log('response', response);
127                         $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
128                 });
129         };
130
131         $scope.editActionPolicyDictWindow = function (actionPolicyDictionaryData) {
132                 $scope.editActionPolicyName = actionPolicyDictionaryData;
133                 var modalInstance = $modal.open({
134                         backdrop: 'static', keyboard: false,
135                         templateUrl: 'add_actionPolicyDict_popup.html',
136                         controller: 'editActionPolicyDictController',
137                         resolve: {
138                                 message: function () {
139                                         var message = {
140                                                         actionPolicyDictionaryData: $scope.editActionPolicyName
141                                         };
142                                         return message;
143                                 }
144                         }
145                 });
146                 modalInstance.result.then(function (response) {
147                         console.log('response', response);
148                         $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
149                 });
150         };
151
152         $scope.deleteActionPolicyDict = function (data) {
153                 modalService.popupConfirmWin("Confirm", "You are about to delete the Action Policy Dictionary Item  " + data.attributeName + ". Do you want to continue?",
154                                 function () {
155                         var uuu = "deleteDictionary/action_dictionary/remove_actionPolicyDict";
156                         var postData = {data: data};
157                         $.ajax({
158                                 type: 'POST',
159                                 url: uuu,
160                                 dataType: 'json',
161                                 contentType: 'application/json',
162                                 data: JSON.stringify(postData),
163                                 success: function (data) {
164                                         $scope.$apply(function () {
165                                                 $scope.actionPolicyDictionaryDatas = data.actionPolicyDictionaryDatas;
166                                         });
167                                 },
168                                 error: function (data) {
169                                         console.log(data);
170                                         modalService.showFailure("Fail", "Error while deleting: " + data.responseText);
171                                 }
172                         });
173
174                 })
175         };
176 });