2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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('editFWTermListController' , function ($scope, $modalInstance, message, PolicyAppService, UserInfoServiceDS2, Notification){
21 $scope.fromZonechoices = [];
22 $scope.toZonechoices = [];
23 $scope.sourceListchoices = [];
24 $scope.destinationListchoices = [];
25 $scope.sourceServicechoices = [];
26 $scope.destinationServicechoices = [];
27 $scope.actionListchoices = [];
28 $scope.groupAddresses=[];
29 $scope.groupServices=[];
30 if(message.termListDictionaryData==null){
31 $scope.label='Add Term List Name'
33 $scope.label='Edit Term List Name'
34 $scope.disableCd=true;
35 var fromZoneheaders = message.termListDictionaryData.fromZone;
36 var splitFromZone = ',';
37 if(fromZoneheaders != null){
38 if (fromZoneheaders.indexOf(splitFromZone) >= 0) {
39 var splitFromZoneValue = fromZoneheaders.split(splitFromZone);
40 for(i = 0; i < splitFromZoneValue.length; i++){
41 var key = splitFromZoneValue[i];
42 $scope.fromZonechoices.push({'id':'choice'+i+1, 'option': key});
45 var key = fromZoneheaders;
46 $scope.fromZonechoices.push({'id':'choice'+1, 'option': key});
50 var toZoneheaders = message.termListDictionaryData.toZone;
51 var splitToZone = ',';
52 if(toZoneheaders != null){
53 if (toZoneheaders.indexOf(splitToZone) >= 0) {
54 var splitToZoneValue = toZoneheaders.split(splitToZone);
55 for(i = 0; i < splitToZoneValue.length; i++){
56 var key = splitToZoneValue[i];
57 $scope.toZonechoices.push({'id':'choice'+i+1, 'option': key});
60 var key = toZoneheaders;
61 $scope.toZonechoices.push({'id':'choice'+1, 'option': key});
65 var srcIPheaders = message.termListDictionaryData.srcIPList;
67 if(srcIPheaders != null){
68 if (srcIPheaders.indexOf(splitSrcIP) >= 0) {
69 var splitSrcIPValue = srcIPheaders.split(splitSrcIP);
70 for(i = 0; i < splitSrcIPValue.length; i++){
71 var key = splitSrcIPValue[i];
72 $scope.sourceListchoices.push({'id':'choice'+i+1, 'option': key});
75 var key = srcIPheaders;
76 $scope.sourceListchoices.push({'id':'choice'+1, 'option': key});
80 var desIPheaders = message.termListDictionaryData.destIPList;
82 if(desIPheaders != null){
83 if (desIPheaders.indexOf(splitDesIP) >= 0) {
84 var splitDestIPValue = desIPheaders.split(splitDesIP);
85 for(i = 0; i < splitDestIPValue.length; i++){
86 var key = splitDestIPValue[i];
87 $scope.destinationListchoices.push({'id':'choice'+i+1, 'option': key});
90 var key = desIPheaders;
91 $scope.destinationListchoices.push({'id':'choice'+1, 'option': key});
95 var srcServheaders = message.termListDictionaryData.srcPortList;
96 var splitSrcServ = ',';
97 if(srcServheaders != null){
98 if (srcServheaders.indexOf(splitSrcServ) >= 0) {
99 var splitSrcServValue = srcServheaders.split(splitSrcServ);
100 for(i = 0; i < splitSrcServValue.length; i++){
101 var key = splitSrcServValue[i];
102 $scope.sourceServicechoices.push({'id':'choice'+i+1, 'option': key});
105 var key = srcServheaders;
106 $scope.sourceServicechoices.push({'id':'choice'+1, 'option': key});
110 var desServheaders = message.termListDictionaryData.destPortList;
111 var splitdesSer = ',';
112 if(desServheaders != null){
113 if (desServheaders.indexOf(splitdesSer) >= 0) {
114 var splitDesSerValue = desServheaders.split(splitdesSer);
115 for(i = 0; i < splitDesSerValue.length; i++){
116 var key = splitDesSerValue[i];
117 $scope.destinationServicechoices.push({'id':'choice'+i+1, 'option': key});
120 var key = desServheaders;
121 $scope.destinationServicechoices.push({'id':'choice'+1, 'option': key});
125 var actionheaders = message.termListDictionaryData.action;
126 var splitAction = ',';
127 if(actionheaders != null){
128 if (actionheaders.indexOf(splitAction) >= 0) {
129 var splitActionValue = actionheaders.split(splitAction);
130 for(i = 0; i < splitActionValue.length; i++){
131 var key = splitActionValue[i];
132 $scope.actionListchoices.push({'id':'choice'+i+1, 'option': key});
135 var key = actionheaders;
136 $scope.actionListchoices.push({'id':'choice'+1, 'option': key});
142 PolicyAppService.getData('getDictionary/get_PrefixListDataByName').then(function (data) {
144 $scope.data = JSON.parse(j.data);
145 console.log($scope.data);
146 $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas);
147 console.log($scope.prefixListDictionaryDatas);
148 for(i = 0; i < $scope.prefixListDictionaryDatas.length; i++){
149 var key = $scope.prefixListDictionaryDatas[i];
150 $scope.groupAddresses.push(key);
152 }, function (error) {
153 console.log("failed");
156 PolicyAppService.getData('getDictionary/get_ZoneDictionaryDataByName').then(function (data) {
158 $scope.data = JSON.parse(j.data);
159 console.log($scope.data);
160 $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas);
161 console.log($scope.zoneDictionaryDatas);
162 }, function (error) {
163 console.log("failed");
166 PolicyAppService.getData('getDictionary/get_AddressGroupDictionaryDataByName').then(function (data) {
168 $scope.data = JSON.parse(j.data);
169 console.log($scope.data);
170 $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
171 console.log($scope.addressGroupDictionaryDatas);
172 for(i = 0; i < $scope.addressGroupDictionaryDatas.length; i++){
173 var key = $scope.addressGroupDictionaryDatas[i];
174 $scope.groupAddresses.push(key);
176 }, function (error) {
177 console.log("failed");
180 PolicyAppService.getData('getDictionary/get_ServiceListDictionaryDataByName').then(function (data) {
182 $scope.data = JSON.parse(j.data);
183 console.log($scope.data);
184 $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
185 console.log($scope.serviceListDictionaryDatas);
186 for(i = 0; i < $scope.serviceListDictionaryDatas.length; i++){
187 var key = $scope.serviceListDictionaryDatas[i];
188 $scope.groupServices.push(key);
190 }, function (error) {
191 console.log("failed");
194 PolicyAppService.getData('getDictionary/get_ServiceGroupDictionaryDataByName').then(function (data) {
196 $scope.data = JSON.parse(j.data);
197 console.log($scope.data);
198 $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas);
199 console.log($scope.serviceGroupDictionaryDatas);
200 for(i = 0; i < $scope.serviceGroupDictionaryDatas.length; i++){
201 var key = $scope.serviceGroupDictionaryDatas[i];
202 $scope.groupServices.push(key);
204 }, function (error) {
205 console.log("failed");
208 PolicyAppService.getData('getDictionary/get_ActionListDictionaryDataByName').then(function (data) {
210 $scope.data = JSON.parse(j.data);
211 console.log($scope.data);
212 $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas);
213 console.log($scope.actionListDictionaryDatas);
214 }, function (error) {
215 console.log("failed");
219 /*getting user info from session*/
221 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
222 .then(function (response) {
223 userid = response.userid;
226 $scope.editTermList = message.termListDictionaryData;
228 $scope.saveTermName = function(termListDictionaryData) {
229 var regex = new RegExp("^[a-zA-Z0-9_]*$");
230 if(!regex.test(termListDictionaryData.termName)) {
231 Notification.error("Enter Valid Term Name without spaces or special characters");
233 var mergeFromZoneData = extend(termListDictionaryData, $scope.fromZoneDatas[0]);
234 var mergeToData = extend(mergeFromZoneData, $scope.toZoneDatas[0]);
235 var mergeSourceListData = extend(mergeToData, $scope.sourceListDatas[0]);
236 var mergeDListData = extend(mergeSourceListData, $scope.destinationListDatas[0]);
237 var mergeSServicesData = extend(mergeDListData, $scope.sourceServicesDatas[0]);
238 var mergeDServicesData = extend(mergeSServicesData, $scope.destinationServicesDatas[0]);
239 var finalData = extend(mergeDServicesData, $scope.actionListDatas[0]);
240 var uuu = "saveDictionary/fw_dictionary/save_termList";
241 var postData={termListDictionaryData: finalData, userid: userid};
246 contentType: 'application/json',
247 data: JSON.stringify(postData),
248 success : function(data){
249 $scope.$apply(function(){
250 $scope.termListDictionaryDatas=data.termListDictionaryDatas;});
251 if($scope.termListDictionaryDatas == "Duplicate"){
252 Notification.error("FW TermList Dictionary exists with Same Term Name.")
254 console.log($scope.termListDictionaryDatas);
255 $modalInstance.close({termListDictionaryDatas:$scope.termListDictionaryDatas});
258 error : function(data){
259 Notification.error("Error while saving.");
265 $scope.close = function() {
266 $modalInstance.close();
270 function extend(obj, src) {
271 for (var key in src) {
272 if (src.hasOwnProperty(key)) obj[key] = src[key];
277 $scope.fromZoneDatas = [{"fromZoneDatas" : $scope.fromZonechoices}];
278 $scope.addFromZoneNewChoice = function() {
279 var newItemNo = $scope.fromZonechoices.length+1;
280 $scope.fromZonechoices.push({'id':'choice'+newItemNo});
282 $scope.removeFromZoneChoice = function() {
283 var lastItem = $scope.fromZonechoices.length-1;
284 $scope.fromZonechoices.splice(lastItem);
287 $scope.toZoneDatas = [{"toZoneDatas" : $scope.toZonechoices}];
288 $scope.addToZoneNewChoice = function() {
289 var newItemNo = $scope.toZonechoices.length+1;
290 $scope.toZonechoices.push({'id':'choice'+newItemNo});
292 $scope.removeToZoneChoice = function() {
293 var lastItem = $scope.toZonechoices.length-1;
294 $scope.toZonechoices.splice(lastItem);
297 $scope.sourceListDatas = [{"sourceListDatas" : $scope.sourceListchoices}];
298 $scope.addSourceListNewChoice = function() {
299 var newItemNo = $scope.sourceListchoices.length+1;
300 $scope.sourceListchoices.push({'id':'choice'+newItemNo});
302 $scope.removeSourceListChoice = function() {
303 var lastItem = $scope.sourceListchoices.length-1;
304 $scope.sourceListchoices.splice(lastItem);
307 $scope.destinationListDatas = [{"destinationListDatas" : $scope.destinationListchoices}];
308 $scope.addDListNewChoice = function() {
309 var newItemNo = $scope.destinationListchoices.length+1;
310 $scope.destinationListchoices.push({'id':'choice'+newItemNo});
312 $scope.removeDlistChoice = function() {
313 var lastItem = $scope.destinationListchoices.length-1;
314 $scope.destinationListchoices.splice(lastItem);
317 $scope.sourceServicesDatas = [{"sourceServiceDatas" : $scope.sourceServicechoices}];
318 $scope.addSourceServiceNewChoice = function() {
319 var newItemNo = $scope.sourceServicechoices.length+1;
320 $scope.sourceServicechoices.push({'id':'choice'+newItemNo});
322 $scope.removeSourceServiceChoice = function() {
323 var lastItem = $scope.sourceServicechoices.length-1;
324 $scope.sourceServicechoices.splice(lastItem);
327 $scope.destinationServicesDatas = [{"destinationServiceDatas" : $scope.destinationServicechoices}];
328 $scope.addDServicesNewChoice = function() {
329 var newItemNo = $scope.destinationServicechoices.length+1;
330 $scope.destinationServicechoices.push({'id':'choice'+newItemNo});
332 $scope.removeDServicesChoice = function() {
333 var lastItem = $scope.destinationServicechoices.length-1;
334 $scope.destinationServicechoices.splice(lastItem);
337 $scope.actionListDatas = [{"actionListDatas" : $scope.actionListchoices}];
338 $scope.addActionListNewChoice = function() {
339 var newItemNo = $scope.actionListchoices.length+1;
340 $scope.actionListchoices.push({'id':'choice'+newItemNo});
342 $scope.removeActionListChoice = function() {
343 var lastItem = $scope.actionListchoices.length-1;
344 $scope.actionListchoices.splice(lastItem);