Remove unused vars and methods
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / BaseConfigPolicyController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 2019 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('baseConfigController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification',  function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
21     $("#dialog").hide();
22     
23    
24     $scope.policyNavigator;
25     $scope.savebutton = true;
26     $scope.refreshCheck = false;
27     
28     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
29         $scope.temp.policy = {
30                 policyType : "Config",
31                 configPolicyType : "Base"
32         }
33     }
34     
35     $scope.refresh = function(){
36         if($scope.refreshCheck){
37                 $scope.policyNavigator.refresh();
38         }
39         $scope.modal('createNewPolicy', true);
40         $scope.temp.policy = "";
41     };
42     
43     $scope.modal = function(id, hide) {
44         return $('#' + id).modal(hide ? 'hide' : 'show');
45     };
46     
47     $('#ttlDate').datepicker({
48         dateFormat: 'dd/mm/yy',
49         changeMonth: true,
50         changeYear: true,
51         onSelect: function(date) {
52                 angular.element($('#ttlDate')).triggerHandler('input');
53         }
54     });
55     
56     PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
57         var j = data;  
58         $scope.data = JSON.parse(j.data);
59         console.log($scope.data);
60         $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
61         console.log($scope.onapNameDictionaryDatas);
62     }, function (error) {
63         console.log("failed");
64     });
65
66     PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
67         var j = data;
68         $scope.data = JSON.parse(j.data);
69         console.log($scope.data);
70         $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
71         console.log($scope.attributeDictionaryDatas);
72     }, function (error) {
73         console.log("failed");
74     });
75
76     PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
77         var j = data;
78         $scope.data = JSON.parse(j.data);
79         console.log($scope.data);
80         $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
81         console.log($scope.riskTypeDictionaryDatas);
82     }, function (error) {
83         console.log("failed");
84     });
85     
86     $scope.savePolicy = function(policy){
87         if(policy.itemContent != undefined){
88                 $scope.refreshCheck = true; 
89                 $scope.policyNavigator = policy.itemContent;
90                 policy.itemContent = "";
91         }
92         $scope.savebutton = false;
93         var uuu = "policycreation/save_policy";
94                 var postData={policyData: policy};
95                 $.ajax({
96                         type : 'POST',
97                         url : uuu,
98                         dataType: 'json',
99                         contentType: 'application/json',
100                         data: JSON.stringify(postData),
101                         success : function(data){
102                                 $scope.$apply(function(){
103                                         $scope.data=data.policyData;
104                                         if($scope.data == 'success'){
105                                                 $scope.temp.policy.readOnly = 'true';
106                                                 Notification.success("Policy Saved Successfully.");     
107                                         }else if ($scope.data == 'PolicyExists'){
108                                                 $scope.savebutton = true;
109                                                 Notification.error("Policy Already Exists with Same Name in Scope.");
110                                         }
111                                 });
112                         },
113                         error : function(data){
114                                 Notification.error("Error Occured while saving Policy.");
115                                 $scope.savebutton = true;
116                         }
117                 });
118     };
119     
120  
121     $scope.validatePolicy = function(policy){
122         $scope.scope = policy.domain;
123         document.getElementById("validate").innerHTML = "";
124         var uuu = "policyController/validate_policy.htm";
125                 var postData={policyData: policy};
126                 $.ajax({
127                         type : 'POST',
128                         url : uuu,
129                         dataType: 'json',
130                         contentType: 'application/json',
131                         data: JSON.stringify(postData),
132                         success : function(data){
133                                 $scope.$apply(function(){
134                                         $scope.validateData = data.data.replace(/\"/g, "");
135                                         $scope.data=data.data.substring(1,8);
136                                         var size = data.data.length;
137                                         if($scope.data == 'success'){
138                                                 Notification.success("Validation Success.");
139                                                 $scope.savebutton = false;
140                                                 if (size > 18){
141                                                         var displayWarning = data.data.substring(19,size);
142                                                         document.getElementById("validate").innerHTML = "Safe Policy Warning Message  :  "+displayWarning;
143                                                         document.getElementById("validate").style.color = "white";
144                                                         document.getElementById("validate").style.backgroundColor = "skyblue";
145                                                 }
146                                         }else{
147                                                 Notification.error("Validation Failed.");
148                                                 document.getElementById("validate").innerHTML = $scope.validateData;
149                                                 document.getElementById("validate").style.color = "white";
150                                                 document.getElementById("validate").style.backgroundColor = "red";
151                                                 $scope.savebutton = true;
152                                         }               
153                                 });                     
154                         },
155                         error : function(data){ 
156                                 Notification.error("Validation Failed.");
157                                 $scope.savebutton = true;
158                         }
159                 }); 
160     };
161     
162     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
163         $scope.temp.policy.attributes = [];
164     }else{
165            if($scope.temp.policy.attributes.length == 0){
166                    $scope.temp.policy.attributes = [];
167            }
168    }
169     
170     
171     $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
172     $scope.addNewChoice = function() {
173         var newItemNo = $scope.temp.policy.attributes .length+1;
174         $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
175     };
176     $scope.removeChoice = function() {
177         var lastItem = $scope.temp.policy.attributes.length-1;
178         $scope.temp.policy.attributes.splice(lastItem);
179     };
180 }]);