[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / FWPrefixListDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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 app.controller('editFWPrefixListController' ,  function ($scope, $modalInstance, message, Notification, UserInfoServiceDS2, Notification){
21         $scope.validate = 'false';
22     if(message.prefixListDictionaryData==null)
23         $scope.label='Add PrefixList'
24     else{
25         $scope.label='Edit PrefixList'
26         $scope.disableCd=true;
27     }
28         
29         /*getting user info from session*/
30         var userid = null;
31         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
32                 .then(function (response) {                     
33                         userid = response.userid;               
34          });
35         
36     $scope.editPrefixList = message.prefixListDictionaryData;
37
38     $scope.saveFWPrefixList = function(prefixListDictionaryData) {
39         var regex = new RegExp("^[a-zA-Z0-9_]*$");
40         if(!regex.test(prefixListDictionaryData.prefixListName)) {
41                 Notification.error("Enter Valid PrefixList Name without spaces or special characters");
42         }else{
43                 if($scope.validate == 'true'){
44                         var uuu = "saveDictionary/fw_dictionary/save_prefixList";
45                         var postData={prefixListDictionaryData: prefixListDictionaryData, userid: userid};
46                         $.ajax({
47                                 type : 'POST',
48                                 url : uuu,
49                                 dataType: 'json',
50                                 contentType: 'application/json',
51                                 data: JSON.stringify(postData),
52                                 success : function(data){
53                                         $scope.$apply(function(){
54                                                 $scope.prefixListDictionaryDatas=data.prefixListDictionaryDatas;});
55                                         if($scope.prefixListDictionaryDatas == "Duplicate"){
56                                                 Notification.error("FW PrefixList Dictionary exists with Same PrefixList Name.")
57                                         }else{      
58                                                 console.log($scope.prefixListDictionaryDatas);
59                                                 $modalInstance.close({prefixListDictionaryDatas:$scope.prefixListDictionaryDatas});
60                                         }
61                                 },
62                                 error : function(data){
63                                         alert("Error while saving.");
64                                 }
65                         });
66                 }else{
67                         Notification.error('Prefix List Validation is Not Successful');
68                 }
69         }
70     };
71
72     $scope.validateFWPrefixList = function(prefixListDictionaryData) {
73         var uuu = "saveDictionary/fw_dictionary/validate_prefixList";
74         var postData={prefixListDictionaryData: prefixListDictionaryData};
75         $.ajax({
76             type : 'POST',
77             url : uuu,
78             dataType: 'json',
79             contentType: 'application/json',
80             data: JSON.stringify(postData),
81             success : function(data){
82                 $scope.$apply(function(){
83                 $scope.result=data.result;});
84                 console.log($scope.result);
85                 if($scope.result == 'error'){
86                         Notification.error('IP not according to CIDR notation');
87                 }else{
88                         $scope.validate = 'true';
89                         Notification.success('Validation Success');
90                 }
91             }
92         });
93     };
94     
95     $scope.close = function() {
96         $modalInstance.close();
97     };
98 });