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('editFWAddressGroupController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, PolicyAppService, Notification){
21 if(message.addressGroupDictionaryData==null)
22 $scope.label='Add Address Group',
23 $scope.apchoices = [];
25 $scope.label='Edit Address Group'
26 $scope.disableCd=true;
27 $scope.apchoices = [];
28 var headers = message.addressGroupDictionaryData.prefixList;
31 if (headers.indexOf(splitEqual) >= 0) {
32 var splitValue = headers.split(splitEqual);
33 for(i = 0; i < splitValue.length; i++){
34 var key = splitValue[i];
35 $scope.apchoices.push({'id':'choice'+i+1, 'option': key});
39 $scope.apchoices.push({'id':'choice'+1, 'option': key});
45 PolicyAppService.getData('getDictionary/get_PrefixListDataByName').then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas);
50 console.log($scope.prefixListDictionaryDatas);
52 console.log("failed");
56 /*getting user info from session*/
58 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
59 .then(function (response) {
60 userid = response.userid;
63 $scope.editAddressGroup = message.addressGroupDictionaryData;
65 $scope.saveFWAddressGroup = function(addressGroupDictionaryData) {
66 var regex = new RegExp("^[a-zA-Z0-9_]*$");
67 if(!regex.test(addressGroupDictionaryData.groupName)) {
68 Notification.error("Enter Valid Address Group Name without spaces or special characters");
70 var finalData = extend(addressGroupDictionaryData, $scope.attributeDatas[0]);
71 var uuu = "saveDictionary/fw_dictionary/save_addressGroup";
72 var postData={addressGroupDictionaryData: finalData, userid: userid};
77 contentType: 'application/json',
78 data: JSON.stringify(postData),
79 success : function(data){
80 $scope.$apply(function(){
81 $scope.addressGroupDictionaryDatas=data.addressGroupDictionaryDatas;});
82 if($scope.addressGroupDictionaryDatas == "Duplicate"){
83 Notification.error("FW AddressGroup Dictionary exists with Same Address group Name.")
85 console.log($scope.addressGroupDictionaryDatas);
86 $modalInstance.close({addressGroupDictionaryDatas:$scope.addressGroupDictionaryDatas});
89 error : function(data){
90 alert("Error while saving.");
96 $scope.close = function() {
97 $modalInstance.close();
100 function extend(obj, src) {
101 for (var key in src) {
102 if (src.hasOwnProperty(key)) obj[key] = src[key];
107 $scope.attributeDatas = [{"attributes" : $scope.apchoices}];
108 $scope.addAPNewChoice = function() {
109 var newItemNo = $scope.apchoices.length+1;
110 $scope.apchoices.push({'id':'choice'+newItemNo});
112 $scope.removeAPChoice = function() {
113 var lastItem = $scope.apchoices.length-1;
114 $scope.apchoices.splice(lastItem);