[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / DecisionRainyDayDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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 app.controller('decisionRainyDayDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas);
28         console.log($scope.rainyDayDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32
33     PolicyAppService.getData('get_LockDownData').then(function(data){
34                  var j = data;
35                  $scope.data = JSON.parse(j.data);
36                  $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37                  if($scope.lockdowndata[0].lockdown == true){
38                          $scope.decisionRainyDayDictionaryGrid.columnDefs[0].visible = false;
39                          $scope.gridApi.grid.refresh();
40                  }else{
41                          $scope.decisionRainyDayDictionaryGrid.columnDefs[0].visible = true;
42                          $scope.gridApi.grid.refresh();
43                  }
44          },function(error){
45                  console.log("failed");
46          });
47     $scope.decisionRainyDayDictionaryGrid = {
48         data : 'rainyDayDictionaryDatas',
49         enableFiltering: true,
50         exporterCsvFilename: 'AllowedTreatments.csv',
51         enableGridMenu: true,
52         enableSelectAll: true,
53         columnDefs: [{
54             field: 'id', enableFiltering: false, headerCellTemplate: '' +
55             '<button id=\'New\' ng-click="grid.appScope.createNewRainyDayDictWindow()" class="btn btn-success">' + 'Create</button>',
56             cellTemplate:                                                               
57             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editRainyDayDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
58             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteRainyDayDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
59                 },      
60                 {field: 'bbid', displayName : 'Building Block ID', sort: { direction: 'asc', priority: 0 }},
61             {field: 'workstep', displayName : 'Work Step' },
62             {field: 'treatments', displayName : 'Allowed Treatments'}
63         ],
64         exporterMenuPdf: false,
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.editRainyDayTreatment = null;
87     $scope.createNewRainyDayDictWindow = function(){
88         $scope.editRainyDayTreatment = null;
89         var modalInstance = $modal.open({
90                 backdrop: 'static', keyboard: false,
91             templateUrl : 'add_RainyDayDict_popup.html',
92             controller: 'editRainyDayDictController',
93             resolve: {
94                 message: function () {
95                     var message = {
96                         rainyDayDictionaryDatas: $scope.editRainyDayTreatment
97                     };
98                     return message;
99                 }
100             }
101         });
102         modalInstance.result.then(function(response){
103             console.log('response', response);
104             $scope.rainyDayDictionaryDatas=response.rainyDayDictionaryDatas;
105         });
106     };
107
108     $scope.editRainyDayDictWindow = function(rainyDayDictionaryData) {
109         $scope.editRainyDayTreatment = rainyDayDictionaryData;
110         var modalInstance = $modal.open({
111                 backdrop: 'static', keyboard: false,
112             templateUrl : 'add_RainyDayDict_popup.html',
113             controller: 'editRainyDayDictController',
114             resolve: {
115                 message: function () {
116                     var message = {
117                         rainyDayDictionaryData: $scope.editRainyDayTreatment
118                     };
119                     return message;
120                 }
121             }
122         });
123         modalInstance.result.then(function(response){
124             console.log('response', response);
125             $scope.rainyDayDictionaryDatas = response.rainyDayDictionaryDatas;
126         });
127     };
128
129     $scope.deleteRainyDayDict = function(data) {
130         modalService.popupConfirmWin("Confirm","You are about to delete the Rainy Day Allowed Treatment Dictionary  "+data.allowedTreatments+". Do you want to continue?",
131             function(){
132                 var uuu = "deleteDictionary/decision_dictionary/remove_rainyDay";
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.rainyDayDictionaryDatas=data.rainyDayDictionaryDatas;});
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
153 });