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 angular.module('abs').controller('fwPolicyController', ['$scope', '$window', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.savebutton = true;
25 $scope.refreshCheck = false;
27 $scope.refresh = function(){
28 if($scope.refreshCheck){
29 $scope.policyNavigator.refresh();
31 $scope.modal('createNewPolicy', true);
32 $scope.temp.policy = "";
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 $('#ttlDate').datepicker({
40 dateFormat: 'dd/mm/yy',
43 onSelect: function(date) {
44 angular.element($('#ttlDate')).triggerHandler('input');
48 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
50 $scope.data = JSON.parse(j.data);
51 console.log($scope.data);
52 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
53 console.log($scope.securityZoneDictionaryDatas);
55 console.log("failed");
58 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
60 $scope.data = JSON.parse(j.data);
61 console.log($scope.data);
62 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
63 console.log($scope.termListDictionaryDatas);
65 console.log("failed");
68 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
70 $scope.data = JSON.parse(j.data);
71 console.log($scope.data);
72 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
73 console.log($scope.fwDictListDictionaryDatas);
75 console.log("failed");
78 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
80 $scope.data = JSON.parse(j.data);
81 console.log($scope.data);
82 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
83 console.log($scope.fwParentListDictionaryDatas);
85 console.log("failed");
88 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
90 $scope.data = JSON.parse(j.data);
91 console.log($scope.data);
92 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
93 console.log($scope.fwTagPickerDictionaryDatas);
95 console.log("failed");
98 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
100 $scope.data = JSON.parse(j.data);
101 console.log($scope.data);
102 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
103 console.log($scope.riskTypeDictionaryDatas);
104 }, function (error) {
105 console.log("failed");
108 function extend(obj, src) {
109 for (var key in src) {
110 if (src.hasOwnProperty(key)) obj[key] = src[key];
115 $scope.viewFWRule = function(policy){
117 var uuu = "policyController/ViewFWPolicyRule.htm";
118 var postData={policyData: policy};
123 contentType: 'application/json',
124 data: JSON.stringify(postData),
125 success : function(data){
126 $scope.$apply(function(){
127 window.alert(data.policyData);
130 error : function(data){
131 Notification.error("Error Occured while Showing Rule.");
137 $scope.saveFWPolicy = function(policy){
138 if(policy.itemContent != undefined){
139 $scope.refreshCheck = true;
140 $scope.policyNavigator = policy.itemContent;
141 policy.itemContent = "";
143 $scope.savebutton = false;
145 var uuu = "policycreation/save_policy";
146 var postData={policyData: policy};
151 contentType: 'application/json',
152 data: JSON.stringify(postData),
153 success : function(data){
154 $scope.$apply(function(){
155 $scope.data=data.policyData;
156 if($scope.data == 'success'){
157 $scope.temp.policy.readOnly = 'true';
158 $scope.pushStatus=data.policyData.split("&")[1];
159 if($scope.pushStatus=="successPush"){
160 Notification.success("Policy pushed successfully");
162 Notification.success("Policy Saved Successfully.");
163 }else if ($scope.data == 'PolicyExists'){
164 $scope.savebutton = true;
165 Notification.error("Policy Already Exists with Same Name in Scope.");
168 console.log($scope.data);
170 error : function(data){
171 Notification.error("Error Occured while saving Policy.");
176 $scope.validatePolicy = function(policy){
178 document.getElementById("validate").innerHTML = "";
179 var uuu = "policyController/validate_policy.htm";
180 var postData={policyData: policy};
185 contentType: 'application/json',
186 data: JSON.stringify(postData),
187 success : function(data){
188 $scope.$apply(function(){
189 $scope.validateData = data.data.replace(/\"/g, "");
190 $scope.data=data.data.substring(1,8);
191 var size = data.data.length;
192 if($scope.data == 'success'){
193 Notification.success("Validation Success.");
194 $scope.savebutton = false;
196 var displayWarning = data.data.substring(19,size);
197 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
198 document.getElementById("validate").style.color = "white";
199 document.getElementById("validate").style.backgroundColor = "skyblue";
202 Notification.error("Validation Failed.");
203 document.getElementById("validate").innerHTML = $scope.validateData;
204 document.getElementById("validate").style.color = "white";
205 document.getElementById("validate").style.backgroundColor = "red";
206 $scope.savebutton = true;
210 console.log($scope.data);
213 error : function(data){
214 Notification.error("Validation Failed.");
215 $scope.savebutton = true;
220 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
221 $scope.temp.policy.attributes = [];
222 $scope.temp.policy.fwattributes = [];
224 if($scope.temp.policy.attributes.length == 0){
225 $scope.temp.policy.attributes = [];
227 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
228 if($scope.temp.policy.fwattributes.length == 0){
229 $scope.temp.policy.fwattributes = [];
234 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
235 $scope.addNewChoice = function() {
236 var newItemNo = $scope.temp.policy.attributes.length+1;
237 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
239 $scope.removeChoice = function() {
240 var lastItem = $scope.temp.policy.attributes.length-1;
241 $scope.temp.policy.attributes.splice(lastItem);
244 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
245 $scope.addNewFWDictList = function() {
246 var newItemNo = $scope.temp.policy.fwattributes.length+1;
247 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
249 $scope.removefwDictChoice = function() {
250 var lastItem = $scope.temp.policy.fwattributes.length-1;
251 $scope.temp.policy.fwattributes.splice(lastItem);