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