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('brmsRawPolicyController', function ($scope, $window, PolicyDictionaryService, PapUrlService, modalService, $modal, Notification) {
27 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
29 PapUrlService.getPapUrl().then(function(data) {
31 papUrl = config.PAP_URL;
34 PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
36 $scope.data = JSON.parse(j.data);
37 console.log($scope.data);
38 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
39 console.log($scope.riskTypeDictionaryDatas);
41 console.log("failed");
43 PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
45 $scope.data = JSON.parse(j.data);
46 console.log($scope.data);
47 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
48 console.log($scope.riskLevelDatas);
50 console.log("failed");
52 PolicyDictionaryService.getGuardValueData().then(function (data) {
54 $scope.data = JSON.parse(j.data);
55 console.log($scope.data);
56 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
57 console.log($scope.guardDatas);
59 console.log("failed");
62 $scope.saveBrmsRawPolicy = function(policy){
64 /* var finalData = extend(policy, $scope.attributeDatas[0]);*/
65 var uuu = "policyController/save_BRMSRawPolicy.htm";
66 var postData={policyData: policy};
71 contentType: 'application/json',
72 data: JSON.stringify(postData),
73 success : function(data){
74 $scope.$apply(function(){
75 $scope.data=data.data;
76 $scope.temp.policy.readOnly = 'true';
77 Notification.success("Policy Saved Successfully.");
79 console.log($scope.data);
80 $modalInstance.close();
83 error : function(data){
84 Notification.error("Error Occured while saving Policy.");
89 $scope.validatePolicy = function(policy){
91 var uuu = "policyController/validate_policy.htm";
92 var postData={policyData: policy};
97 contentType: 'application/json',
98 data: JSON.stringify(postData),
99 success : function(data){
100 $scope.$apply(function(){
101 $scope.data=data.data.substring(1,8);
102 var size = data.data.length;
103 if($scope.data == 'success'){
104 Notification.success("Validation Success.");
106 var displayWarning = data.data.substring(19,size);
107 window.alert(displayWarning);
110 Notification.error("Validation Failed.");
114 console.log($scope.data);
115 /*$modalInstance.close();*/
118 error : function(data){
119 Notification.error("Validation Failed.");
124 function extend(obj, src) {
125 for (var key in src) {
126 if (src.hasOwnProperty(key)) obj[key] = src[key];
131 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
132 $scope.temp.policy.attributes = [];
134 if($scope.temp.policy.attributes.length == 0){
135 $scope.temp.policy.attributes = [];
138 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
139 $scope.addNewChoice = function() {
140 var newItemNo = $scope.temp.policy.attributes.length+1;
141 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
143 $scope.removeChoice = function() {
144 var lastItem = $scope.temp.policy.attributes.length-1;
145 $scope.temp.policy.attributes.splice(lastItem);