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