Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / FWPrefixListDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 /**
22  */
23 var editFWPrefixListController =  function ($scope, $modalInstance, message, Notification, PapUrlService, UserInfoService, Notification){
24         $scope.validate = 'false';
25     if(message.prefixListDictionaryData==null)
26         $scope.label='Add PrefixList'
27     else{
28         $scope.label='Edit PrefixList'
29         $scope.disableCd=true;
30     }
31     
32         var papUrl;
33         PapUrlService.getPapUrl().then(function(data) {
34                 var config = data;
35                 papUrl = config.PAP_URL;
36                 console.log(papUrl);
37         });
38         
39         /*getting user info from session*/
40         var loginId = null;
41         UserInfoService.getFunctionalMenuStaticDetailSession()
42                 .then(function (response) {                     
43                         loginId = response.userid;              
44          });
45         
46     $scope.editPrefixList = message.prefixListDictionaryData;
47
48     $scope.saveFWPrefixList = function(prefixListDictionaryData) {
49         if($scope.validate == 'true'){
50                 var uuu = papUrl + "/ecomp/fw_dictionary/save_prefixList.htm";
51             var postData={prefixListDictionaryData: prefixListDictionaryData, loginId: loginId};
52             $.ajax({
53                 type : 'POST',
54                 url : uuu,
55                 dataType: 'json',
56                 contentType: 'application/json',
57                 data: JSON.stringify(postData),
58                 success : function(data){
59                     $scope.$apply(function(){
60                         $scope.prefixListDictionaryDatas=data.prefixListDictionaryDatas;});
61                     if($scope.prefixListDictionaryDatas == "Duplicate"){
62                         Notification.error("FW PrefixList Dictionary exists with Same PrefixList Name.")
63                     }else{      
64                         console.log($scope.prefixListDictionaryDatas);
65                         $modalInstance.close({prefixListDictionaryDatas:$scope.prefixListDictionaryDatas});
66                     }
67                 },
68                 error : function(data){
69                     alert("Error while saving.");
70                 }
71             });
72         }else{
73                 Notification.error('Prefix List Validation is Not Successful');
74         }
75         
76     };
77
78     $scope.validateFWPrefixList = function(prefixListDictionaryData) {
79         var uuu = papUrl + "/ecomp/fw_dictionary/validate_prefixList.htm";
80         var postData={prefixListDictionaryData: prefixListDictionaryData};
81         $.ajax({
82             type : 'POST',
83             url : uuu,
84             dataType: 'json',
85             contentType: 'application/json',
86             data: JSON.stringify(postData),
87             success : function(data){
88                 $scope.$apply(function(){
89                 $scope.result=data.result;});
90                 console.log($scope.result);
91                 if($scope.result == 'error'){
92                         Notification.error('IP not according to CIDR notation');
93                 }else{
94                         $scope.validate = 'true';
95                 }
96             }
97         });
98     };
99     
100     $scope.close = function() {
101         $modalInstance.close();
102     };
103 }