Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-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
21 /**
22  */
23 app.controller('serviceDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){
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             CLDictionaryService.getServiceDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.closedLoopServiceDictionaryDatas = JSON.parse($scope.data.closedLoopServiceDictionaryDatas);
37                 console.log($scope.closedLoopServiceDictionaryDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41             
42         });
43
44     $scope.serviceDictionaryGrid = {
45         data : 'closedLoopServiceDictionaryDatas',
46         enableFiltering: true,
47         columnDefs: [{
48             field: 'id', enableFiltering: false, headerCellTemplate: '' +
49             '<button id=\'New\' ng-click="grid.appScope.createNewServiceDictWindow()" class="btn btn-success">' + 'Create</button>',
50             cellTemplate:
51             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editServiceDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
52             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteServiceDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
53         },
54             { field: 'serviceName', displayName : 'Service Name'},
55             { field: 'description'},
56             {field: 'userCreatedBy.userName', displayName : 'Created By'},
57             {field: 'userModifiedBy.userName', displayName : 'Modified By'},
58             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' },
59             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
60         ]
61     };
62
63     $scope.editCLService = null;
64     $scope.createNewServiceDictWindow = function(){
65         $scope.editCLService = null;
66         var modalInstance = $modal.open({
67                 backdrop: 'static', keyboard: false,
68             templateUrl : 'add_CLService_popup.html',
69             controller: 'editCLServiceController',
70             resolve: {
71                 message: function () {
72                     var message = {
73                         closedLoopServiceDictionaryDatas: $scope.editCLService
74                     };
75                     return message;
76                 }
77             }
78         });
79         modalInstance.result.then(function(response){
80             console.log('response', response);
81             $scope.closedLoopServiceDictionaryDatas=response.closedLoopServiceDictionaryDatas;
82         });
83     };
84
85     $scope.editServiceDictWindow = function(closedLoopServiceDictionaryData) {
86         $scope.editCLService = closedLoopServiceDictionaryData;
87         var modalInstance = $modal.open({
88                 backdrop: 'static', keyboard: false,
89             templateUrl : 'add_CLService_popup.html',
90             controller: 'editCLServiceController',
91             resolve: {
92                 message: function () {
93                     var message = {
94                         closedLoopServiceDictionaryData: $scope.editCLService
95                     };
96                     return message;
97                 }
98             }
99         });
100         modalInstance.result.then(function(response){
101             console.log('response', response);
102             $scope.closedLoopServiceDictionaryDatas = response.closedLoopServiceDictionaryDatas;
103         });
104     };
105
106     $scope.deleteServiceDict = function(data) {
107         var uuu = "searchDictionary.htm";
108         var postData={data: data, type: "clService"};
109         var searchString = "\n";
110         $.ajax({
111                 type : 'POST',
112                 url : uuu,
113                 dataType: 'json',
114                 contentType: 'application/json',
115                 data: JSON.stringify(postData),
116                 success : function(resultList){
117                         $scope.$apply(function(){
118                                 $scope.list =resultList.result;});
119                         $scope.searchData = JSON.stringify(resultList.result);
120                         $scope.searchDatas = JSON.parse($scope.searchData);        
121                         $scope.success = true;
122                         var i;
123                         if($scope.searchDatas.length > 0){
124                                 for(i = 0 ; i < $scope.searchDatas.length; i++){
125                                         searchString += $scope.searchDatas[i].name + "\n";
126                                 }       
127                         }else{
128                                 searchString += "No Policies is Using this Value"
129                         }
130
131                         console.log($scope.list);
132                         if($scope.success){
133                                 modalService.popupConfirmWin("Confirm","You are about to delete the Service Dictionary  "+data.serviceName+". \n "+searchString+" \n  Do you want to continue?",
134                                                 function(){
135                                         var uuu = papUrl + "/ecomp/cl_dictionary/remove_Service.htm";
136                                         var postData={data: data};
137                                         $.ajax({
138                                                 type : 'POST',
139                                                 url : uuu,
140                                                 dataType: 'json',
141                                                 contentType: 'application/json',
142                                                 data: JSON.stringify(postData),
143                                                 success : function(data){
144                                                         $scope.$apply(function(){$scope.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;});
145                                                 },
146                                                 error : function(data){
147                                                         console.log(data);
148                                                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
149                                                 }
150                                         });
151
152                                 })}
153                 },
154                 error : function(data){
155                         alert("Error while Searching.");
156                 }
157         });
158     };
159
160
161 });