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=========================================================
24 angular.module('abs').controller('brmsParamPolicyController', function ($scope, $window, PolicyDictionaryService, PapUrlService, modalService, $modal, Notification) {
27 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
28 $scope.validateSuccess = true;
29 var readValue = $scope.temp.policy.readOnly;
31 $scope.validateSuccess = false;
35 PapUrlService.getPapUrl().then(function(data) {
37 papUrl = config.PAP_URL;
40 PolicyDictionaryService.getBRMSParamDictionaryData(papUrl).then(function (data) {
42 $scope.data = JSON.parse(j.data);
43 console.log($scope.data);
44 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
45 console.log($scope.brmsParamDictionaryDatas);
47 console.log("failed");
49 PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
54 console.log($scope.riskTypeDictionaryDatas);
56 console.log("failed");
58 PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
60 $scope.data = JSON.parse(j.data);
61 console.log($scope.data);
62 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
63 console.log($scope.riskLevelDatas);
65 console.log("failed");
67 PolicyDictionaryService.getGuardValueData().then(function (data) {
69 $scope.data = JSON.parse(j.data);
70 console.log($scope.data);
71 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
72 console.log($scope.guardDatas);
74 console.log("failed");
78 $scope.temp.policy.dynamicLayoutMap = [];
79 $scope.addDataToFields = function(ruleName){
80 console.log(ruleName);
82 var uuu = "policyController/getBRMSTemplateData.htm";
83 var postData={policyData: ruleName};
88 contentType: 'application/json',
89 data: JSON.stringify(postData),
90 success : function(data){
91 $scope.$apply(function(){
92 $scope.temp.policy.dynamicLayoutMap = data.policyData;
94 console.log( $scope.temp.policy.dynamicLayoutMap);
96 error : function(data){
97 alert("Error While Retriving the Template Layout Pattren.");
103 $scope.ShowRule = function(policy){
105 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
106 var postData={policyData: policy};
111 contentType: 'application/json',
112 data: JSON.stringify(postData),
113 success : function(data){
114 $scope.$apply(function(){
115 window.alert(data.policyData);
118 error : function(data){
119 Notification.error("Error Occured while Showing Rule.");
124 $scope.saveBrmsParamPolicy = function(policy){
126 var uuu = "policyController/save_BRMSParamPolicy.htm";
127 var postData={policyData: policy};
132 contentType: 'application/json',
133 data: JSON.stringify(postData),
134 success : function(data){
135 $scope.$apply(function(){
136 $scope.data=data.data;
137 $scope.temp.policy.readOnly = 'true';
138 Notification.success("Policy Saved Successfully.");
140 console.log($scope.data);
141 $modalInstance.close();
144 error : function(data){
145 Notification.error("Error Occured while saving Policy.");
150 $scope.validatePolicy = function(policy){
152 var uuu = "policyController/validate_policy.htm";
153 var postData={policyData: policy};
158 contentType: 'application/json',
159 data: JSON.stringify(postData),
160 success : function(data){
161 $scope.$apply(function(){
162 $scope.data=data.data.substring(1,8);
163 var size = data.data.length;
164 if($scope.data == 'success'){
165 Notification.success("Validation Success.");
167 var displayWarning = data.data.substring(19,size);
168 window.alert(displayWarning);
170 $scope.validateSuccess = false;
172 Notification.error("Validation Failed.");
176 console.log($scope.data);
177 /*$modalInstance.close();*/
180 error : function(data){
181 Notification.error("Validation Failed.");
186 function extend(obj, src) {
187 for (var key in src) {
188 if (src.hasOwnProperty(key)) obj[key] = src[key];
193 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
194 $scope.temp.policy.attributes = [];
196 if($scope.temp.policy.attributes.length == 0){
197 $scope.temp.policy.attributes = [];
201 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
202 $scope.addNewChoice = function() {
203 var newItemNo = $scope.temp.policy.attributes.length+1;
204 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
206 $scope.removeChoice = function() {
207 var lastItem = $scope.temp.policy.attributes.length-1;
208 $scope.temp.policy.attributes.splice(lastItem);