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