Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / BRMSDependencyDictGridController.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('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                         exporterPdfOrientation: 'portrait',
84                         exporterPdfPageSize: 'LETTER',
85                         exporterPdfMaxGridWidth: 500,
86                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
87                         onRegisterApi: function(gridApi){
88                                 $scope.gridApi = gridApi;
89                         }
90         };
91
92         $scope.editBRMSDependency = null;
93         $scope.createNewBRMSDependencyWindow = function(){
94                 $scope.editBRMSDependency = null;
95                 var modalInstance = $modal.open({
96                         backdrop: 'static', keyboard: false,
97                         templateUrl : 'add_brmsDependency_popup.html',
98                         controller: 'editBRMSDependencyController',
99                         resolve: {
100                                 message: function () {
101                                         var message = {
102                                                         brmsDependencyDictionaryDatas: $scope.editBRMSDependency,
103                                                         disabled : false
104                                         };
105                                         return message;
106                                 }
107                         }
108                 });
109                 modalInstance.result.then(function(response){
110                         console.log('response', response);
111                         $scope.brmsDependencyDictionaryDatas=response.brmsDependencyDictionaryDatas;
112                 });
113         };
114
115         $scope.viewBRMSDependencyWindow = function(brmsDependencyDictionaryData) {
116                 $scope.editBRMSDependency = brmsDependencyDictionaryData;
117                 var modalInstance = $modal.open({
118                         backdrop: 'static', keyboard: false,
119                         templateUrl : 'add_brmsDependency_popup.html',
120                         controller: 'editBRMSDependencyController',
121                         resolve: {
122                                 message: function () {
123                                         var message = {
124                                                         brmsDependencyDictionaryDatas: $scope.editBRMSDependency,
125                                                         disabled : true
126                                         };
127                                         return message;
128                                 }
129                         }
130                 });
131                 modalInstance.result.then(function(response){
132                         console.log('response', response);
133                         $scope.brmsDependencyDictionaryDatas=response.brmsDependencyDictionaryDatas;
134                 });
135         }; 
136
137         $scope.editBRMSDependencyWindow = function(brmsDependencyDictionaryData) {
138                 $scope.editBRMSDependency = brmsDependencyDictionaryData;
139                 var modalInstance = $modal.open({
140                         backdrop: 'static', keyboard: false,
141                         templateUrl : 'add_brmsDependency_popup.html',
142                         controller: 'editBRMSDependencyController',
143                         resolve: {
144                                 message: function () {
145                                         var message = {
146                                                         brmsDependencyDictionaryDatas: $scope.editBRMSDependency,
147                                                         disabled : false
148                                         };
149                                         return message;
150                                 }
151                         }
152                 });
153                 modalInstance.result.then(function(response){
154                         console.log('response', response);
155                         $scope.brmsDependencyDictionaryDatas=response.brmsDependencyDictionaryDatas;
156                 });
157         };
158
159         $scope.deleteBRMSDependency = function(data) {
160                 modalService.popupConfirmWin("Confirm","You are about to delete the BRMS Dependency "+data.dependencyName+". Do you want to continue?",
161                                 function(){
162                         var uuu =  "deleteDictionary/brms_dictionary/remove_brmsDependency";
163                         var postData={data: data};
164                         $.ajax({
165                                 type : 'POST',
166                                 url : uuu,
167                                 dataType: 'json',
168                                 contentType: 'application/json',
169                                 data: JSON.stringify(postData),
170                                 success : function(data){
171                                         $scope.$apply(function(){$scope.brmsDependencyDictionaryDatas=data.brmsDependencyDictionaryDatas;});
172                                 },
173                                 error : function(data){
174                                         console.log(data);
175                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
176                                 }
177                         });
178
179                 })
180         };
181
182 });