Resolved the Policy GUI Javascript issues
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWTagPickerListDictGridController.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('tagPickerListDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_TagPickerListData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
28         console.log($scope.fwTagPickerDictionaryDatas);
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.tagPickerListDictionaryGrid.columnDefs[0].visible = false;
39                 $scope.gridApi.grid.refresh();
40         }else{
41                 $scope.tagPickerListDictionaryGrid.columnDefs[0].visible = true;
42                 $scope.gridApi.grid.refresh();
43         }
44     },function(error){
45         console.log("failed");
46     });
47         
48     $scope.tagPickerListDictionaryGrid = {
49         data : 'fwTagPickerDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'SearchCriteria.csv',
52         enableSelectAll: true,
53         columnDefs: [{
54             field: 'id', enableFiltering: false, headerCellTemplate: '' +
55             '<button id=\'New\' ng-click="grid.appScope.createNewFWTagPickerWindow()" class="btn btn-success">' + 'Create</button>',
56             cellTemplate:
57             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWTagPickerWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
58             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWTagPicker(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
59         },{ field: 'tagPickerName', displayName : 'Tag Picker Name', sort: { direction: 'asc', priority: 0 }},
60             { field: 'tagValues', displayName : 'Select Tags' },
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         exporterPdfDefaultStyle: {fontSize: 9},
68         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
69         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
70         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
71         exporterPdfFooter: function ( currentPage, pageCount ) {
72          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
73         },
74         exporterPdfCustomFormatter: function ( docDefinition ) {
75          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
76          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
77          return docDefinition;
78         },
79         exporterMenuPdf: false,
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.editFWTagPicker = null;
90     $scope.createNewFWTagPickerWindow = function(){
91         $scope.editFWTagPicker = null;
92         var modalInstance = $modal.open({
93                 backdrop: 'static', keyboard: false,
94             templateUrl : 'add_fwTagPicker_popup.html',
95             controller: 'editFWTagPickerController',
96             resolve: {
97                 message: function () {
98                     var message = {
99                         fwTagPickerDictionaryDatas: $scope.editFWTagPicker
100                     };
101                     return message;
102                 }
103             }
104         });
105         modalInstance.result.then(function(response){
106             console.log('response', response);
107             $scope.fwTagPickerDictionaryDatas=response.fwTagPickerDictionaryDatas;
108         });
109     };
110
111     $scope.editFWTagPickerWindow = function(fwTagPickerDictionaryData) {
112         $scope.editFWTagPicker = fwTagPickerDictionaryData;
113         var modalInstance = $modal.open({
114                 backdrop: 'static', keyboard: false,
115             templateUrl : 'add_fwTagPicker_popup.html',
116             controller: 'editFWTagPickerController',
117             resolve: {
118                 message: function () {
119                     var message = {
120                         fwTagPickerDictionaryData: $scope.editFWTagPicker
121                     };
122                     return message;
123                 }
124             }
125         });
126         modalInstance.result.then(function(response){
127             console.log('response', response);
128             $scope.fwTagPickerDictionaryDatas = response.fwTagPickerDictionaryDatas;
129         });
130     };
131
132     $scope.deleteFWTagPicker = function(data) {
133         modalService.popupConfirmWin("Confirm","You are about to delete the TagPicker:   "+data.tagPickerName +". Do you want to continue?",
134             function(){
135                 var uuu = "deleteDictionary/fw_dictionary/remove_tagPicker";
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.fwTagPickerDictionaryDatas=data.fwTagPickerDictionaryDatas;});
145                     },
146                     error : function(data){
147                         console.log(data);
148                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
149                     }
150                 });
151
152             })
153     };
154 });