2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 var editFWServiceListController = function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){
24 $scope.protocolListDictionaryDatas =[];
26 $scope.tpchoices = [];
27 $scope.apchoices = [];
28 if(message.serviceListDictionaryData==null){
29 $scope.label='Add Service List'
31 $scope.label='Edit Service List'
32 $scope.disableCd=true;
33 var tcpheaders = message.serviceListDictionaryData.serviceTransProtocol;
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});
44 $scope.tpchoices.push({'id':'choice'+1, 'option': key});
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});
57 var key1 = appheaders;
58 $scope.apchoices.push({'id':'choice'+1, 'option': key1});
64 PapUrlService.getPapUrl().then(function(data) {
66 papUrl = config.PAP_URL;
69 FWDictionaryService.getProtocolListDictionaryDataByName(papUrl).then(function (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);
76 console.log("failed");
80 /*getting user info from session*/
82 UserInfoService.getFunctionalMenuStaticDetailSession()
83 .then(function (response) {
84 loginId = response.userid;
87 $scope.editServiceList = message.serviceListDictionaryData;
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};
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.")
106 console.log($scope.serviceListDictionaryDatas);
107 $modalInstance.close({serviceListDictionaryDatas:$scope.serviceListDictionaryDatas});
110 error : function(data){
111 alert("Error while saving.");
116 $scope.close = function() {
117 $modalInstance.close();
120 function extend(obj, src) {
121 for (var key in src) {
122 if (src.hasOwnProperty(key)) obj[key] = src[key];
127 $scope.attributeTCPDatas = [{"transportProtocols" : $scope.tpchoices}];
128 $scope.addTPNewChoice = function() {
129 var newItemNo = $scope.tpchoices.length+1;
130 $scope.tpchoices.push({'id':'choice'+newItemNo});
132 $scope.removeTPChoice = function() {
133 var lastItem = $scope.tpchoices.length-1;
134 $scope.tpchoices.splice(lastItem);
138 $scope.attributeAPPDatas = [{"appProtocols" : $scope.apchoices}];
139 $scope.addAPNewChoice = function() {
140 var newItemNo = $scope.apchoices.length+1;
141 $scope.apchoices.push({'id':'choice'+newItemNo});
143 $scope.removeAPChoice = function() {
144 var lastItem = $scope.apchoices.length-1;
145 $scope.apchoices.splice(lastItem);