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 $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas);
146 for(i = 0; i < $scope.prefixListDictionaryDatas.length; i++){
147 var key = $scope.prefixListDictionaryDatas[i];
148 $scope.groupAddresses.push(key);
152 PolicyAppService.getData('getDictionary/get_ZoneDictionaryDataByName').then(function (data) {
154 $scope.data = JSON.parse(j.data);
155 $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas);
158 PolicyAppService.getData('getDictionary/get_AddressGroupDictionaryDataByName').then(function (data) {
160 $scope.data = JSON.parse(j.data);
161 $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
162 for(i = 0; i < $scope.addressGroupDictionaryDatas.length; i++){
163 var key = $scope.addressGroupDictionaryDatas[i];
164 $scope.groupAddresses.push(key);
168 PolicyAppService.getData('getDictionary/get_ServiceListDictionaryDataByName').then(function (data) {
170 $scope.data = JSON.parse(j.data);
171 $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
172 for(i = 0; i < $scope.serviceListDictionaryDatas.length; i++){
173 var key = $scope.serviceListDictionaryDatas[i];
174 $scope.groupServices.push(key);
178 PolicyAppService.getData('getDictionary/get_ServiceGroupDictionaryDataByName').then(function (data) {
180 $scope.data = JSON.parse(j.data);
181 $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas);
182 for(i = 0; i < $scope.serviceGroupDictionaryDatas.length; i++){
183 var key = $scope.serviceGroupDictionaryDatas[i];
184 $scope.groupServices.push(key);
186 }, function (error) {
189 PolicyAppService.getData('getDictionary/get_ActionListDictionaryDataByName').then(function (data) {
191 $scope.data = JSON.parse(j.data);
192 $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas);
196 /*getting user info from session*/
198 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
199 .then(function (response) {
200 userid = response.userid;
203 $scope.editTermList = message.termListDictionaryData;
205 $scope.saveTermName = function(termListDictionaryData) {
206 var regex = new RegExp("^[a-zA-Z0-9_]*$");
207 if(!regex.test(termListDictionaryData.termName)) {
208 Notification.error("Enter Valid Term Name without spaces or special characters");
210 var mergeFromZoneData = extend(termListDictionaryData, $scope.fromZoneDatas[0]);
211 var mergeToData = extend(mergeFromZoneData, $scope.toZoneDatas[0]);
212 var mergeSourceListData = extend(mergeToData, $scope.sourceListDatas[0]);
213 var mergeDListData = extend(mergeSourceListData, $scope.destinationListDatas[0]);
214 var mergeSServicesData = extend(mergeDListData, $scope.sourceServicesDatas[0]);
215 var mergeDServicesData = extend(mergeSServicesData, $scope.destinationServicesDatas[0]);
216 var finalData = extend(mergeDServicesData, $scope.actionListDatas[0]);
217 var uuu = "saveDictionary/fw_dictionary/save_termList";
218 var postData={termListDictionaryData: finalData, userid: userid};
223 contentType: 'application/json',
224 data: JSON.stringify(postData),
225 success : function(data){
226 $scope.$apply(function(){
227 $scope.termListDictionaryDatas=data.termListDictionaryDatas;});
228 if($scope.termListDictionaryDatas == "Duplicate"){
229 Notification.error("FW TermList Dictionary exists with Same Term Name.")
231 $modalInstance.close({termListDictionaryDatas:$scope.termListDictionaryDatas});
234 error : function(data){
235 Notification.error("Error while saving.");
241 $scope.close = function() {
242 $modalInstance.close();
246 function extend(obj, src) {
247 for (var key in src) {
248 if (src.hasOwnProperty(key)) obj[key] = src[key];
253 $scope.fromZoneDatas = [{"fromZoneDatas" : $scope.fromZonechoices}];
254 $scope.addFromZoneNewChoice = function() {
255 var newItemNo = $scope.fromZonechoices.length+1;
256 $scope.fromZonechoices.push({'id':'choice'+newItemNo});
258 $scope.removeFromZoneChoice = function() {
259 var lastItem = $scope.fromZonechoices.length-1;
260 $scope.fromZonechoices.splice(lastItem);
263 $scope.toZoneDatas = [{"toZoneDatas" : $scope.toZonechoices}];
264 $scope.addToZoneNewChoice = function() {
265 var newItemNo = $scope.toZonechoices.length+1;
266 $scope.toZonechoices.push({'id':'choice'+newItemNo});
268 $scope.removeToZoneChoice = function() {
269 var lastItem = $scope.toZonechoices.length-1;
270 $scope.toZonechoices.splice(lastItem);
273 $scope.sourceListDatas = [{"sourceListDatas" : $scope.sourceListchoices}];
274 $scope.addSourceListNewChoice = function() {
275 var newItemNo = $scope.sourceListchoices.length+1;
276 $scope.sourceListchoices.push({'id':'choice'+newItemNo});
278 $scope.removeSourceListChoice = function() {
279 var lastItem = $scope.sourceListchoices.length-1;
280 $scope.sourceListchoices.splice(lastItem);
283 $scope.destinationListDatas = [{"destinationListDatas" : $scope.destinationListchoices}];
284 $scope.addDListNewChoice = function() {
285 var newItemNo = $scope.destinationListchoices.length+1;
286 $scope.destinationListchoices.push({'id':'choice'+newItemNo});
288 $scope.removeDlistChoice = function() {
289 var lastItem = $scope.destinationListchoices.length-1;
290 $scope.destinationListchoices.splice(lastItem);
293 $scope.sourceServicesDatas = [{"sourceServiceDatas" : $scope.sourceServicechoices}];
294 $scope.addSourceServiceNewChoice = function() {
295 var newItemNo = $scope.sourceServicechoices.length+1;
296 $scope.sourceServicechoices.push({'id':'choice'+newItemNo});
298 $scope.removeSourceServiceChoice = function() {
299 var lastItem = $scope.sourceServicechoices.length-1;
300 $scope.sourceServicechoices.splice(lastItem);
303 $scope.destinationServicesDatas = [{"destinationServiceDatas" : $scope.destinationServicechoices}];
304 $scope.addDServicesNewChoice = function() {
305 var newItemNo = $scope.destinationServicechoices.length+1;
306 $scope.destinationServicechoices.push({'id':'choice'+newItemNo});
308 $scope.removeDServicesChoice = function() {
309 var lastItem = $scope.destinationServicechoices.length-1;
310 $scope.destinationServicechoices.splice(lastItem);
313 $scope.actionListDatas = [{"actionListDatas" : $scope.actionListchoices}];
314 $scope.addActionListNewChoice = function() {
315 var newItemNo = $scope.actionListchoices.length+1;
316 $scope.actionListchoices.push({'id':'choice'+newItemNo});
318 $scope.removeActionListChoice = function() {
319 var lastItem = $scope.actionListchoices.length-1;
320 $scope.actionListchoices.splice(lastItem);