Policy TestSuite Enabled
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / ecompNameDictGridController.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 app.controller('ecompNameDictGridController', function ($scope, PolicyAppService, modalService, $modal, uiGridConstants,Grid){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_EcompNameData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
28         console.log($scope.ecompNameDictionaryDatas);
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.ecompNameDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.ecompNameDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47         
48     $scope.ecompNameDictionaryGrid = {
49         data : 'ecompNameDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'EcompName.csv',
52         enableGridMenu: true,
53         enableSelectAll: true,
54         columnDefs: [{
55             field: 'id', enableFiltering: false, headerCellTemplate: '' +
56             '<button id=\'New\' ng-click="grid.appScope.createNewEcompName()" class="btn btn-success">' + 'Create</button>',
57             cellTemplate:
58             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editEcompNameWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteEcompName(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60         },
61             { field: 'ecompName', displayName : 'Ecomp Name', sort: { direction: 'asc', priority: 0 } },
62             { field: 'description', width: '20%' },
63             {field: 'userCreatedBy.userName', displayName : 'Created By'},
64             {field: 'userModifiedBy.userName', displayName : 'Modified By' },
65             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
66             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
67         ],
68         exporterMenuPdf: false,
69         enableColumnResize : true,
70         exporterPdfDefaultStyle: {fontSize: 9},
71         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
72         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
73         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
74         exporterPdfFooter: function ( currentPage, pageCount ) {
75          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
76         },
77         exporterPdfCustomFormatter: function ( docDefinition ) {
78          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
79          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
80          return docDefinition;
81         },
82         exporterPdfOrientation: 'portrait',
83         exporterPdfPageSize: 'LETTER',
84         exporterPdfMaxGridWidth: 500,
85         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
86         onRegisterApi: function(gridApi){
87                 $scope.gridApi = gridApi;
88         }
89     };
90
91
92     $scope.editEcompName = null;
93     $scope.createNewEcompName = function(){
94         $scope.editEcompName = null;
95         var modalInstance = $modal.open({
96                 backdrop: 'static', keyboard: false,
97             templateUrl : 'add_ecompName_popup.html',
98             controller: 'editEcompNameController',
99             resolve: {
100                 message: function () {
101                     var message = {
102                         ecompNameDictionaryDatas: $scope.editEcompName
103                     };
104                     return message;
105                 }
106             }
107         });
108         modalInstance.result.then(function(response){
109             console.log('response', response);
110             $scope.ecompNameDictionaryDatas=response.ecompNameDictionaryDatas;
111         });
112     };
113
114     $scope.editEcompNameWindow = function(ecompNameDictionaryData) {
115         $scope.editEcompName = ecompNameDictionaryData;
116         var modalInstance = $modal.open({
117                 backdrop: 'static', keyboard: false,
118             templateUrl : 'add_ecompName_popup.html',
119             controller: 'editEcompNameController',
120             resolve: {
121                 message: function () {
122                     var message = {
123                         ecompNameDictionaryData: $scope.editEcompName
124                     };
125                     return message;
126                 }
127             }
128         });
129         modalInstance.result.then(function(response){
130             console.log('response', response);
131             $scope.ecompNameDictionaryDatas = response.ecompNameDictionaryDatas;
132         });
133     };
134
135     $scope.deleteEcompName = function(data) {
136         var uuu = "searchDictionary";
137         var postData={data: data, type: "ecompName"};
138         var searchString = "\n";
139         $.ajax({
140                 type : 'POST',
141                 url : uuu,
142                 dataType: 'json',
143                 contentType: 'application/json',
144                 data: JSON.stringify(postData),
145                 success : function(resultList){
146                         $scope.$apply(function(){
147                                 $scope.list =resultList.result;});
148                         $scope.searchData = JSON.stringify(resultList.result);
149                         $scope.searchDatas = JSON.parse($scope.searchData);        
150                         $scope.success = true;
151                         var i;
152                         if($scope.searchDatas.length > 0){
153                                 for(i = 0 ; i < $scope.searchDatas.length; i++){
154                                         searchString += $scope.searchDatas[i] + "\n";
155                                 }       
156                         }else{
157                                 searchString += "No Policies is Using this Value"
158                         }
159
160                         console.log($scope.list);
161                         if($scope.success){
162                                 modalService.popupConfirmWin("Confirm","You are about to delete the Ecomp Name  "+data.ecompName+".\n "+searchString+" \n  Do you want to continue?",
163                                                 function(){
164                                         var uuu = "deleteDictionary/ecomp_dictionary/remove_ecomp";
165                                         var postData={data: data};
166                                         $.ajax({
167                                                 type : 'POST',
168                                                 url : uuu,
169                                                 dataType: 'json',
170                                                 contentType: 'application/json',
171                                                 data: JSON.stringify(postData),
172                                                 success : function(data){
173                                                         $scope.$apply(function(){$scope.ecompNameDictionaryDatas=data.ecompNameDictionaryDatas;});
174                                                 },
175                                                 error : function(data){
176                                                         console.log(data);
177                                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
178                                                 }
179                                         });
180
181                                 })}
182                 },
183                 error : function(data){
184                         alert("Error while Searching.");
185                 }
186         });     
187     };
188
189 });