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=========================================================
20 app.controller('editFWServiceListController' , function ($scope, $modalInstance, message, PolicyAppService, UserInfoServiceDS2, Notification){
21 $scope.protocolListDictionaryDatas =[];
23 $scope.tpchoices = [];
24 $scope.apchoices = [];
25 if(message.serviceListDictionaryData==null){
26 $scope.label='Add Service List'
28 $scope.label='Edit Service List'
29 $scope.disableCd=true;
30 var tcpheaders = message.serviceListDictionaryData.serviceTransProtocol;
32 if(tcpheaders != null){
33 if (tcpheaders.indexOf(splitEqual) >= 0) {
34 var splitValue = tcpheaders.split(splitEqual);
35 for(i = 0; i < splitValue.length; i++){
36 var key = splitValue[i];
37 $scope.tpchoices.push({'id':'choice'+i+1, 'option': key});
41 $scope.tpchoices.push({'id':'choice'+1, 'option': key});
44 var appheaders = message.serviceListDictionaryData.serviceAppProtocol;
45 var splitEqual1 = ',';
46 if(appheaders != null){
47 if (appheaders.indexOf(splitEqual1) >= 0) {
48 var splitValue1 = appheaders.split(splitEqual1);
49 for(i = 0; i < splitValue1.length; i++){
50 var key1 = splitValue1[i];
51 $scope.apchoices.push({'id':'choice'+i+1, 'option': key1});
54 var key1 = appheaders;
55 $scope.apchoices.push({'id':'choice'+1, 'option': key1});
61 PolicyAppService.getData('getDictionary/get_ProtocolListDataByName').then(function (data) {
63 $scope.data = JSON.parse(j.data);
64 console.log($scope.data);
65 $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas);
66 console.log($scope.protocolListDictionaryDatas);
68 console.log("failed");
72 /*getting user info from session*/
74 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
75 .then(function (response) {
76 userid = response.userid;
79 $scope.editServiceList = message.serviceListDictionaryData;
81 $scope.saveFWServiceList = function(serviceListDictionaryData) {
82 var regex = new RegExp("^[a-zA-Z0-9_]*$");
83 if(!regex.test(serviceListDictionaryData.serviceName)) {
84 Notification.error("Enter Valid ServiceList Name without spaces or special characters");
86 var addtcpData = extend(serviceListDictionaryData, $scope.attributeTCPDatas[0]);
87 var finalData = extend(addtcpData, $scope.attributeAPPDatas[0]);
88 var uuu = "saveDictionary/fw_dictionary/save_serviceList";
89 var postData={serviceListDictionaryData: finalData, userid: userid};
94 contentType: 'application/json',
95 data: JSON.stringify(postData),
96 success : function(data){
97 $scope.$apply(function(){
98 $scope.serviceListDictionaryDatas=data.serviceListDictionaryDatas;});
99 if($scope.serviceListDictionaryDatas == "Duplicate"){
100 Notification.error("FW ServiceList Dictionary exists with Same ServiceList Name.")
102 console.log($scope.serviceListDictionaryDatas);
103 $modalInstance.close({serviceListDictionaryDatas:$scope.serviceListDictionaryDatas});
106 error : function(data){
107 alert("Error while saving.");
113 $scope.close = function() {
114 $modalInstance.close();
117 function extend(obj, src) {
118 for (var key in src) {
119 if (src.hasOwnProperty(key)) obj[key] = src[key];
124 $scope.attributeTCPDatas = [{"transportProtocols" : $scope.tpchoices}];
125 $scope.addTPNewChoice = function() {
126 var newItemNo = $scope.tpchoices.length+1;
127 $scope.tpchoices.push({'id':'choice'+newItemNo});
129 $scope.removeTPChoice = function() {
130 var lastItem = $scope.tpchoices.length-1;
131 $scope.tpchoices.splice(lastItem);
135 $scope.attributeAPPDatas = [{"appProtocols" : $scope.apchoices}];
136 $scope.addAPNewChoice = function() {
137 var newItemNo = $scope.apchoices.length+1;
138 $scope.apchoices.push({'id':'choice'+newItemNo});
140 $scope.removeAPChoice = function() {
141 var lastItem = $scope.apchoices.length-1;
142 $scope.apchoices.splice(lastItem);