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('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 if(message.termListDictionaryData==null){
29 $scope.label='Add Term List Name'
31 $scope.label='Edit Term List Name'
32 $scope.disableCd=true;
33 var fromZoneheaders = message.termListDictionaryData.fromZone;
34 var splitFromZone = ',';
35 if(fromZoneheaders != null){
36 if (fromZoneheaders.indexOf(splitFromZone) >= 0) {
37 var splitFromZoneValue = fromZoneheaders.split(splitFromZone);
38 for(i = 0; i < splitFromZoneValue.length; i++){
39 var key = splitFromZoneValue[i];
40 $scope.fromZonechoices.push({'id':'choice'+i+1, 'option': key});
43 var key = fromZoneheaders;
44 $scope.fromZonechoices.push({'id':'choice'+1, 'option': key});
48 var toZoneheaders = message.termListDictionaryData.toZone;
49 var splitToZone = ',';
50 if(toZoneheaders != null){
51 if (toZoneheaders.indexOf(splitToZone) >= 0) {
52 var splitToZoneValue = toZoneheaders.split(splitToZone);
53 for(i = 0; i < splitToZoneValue.length; i++){
54 var key = splitToZoneValue[i];
55 $scope.toZonechoices.push({'id':'choice'+i+1, 'option': key});
58 var key = toZoneheaders;
59 $scope.toZonechoices.push({'id':'choice'+1, 'option': key});
63 var srcIPheaders = message.termListDictionaryData.srcIPList;
65 if(srcIPheaders != null){
66 if (srcIPheaders.indexOf(splitSrcIP) >= 0) {
67 var splitSrcIPValue = srcIPheaders.split(splitSrcIP);
68 for(i = 0; i < splitSrcIPValue.length; i++){
69 var key = splitSrcIPValue[i];
70 $scope.sourceListchoices.push({'id':'choice'+i+1, 'option': key});
73 var key = srcIPheaders;
74 $scope.sourceListchoices.push({'id':'choice'+1, 'option': key});
78 var desIPheaders = message.termListDictionaryData.destIPList;
80 if(desIPheaders != null){
81 if (desIPheaders.indexOf(splitDesIP) >= 0) {
82 var splitDestIPValue = desIPheaders.split(splitDesIP);
83 for(i = 0; i < splitDestIPValue.length; i++){
84 var key = splitDestIPValue[i];
85 $scope.destinationListchoices.push({'id':'choice'+i+1, 'option': key});
88 var key = desIPheaders;
89 $scope.destinationListchoices.push({'id':'choice'+1, 'option': key});
93 var srcServheaders = message.termListDictionaryData.srcPortList;
94 var splitSrcServ = ',';
95 if(srcServheaders != null){
96 if (srcServheaders.indexOf(splitSrcServ) >= 0) {
97 var splitSrcServValue = srcServheaders.split(splitSrcServ);
98 for(i = 0; i < splitSrcServValue.length; i++){
99 var key = splitSrcServValue[i];
100 $scope.sourceServicechoices.push({'id':'choice'+i+1, 'option': key});
103 var key = srcServheaders;
104 $scope.sourceServicechoices.push({'id':'choice'+1, 'option': key});
108 var desServheaders = message.termListDictionaryData.destPortList;
109 var splitdesSer = ',';
110 if(desServheaders != null){
111 if (desServheaders.indexOf(splitdesSer) >= 0) {
112 var splitDesSerValue = desServheaders.split(splitdesSer);
113 for(i = 0; i < splitDesSerValue.length; i++){
114 var key = splitDesSerValue[i];
115 $scope.destinationServicechoices.push({'id':'choice'+i+1, 'option': key});
118 var key = desServheaders;
119 $scope.destinationServicechoices.push({'id':'choice'+1, 'option': key});
123 var actionheaders = message.termListDictionaryData.action;
124 var splitAction = ',';
125 if(actionheaders != null){
126 if (actionheaders.indexOf(splitAction) >= 0) {
127 var splitActionValue = actionheaders.split(splitAction);
128 for(i = 0; i < splitActionValue.length; i++){
129 var key = splitActionValue[i];
130 $scope.actionListchoices.push({'id':'choice'+i+1, 'option': key});
133 var key = actionheaders;
134 $scope.actionListchoices.push({'id':'choice'+1, 'option': key});
140 PolicyAppService.getData('getDictionary/get_PrefixListDataByName').then(function (data) {
142 $scope.data = JSON.parse(j.data);
143 console.log($scope.data);
144 $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas);
145 console.log($scope.prefixListDictionaryDatas);
146 }, function (error) {
147 console.log("failed");
150 PolicyAppService.getData('getDictionary/get_ZoneDictionaryDataByName').then(function (data) {
152 $scope.data = JSON.parse(j.data);
153 console.log($scope.data);
154 $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas);
155 console.log($scope.zoneDictionaryDatas);
156 }, function (error) {
157 console.log("failed");
160 PolicyAppService.getData('getDictionary/get_AddressGroupDictionaryDataByName').then(function (data) {
162 $scope.data = JSON.parse(j.data);
163 console.log($scope.data);
164 $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
165 console.log($scope.addressGroupDictionaryDatas);
166 }, function (error) {
167 console.log("failed");
170 PolicyAppService.getData('getDictionary/get_ServiceListDictionaryDataByName').then(function (data) {
172 $scope.data = JSON.parse(j.data);
173 console.log($scope.data);
174 $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
175 console.log($scope.serviceListDictionaryDatas);
176 }, function (error) {
177 console.log("failed");
180 PolicyAppService.getData('getDictionary/get_ServiceGroupDictionaryDataByName').then(function (data) {
182 $scope.data = JSON.parse(j.data);
183 console.log($scope.data);
184 $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas);
185 console.log($scope.serviceGroupDictionaryDatas);
186 }, function (error) {
187 console.log("failed");
190 PolicyAppService.getData('getDictionary/get_ActionListDictionaryDataByName').then(function (data) {
192 $scope.data = JSON.parse(j.data);
193 console.log($scope.data);
194 $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas);
195 console.log($scope.actionListDictionaryDatas);
196 }, function (error) {
197 console.log("failed");
201 /*getting user info from session*/
203 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
204 .then(function (response) {
205 userid = response.userid;
208 $scope.editTermList = message.termListDictionaryData;
210 $scope.saveTermName = function(termListDictionaryData) {
211 var regex = new RegExp("^[a-zA-Z0-9_]*$");
212 if(!regex.test(termListDictionaryData.termName)) {
213 Notification.error("Enter Valid Term Name without spaces or special characters");
215 var mergeFromZoneData = extend(termListDictionaryData, $scope.fromZoneDatas[0]);
216 var mergeToData = extend(mergeFromZoneData, $scope.toZoneDatas[0]);
217 var mergeSourceListData = extend(mergeToData, $scope.sourceListDatas[0]);
218 var mergeDListData = extend(mergeSourceListData, $scope.destinationListDatas[0]);
219 var mergeSServicesData = extend(mergeDListData, $scope.sourceServicesDatas[0]);
220 var mergeDServicesData = extend(mergeSServicesData, $scope.destinationServicesDatas[0]);
221 var finalData = extend(mergeDServicesData, $scope.actionListDatas[0]);
222 var uuu = "saveDictionary/fw_dictionary/save_termList";
223 var postData={termListDictionaryData: finalData, userid: userid};
228 contentType: 'application/json',
229 data: JSON.stringify(postData),
230 success : function(data){
231 $scope.$apply(function(){
232 $scope.termListDictionaryDatas=data.termListDictionaryDatas;});
233 if($scope.termListDictionaryDatas == "Duplicate"){
234 Notification.error("FW TermList Dictionary exists with Same Term Name.")
236 console.log($scope.termListDictionaryDatas);
237 $modalInstance.close({termListDictionaryDatas:$scope.termListDictionaryDatas});
240 error : function(data){
241 alert("Error while saving.");
247 $scope.close = function() {
248 $modalInstance.close();
252 function extend(obj, src) {
253 for (var key in src) {
254 if (src.hasOwnProperty(key)) obj[key] = src[key];
259 $scope.fromZoneDatas = [{"fromZoneDatas" : $scope.fromZonechoices}];
260 $scope.addFromZoneNewChoice = function() {
261 var newItemNo = $scope.fromZonechoices.length+1;
262 $scope.fromZonechoices.push({'id':'choice'+newItemNo});
264 $scope.removeFromZoneChoice = function() {
265 var lastItem = $scope.fromZonechoices.length-1;
266 $scope.fromZonechoices.splice(lastItem);
269 $scope.toZoneDatas = [{"toZoneDatas" : $scope.toZonechoices}];
270 $scope.addToZoneNewChoice = function() {
271 var newItemNo = $scope.toZonechoices.length+1;
272 $scope.toZonechoices.push({'id':'choice'+newItemNo});
274 $scope.removeToZoneChoice = function() {
275 var lastItem = $scope.toZonechoices.length-1;
276 $scope.toZonechoices.splice(lastItem);
279 $scope.sourceListDatas = [{"sourceListDatas" : $scope.sourceListchoices}];
280 $scope.addSourceListNewChoice = function() {
281 var newItemNo = $scope.sourceListchoices.length+1;
282 $scope.sourceListchoices.push({'id':'choice'+newItemNo});
284 $scope.removeSourceListChoice = function() {
285 var lastItem = $scope.sourceListchoices.length-1;
286 $scope.sourceListchoices.splice(lastItem);
289 $scope.destinationListDatas = [{"destinationListDatas" : $scope.destinationListchoices}];
290 $scope.addDListNewChoice = function() {
291 var newItemNo = $scope.destinationListchoices.length+1;
292 $scope.destinationListchoices.push({'id':'choice'+newItemNo});
294 $scope.removeDlistChoice = function() {
295 var lastItem = $scope.destinationListchoices.length-1;
296 $scope.destinationListchoices.splice(lastItem);
299 $scope.sourceServicesDatas = [{"sourceServiceDatas" : $scope.sourceServicechoices}];
300 $scope.addSourceServiceNewChoice = function() {
301 var newItemNo = $scope.sourceServicechoices.length+1;
302 $scope.sourceServicechoices.push({'id':'choice'+newItemNo});
304 $scope.removeSourceServiceChoice = function() {
305 var lastItem = $scope.sourceServicechoices.length-1;
306 $scope.sourceServicechoices.splice(lastItem);
309 $scope.destinationServicesDatas = [{"destinationServiceDatas" : $scope.destinationServicechoices}];
310 $scope.addDServicesNewChoice = function() {
311 var newItemNo = $scope.destinationServicechoices.length+1;
312 $scope.destinationServicechoices.push({'id':'choice'+newItemNo});
314 $scope.removeDServicesChoice = function() {
315 var lastItem = $scope.destinationServicechoices.length-1;
316 $scope.destinationServicechoices.splice(lastItem);
319 $scope.actionListDatas = [{"actionListDatas" : $scope.actionListchoices}];
320 $scope.addActionListNewChoice = function() {
321 var newItemNo = $scope.actionListchoices.length+1;
322 $scope.actionListchoices.push({'id':'choice'+newItemNo});
324 $scope.removeActionListChoice = function() {
325 var lastItem = $scope.actionListchoices.length-1;
326 $scope.actionListchoices.splice(lastItem);