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