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