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