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