[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / MSConfigNameDictGridController.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('msConfigNameDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
28         console.log($scope.microServiceCongigNameDictionaryDatas);
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.msConfigNameDictionaryGrid.columnDefs[0].visible = false;
39                 $scope.gridApi.grid.refresh();
40         }else{
41                 $scope.msConfigNameDictionaryGrid.columnDefs[0].visible = true;
42                 $scope.gridApi.grid.refresh();
43         }
44     },function(error){
45         console.log("failed");
46     });
47         
48     $scope.msConfigNameDictionaryGrid = {
49         data : 'microServiceCongigNameDictionaryDatas',
50         enableFiltering: true,
51         columnDefs: [{
52             field: 'id', enableFiltering: false, headerCellTemplate: '' +
53             '<button id=\'New\' ng-click="grid.appScope.createNewMSConfigNameWindow()" class="btn btn-success">' + 'Create</button>',
54             cellTemplate:
55             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editMSConfigNameWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
56             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteMSConfigName(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
57         },{ field: 'name', displayName : 'Name', sort: { direction: 'asc', priority: 0 }},
58             { field: 'descriptionValue', displayName : 'Description' }
59         ]
60     };
61
62     $scope.editMSConfig = null;
63     $scope.createNewMSConfigNameWindow = function(){
64         $scope.editMSConfig = null;
65         var modalInstance = $modal.open({
66                 backdrop: 'static', keyboard: false,
67             templateUrl : 'add_msConfigName_popup.html',
68             controller: 'editMSConfigController',
69             resolve: {
70                 message: function () {
71                     var message = {
72                         microServiceCongigNameDictionaryDatas: $scope.editMSConfig
73                     };
74                     return message;
75                 }
76             }
77         });
78         modalInstance.result.then(function(response){
79             console.log('response', response);
80             $scope.microServiceCongigNameDictionaryDatas=response.microServiceCongigNameDictionaryDatas;
81         });
82     };
83
84     $scope.editMSConfigNameWindow = function(microServiceCongigNameDictionaryData) {
85         $scope.editMSConfig = microServiceCongigNameDictionaryData;
86         var modalInstance = $modal.open({
87                 backdrop: 'static', keyboard: false,
88             templateUrl : 'add_msConfigName_popup.html',
89             controller: 'editMSConfigController',
90             resolve: {
91                 message: function () {
92                     var message = {
93                         microServiceCongigNameDictionaryData: $scope.editMSConfig
94                     };
95                     return message;
96                 }
97             }
98         });
99         modalInstance.result.then(function(response){
100             console.log('response', response);
101             $scope.microServiceCongigNameDictionaryDatas = response.microServiceCongigNameDictionaryDatas;
102         });
103     };
104
105     $scope.deleteMSConfigName = function(data) {
106         modalService.popupConfirmWin("Confirm","You are about to delete the Micro Service Config Name  "+data.name+". Do you want to continue?",
107             function(){
108                 var uuu = "deleteDictionary/ms_dictionary/remove_msConfigName";
109                 var postData={data: data};
110                 $.ajax({
111                     type : 'POST',
112                     url : uuu,
113                     dataType: 'json',
114                     contentType: 'application/json',
115                     data: JSON.stringify(postData),
116                     success : function(data){
117                         $scope.$apply(function(){$scope.microServiceCongigNameDictionaryDatas=data.microServiceCongigNameDictionaryDatas;});
118                     },
119                     error : function(data){
120                         console.log(data);
121                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
122                     }
123                 });
124
125             })
126     };
127 });