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