removing unused db file
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / FWServiceListDictController.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 var editFWServiceListController =  function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){
24         $scope.protocolListDictionaryDatas =[];
25
26         $scope.tpchoices = [];
27         $scope.apchoices = [];
28         if(message.serviceListDictionaryData==null){
29                 $scope.label='Add Service List'    
30         }else{
31                 $scope.label='Edit Service List'
32                         $scope.disableCd=true;
33                 var tcpheaders = message.serviceListDictionaryData.serviceTransProtocol;
34                 var splitEqual = ',';
35                 if(tcpheaders != null){
36                         if (tcpheaders.indexOf(splitEqual) >= 0) {
37                                 var splitValue = tcpheaders.split(splitEqual);
38                                 for(i = 0; i < splitValue.length; i++){
39                                         var key  = splitValue[i];
40                                         $scope.tpchoices.push({'id':'choice'+i+1, 'option': key});
41                                 }
42                         }else{
43                                 var key  = tcpheaders;
44                                 $scope.tpchoices.push({'id':'choice'+1, 'option': key});
45                         }
46                 }
47                 var appheaders = message.serviceListDictionaryData.serviceAppProtocol;
48                 var splitEqual1 = ',';
49                 if(appheaders != null){
50                         if (appheaders.indexOf(splitEqual1) >= 0) {
51                                 var splitValue1 = appheaders.split(splitEqual1);
52                                 for(i = 0; i < splitValue1.length; i++){
53                                         var key1  = splitValue1[i];
54                                         $scope.apchoices.push({'id':'choice'+i+1, 'option': key1});
55                                 }
56                         }else{
57                                 var key1  = appheaders;
58                                 $scope.apchoices.push({'id':'choice'+1, 'option': key1});
59                         }
60                 }
61         }
62         
63         var papUrl;
64         PapUrlService.getPapUrl().then(function(data) {
65                 var config = data;
66                 papUrl = config.PAP_URL;
67                 console.log(papUrl);
68                 
69                 FWDictionaryService.getProtocolListDictionaryDataByName(papUrl).then(function (data) {
70                         var j = data;
71                         $scope.data = JSON.parse(j.data);
72                         console.log($scope.data);
73                         $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas);
74                         console.log($scope.protocolListDictionaryDatas);
75                 }, function (error) {
76                         console.log("failed");
77                 });
78         });
79         
80         /*getting user info from session*/
81         var loginId = null;
82         UserInfoService.getFunctionalMenuStaticDetailSession()
83                 .then(function (response) {                     
84                         loginId = response.userid;              
85          });
86         
87         $scope.editServiceList = message.serviceListDictionaryData;
88
89         $scope.saveFWServiceList = function(serviceListDictionaryData) {
90                 var addtcpData = extend(serviceListDictionaryData, $scope.attributeTCPDatas[0]);
91                 var finalData = extend(addtcpData, $scope.attributeAPPDatas[0]);
92                 var uuu = papUrl + "/ecomp/fw_dictionary/save_serviceList.htm";
93                 var postData={serviceListDictionaryData: finalData, loginId: loginId};
94                 $.ajax({
95                         type : 'POST',
96                         url : uuu,
97                         dataType: 'json',
98                         contentType: 'application/json',
99                         data: JSON.stringify(postData),
100                         success : function(data){
101                                 $scope.$apply(function(){
102                                         $scope.serviceListDictionaryDatas=data.serviceListDictionaryDatas;});
103                                 if($scope.serviceListDictionaryDatas == "Duplicate"){
104                                         Notification.error("FW ServiceList Dictionary exists with Same ServiceList Name.")
105                                 }else{      
106                                         console.log($scope.serviceListDictionaryDatas);
107                                         $modalInstance.close({serviceListDictionaryDatas:$scope.serviceListDictionaryDatas});
108                                 }
109                         },
110                         error : function(data){
111                                 alert("Error while saving.");
112                         }
113                 });
114         };
115
116         $scope.close = function() {
117                 $modalInstance.close();
118         };
119
120         function extend(obj, src) {
121                 for (var key in src) {
122                         if (src.hasOwnProperty(key)) obj[key] = src[key];
123                 }
124                 return obj;
125         }
126
127         $scope.attributeTCPDatas = [{"transportProtocols" : $scope.tpchoices}];
128         $scope.addTPNewChoice = function() {
129                 var newItemNo = $scope.tpchoices.length+1;
130                 $scope.tpchoices.push({'id':'choice'+newItemNo});
131         };
132         $scope.removeTPChoice = function() {
133                 var lastItem = $scope.tpchoices.length-1;
134                 $scope.tpchoices.splice(lastItem);
135         };
136
137
138         $scope.attributeAPPDatas = [{"appProtocols" : $scope.apchoices}];
139         $scope.addAPNewChoice = function() {
140                 var newItemNo = $scope.apchoices.length+1;
141                 $scope.apchoices.push({'id':'choice'+newItemNo});
142         };
143         $scope.removeAPChoice = function() {
144                 var lastItem = $scope.apchoices.length-1;
145                 $scope.apchoices.splice(lastItem);
146         };
147 }