Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWParentListDictGridController.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('parentDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){
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                 FWDictionaryService.getParentListDictionaryData(papUrl).then(function (data) {
33                         var j = data;
34                         $scope.data = JSON.parse(j.data);
35                         console.log($scope.data);
36                         $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
37                         console.log($scope.fwDictListDictionaryDatas);
38                 }, function (error) {
39                         console.log("failed");
40                 });
41         });
42
43
44
45         $scope.parentDictionaryGrid = {
46                         data : 'fwDictListDictionaryDatas',
47                         enableFiltering: true,
48                         exporterCsvFilename: 'ParentList.csv',
49                         enableGridMenu: true,
50                         enableSelectAll: true,
51                         columnDefs: [{
52                                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
53                                 '<button id=\'New\' ng-click="grid.appScope.createNewFWParentListWindow()" class="btn btn-success">' + 'Create</button>',
54                                 cellTemplate:
55                                         '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWParentListWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
56                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWParentList(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
57                         },{ field: 'parentItemName', displayName : 'Parent Name'},
58                         { field: 'description', displayName : 'Description' },
59                         { field: 'addressList', displayName : 'Address List' },
60                         { field: 'serviceList', displayName : 'Service List' }
61                         ],
62                         exporterPdfDefaultStyle: {fontSize: 9},
63                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
64                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
65                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
66                         exporterPdfFooter: function ( currentPage, pageCount ) {
67                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
68                         },
69                         exporterPdfCustomFormatter: function ( docDefinition ) {
70                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
71                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
72                                 return docDefinition;
73                         },
74                         exporterPdfOrientation: 'portrait',
75                         exporterPdfPageSize: 'LETTER',
76                         exporterPdfMaxGridWidth: 500,
77                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
78                         onRegisterApi: function(gridApi){
79                                 $scope.gridApi = gridApi;
80                         }
81         };
82
83         $scope.editParentList = null;
84         $scope.createNewFWParentListWindow = function(){
85                 $scope.editParentList = null;
86                 var modalInstance = $modal.open({
87                         backdrop: 'static', keyboard: false,
88                         templateUrl : 'add_fwParentList_popup.html',
89                         controller: 'editFWParentListController',
90                         resolve: {
91                                 message: function () {
92                                         var message = {
93                                                         fwDictListDictionaryDatas: $scope.editParentList
94                                         };
95                                         return message;
96                                 }
97                         }
98                 });
99                 modalInstance.result.then(function(response){
100                         console.log('response', response);
101                         $scope.fwDictListDictionaryDatas=response.fwDictListDictionaryDatas;
102                 });
103         };
104
105         $scope.editFWParentListWindow = function(fwDictListDictionaryData) {
106                 $scope.editParentList = fwDictListDictionaryData;
107                 var modalInstance = $modal.open({
108                         backdrop: 'static', keyboard: false,
109                         templateUrl : 'add_fwParentList_popup.html',
110                         controller: 'editFWParentListController',
111                         resolve: {
112                                 message: function () {
113                                         var message = {
114                                                         fwDictListDictionaryData: $scope.editParentList
115                                         };
116                                         return message;
117                                 }
118                         }
119                 });
120                 modalInstance.result.then(function(response){
121                         console.log('response', response);
122                         $scope.fwDictListDictionaryDatas = response.fwDictListDictionaryDatas;
123                 });
124         };
125
126         $scope.deleteFWParentList = function(data) {
127                 modalService.popupConfirmWin("Confirm","You are about to delete the Parent List:  "+data.parentItemName+". Do you want to continue?",
128                                 function(){
129                         var uuu = papUrl + "/ecomp/fw_dictionary/remove_FWDictionaryList.htm";
130                         var postData={data: data};
131                         $.ajax({
132                                 type : 'POST',
133                                 url : uuu,
134                                 dataType: 'json',
135                                 contentType: 'application/json',
136                                 data: JSON.stringify(postData),
137                                 success : function(data){
138                                         $scope.$apply(function(){$scope.fwDictListDictionaryDatas=data.fwDictListDictionaryDatas;});
139                                 },
140                                 error : function(data){
141                                         console.log(data);
142                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
143                                 }
144                         });
145
146                 })
147         };
148
149 });