Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / SafePolicyWarningDictController.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 editSafePolicyWarningController =  function ($scope, $modalInstance, message, SafePolicyService, PapUrlService, UserInfoService, Notification){
24         $scope.edit = false;
25     if(message.safePolicyWarningData==null)
26         $scope.label='Add New Safe Policy Warning'
27     else{
28         $scope.label='Edit Safe Policy Warning'
29         $scope.disableCd=true;
30         $scope.edit = true;
31     }
32     
33         var papUrl;
34         PapUrlService.getPapUrl().then(function(data) {
35                 var config = data;
36                 papUrl = config.PAP_URL;
37                 console.log(papUrl);
38             
39                 SafePolicyService.getSafePolicyWarningDictionaryDataByName(papUrl).then(function (data) {
40                 var j = data;
41                 $scope.data = JSON.parse(j.data);
42                 console.log($scope.data);
43                 $scope.safePolicyWarningDatas = JSON.parse($scope.data.safePolicyWarningDatas);
44                 console.log($scope.safePolicyWarningDatas);
45             }, function (error) {
46                 console.log("failed");
47             });
48                 SafePolicyService.getRiskTypeDictionaryDataByName(papUrl).then(function (data) {
49                 var j = data;
50                 $scope.data = JSON.parse(j.data);
51                 console.log($scope.data);
52                 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
53                 console.log($scope.riskTypeDictionaryDatas);
54             }, function (error) {
55                 console.log("failed");
56             });
57         });
58         
59         /*getting user info from session*/
60         var loginId = null;
61         UserInfoService.getFunctionalMenuStaticDetailSession()
62                 .then(function (response) {                     
63                         loginId = response.userid;              
64          });
65    
66     $scope.editSafePolicyWarning = message.safePolicyWarningData;
67     $scope.editSafePolicyWarning1 = {resource: [], type:[], service: [], closedloop: []};
68     if($scope.edit){
69         if(message.safePolicyWarningData.groupList != null){
70                 var splitValue = message.safePolicyWarningData.groupList.split(",");
71                 console.log(splitValue);
72                 $scope.splittedGroupListValues = [];
73                 var splitResource = splitValue[0].split("=");
74                 $scope.editSafePolicyWarningScope1.riskType.push(splitResource[1]);
75         }       
76     }
77     
78     $scope.saveSafePolicyWarning = function(safePolicyWarningData) {
79         console.log(safePolicyWarningData);
80         var uuu = papUrl + "/ecomp/sp_dictionary/save_safePolicyWarning.htm";
81         var postData={safePolicyWarningData: safePolicyWarningData, loginId: loginId};
82         $.ajax({
83             type : 'POST',
84             url : uuu,
85             dataType: 'json',
86             contentType: 'application/json',
87             data: JSON.stringify(postData),
88             success : function(data){
89                 $scope.$apply(function(){
90                     $scope.safePolicyWarningDatas=data.safePolicyWarningDatas;});
91                 if($scope.safePolicyWarningDatas == "Duplicate"){
92                         Notification.error("Safe Policy Dictionary exists with Same Name.")
93                 }else{      
94                         console.log($scope.safePolicyWarningDatas);
95                     $modalInstance.close({safePolicyWarningDatas:$scope.safePolicyWarningDatas});
96                 }
97             },
98             error : function(data){
99                 alert("Error while saving.");
100             }
101         });
102     };
103
104     $scope.close = function() {
105         $modalInstance.close();
106     };
107 }