Fixed the Policy API issues and Bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / CLServiceDictGridController.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 app.controller('serviceDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21         $( "#dialog" ).hide();
22
23         PolicyAppService.getData('getDictionary/get_ClosedLoopServicesData').then(function (data) {
24                 var j = data;
25                 $scope.data = JSON.parse(j.data);
26                 console.log($scope.data);
27                 $scope.closedLoopServiceDictionaryDatas = JSON.parse($scope.data.closedLoopServiceDictionaryDatas);
28                 console.log($scope.closedLoopServiceDictionaryDatas);
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.serviceDictionaryGrid.columnDefs[0].visible = false;
39                         $scope.gridApi.grid.refresh();
40                 }else{
41                         $scope.serviceDictionaryGrid.columnDefs[0].visible = true;
42                         $scope.gridApi.grid.refresh();
43                 }
44         },function(error){
45                 console.log("failed");
46         });
47
48         $scope.serviceDictionaryGrid = {
49                         data : 'closedLoopServiceDictionaryDatas',
50                         enableFiltering: true,
51                         columnDefs: [{
52                                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
53                                 '<button id=\'New\' ng-click="grid.appScope.createNewServiceDictWindow()" class="btn btn-success">' + 'Create</button>',
54                                 cellTemplate:
55                                         '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editServiceDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
56                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteServiceDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
57                         },
58                         { field: 'serviceName', displayName : 'Service Name', sort: { direction: 'asc', priority: 0 }},
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         };
66
67         $scope.editCLService = null;
68         $scope.createNewServiceDictWindow = function(){
69                 $scope.editCLService = null;
70                 var modalInstance = $modal.open({
71                         backdrop: 'static', keyboard: false,
72                         templateUrl : 'add_CLService_popup.html',
73                         controller: 'editCLServiceController',
74                         resolve: {
75                                 message: function () {
76                                         var message = {
77                                                         closedLoopServiceDictionaryDatas: $scope.editCLService
78                                         };
79                                         return message;
80                                 }
81                         }
82                 });
83                 modalInstance.result.then(function(response){
84                         console.log('response', response);
85                         $scope.closedLoopServiceDictionaryDatas=response.closedLoopServiceDictionaryDatas;
86                 });
87         };
88
89         $scope.editServiceDictWindow = function(closedLoopServiceDictionaryData) {
90                 $scope.editCLService = closedLoopServiceDictionaryData;
91                 var modalInstance = $modal.open({
92                         backdrop: 'static', keyboard: false,
93                         templateUrl : 'add_CLService_popup.html',
94                         controller: 'editCLServiceController',
95                         resolve: {
96                                 message: function () {
97                                         var message = {
98                                                         closedLoopServiceDictionaryData: $scope.editCLService
99                                         };
100                                         return message;
101                                 }
102                         }
103                 });
104                 modalInstance.result.then(function(response){
105                         console.log('response', response);
106                         $scope.closedLoopServiceDictionaryDatas = response.closedLoopServiceDictionaryDatas;
107                 });
108         };
109
110         $scope.deleteServiceDict = function(data) {
111                 var uuu = "searchDictionary";
112                 var postData={data: data, type: "clService"};
113                 var searchString = "\n";
114                 $.ajax({
115                         type : 'POST',
116                         url : uuu,
117                         dataType: 'json',
118                         contentType: 'application/json',
119                         data: JSON.stringify(postData),
120                         success : function(resultList){
121                                 $scope.$apply(function(){
122                                         $scope.list =resultList.result;});
123                                 $scope.searchData = JSON.stringify(resultList.result);
124                                 $scope.searchDatas = JSON.parse($scope.searchData);        
125                                 $scope.success = true;
126                                 var i;
127                                 if($scope.searchDatas.length > 0){
128                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
129                                                 searchString += $scope.searchDatas[i] + "\n";
130                                         }       
131                                 }else{
132                                         searchString += "No Policies is Using this Value"
133                                 }
134
135                                 console.log($scope.list);
136                                 if($scope.success){
137                                         modalService.popupConfirmWin("Confirm","You are about to delete the Service Dictionary  "+data.serviceName+". \n "+searchString+" \n  Do you want to continue?",
138                                                         function(){
139                                                 var uuu = "deleteDictionary/cl_dictionary/remove_Service";
140                                                 var postData={data: data};
141                                                 $.ajax({
142                                                         type : 'POST',
143                                                         url : uuu,
144                                                         dataType: 'json',
145                                                         contentType: 'application/json',
146                                                         data: JSON.stringify(postData),
147                                                         success : function(data){
148                                                                 $scope.$apply(function(){$scope.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;});
149                                                         },
150                                                         error : function(data){
151                                                                 console.log(data);
152                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
153                                                         }
154                                                 });
155
156                                         })}
157                         },
158                         error : function(data){
159                                 alert("Error while Searching.");
160                         }
161                 });
162         };
163
164
165 });