Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / PSClosedLoopDictGridController.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('psClosedLoopDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){
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             PolicyScopeService.getPSClosedLoopDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.psClosedLoopDictionaryDatas = JSON.parse($scope.data.psClosedLoopDictionaryDatas);
37                 console.log($scope.psClosedLoopDictionaryDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41                 
42         });
43
44     $scope.psClosedLoopDictionaryGrid = {
45         data : 'psClosedLoopDictionaryDatas',
46         enableFiltering: true,
47         columnDefs: [{
48             field: 'id', enableFiltering: false, headerCellTemplate: '' +
49             '<button id=\'New\' ng-click="grid.appScope.createNewPSClosedLoopWindow()" class="btn btn-success">' + 'Create</button>',
50             cellTemplate:
51             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editPSClosedLoopWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
52             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deletePSClosedLoop(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
53         },{ field: 'name', displayName : 'Closed Loop Name'},
54             { field: 'descriptionValue' , displayName : 'Description'}
55         ]
56     };
57     
58     $scope.editPSClosedLoop = null;
59     $scope.createNewPSClosedLoopWindow = function(){
60         $scope.editPSClosedLoop = null;
61         var modalInstance = $modal.open({
62                 backdrop: 'static', keyboard: false,
63             templateUrl : 'add_PSClosedLoop_popup.html',
64             controller: 'editPSClosedLoopController',
65             resolve: {
66                 message: function () {
67                     var message = {
68                                 psClosedLoopDictionaryDatas: $scope.editPSClosedLoop
69                     };
70                     return message;
71                 }
72             }
73         });
74         modalInstance.result.then(function(response){
75             console.log('response', response);
76             $scope.psClosedLoopDictionaryDatas=response.psClosedLoopDictionaryDatas;
77         });
78     };
79
80     $scope.editPSClosedLoopWindow = function(psClosedLoopDictionaryData) {
81         $scope.editPSClosedLoop = psClosedLoopDictionaryData;
82         var modalInstance = $modal.open({
83                 backdrop: 'static', keyboard: false,
84             templateUrl : 'add_PSClosedLoop_popup.html',
85             controller: 'editPSClosedLoopController',
86             resolve: {
87                 message: function () {
88                     var message = {
89                                 psClosedLoopDictionaryData: $scope.editPSClosedLoop
90                     };
91                     return message;
92                 }
93             }
94         });
95         modalInstance.result.then(function(response){
96             console.log('response', response);
97             $scope.psClosedLoopDictionaryDatas = response.psClosedLoopDictionaryDatas;
98         });
99     };
100
101     $scope.deletePSClosedLoop = function(data) {
102         modalService.popupConfirmWin("Confirm","You are about to delete the Closed Loop  "+data.name+". Do you want to continue?",
103             function(){
104                 var uuu = papUrl + "/ecomp/ps_dictionary/remove_PSClosedLoop.htm";
105                 var postData={data: data};
106                 $.ajax({
107                     type : 'POST',
108                     url : uuu,
109                     dataType: 'json',
110                     contentType: 'application/json',
111                     data: JSON.stringify(postData),
112                     success : function(data){
113                         $scope.$apply(function(){$scope.psClosedLoopDictionaryDatas=data.psClosedLoopDictionaryDatas;});
114                     },
115                     error : function(data){
116                         console.log(data);
117                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
118                     }
119                 });
120
121             })
122     };
123 });