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('brmsParamPolicyController', ['$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 $scope.validateSuccess = true;
40 var readValue = $scope.temp.policy.readOnly;
42 $scope.validateSuccess = false;
45 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
50 console.log($scope.brmsControllerDatas);
52 console.log("failed");
55 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
60 console.log($scope.brmsDependencyDatas);
62 console.log("failed");
65 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
70 console.log($scope.brmsParamDictionaryDatas);
72 console.log("failed");
75 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 console.log($scope.data);
79 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
80 console.log($scope.riskTypeDictionaryDatas);
82 console.log("failed");
85 $scope.temp.policy.dynamicLayoutMap = {};
86 $scope.addDataToFields = function(ruleName){
87 console.log(ruleName);
89 var uuu = "policyController/getBRMSTemplateData.htm";
90 var postData={policyData: ruleName};
95 contentType: 'application/json',
96 data: JSON.stringify(postData),
97 success : function(data){
98 $scope.$apply(function(){
99 $scope.temp.policy.dynamicLayoutMap = data.policyData;
101 console.log( $scope.temp.policy.dynamicLayoutMap);
103 error : function(data){
104 alert("Error While Retriving the Template Layout Pattren.");
110 $scope.showbrmsrule = true;
112 $scope.ShowRule = function(policy){
114 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
115 var postData={policyData: policy};
120 contentType: 'application/json',
121 data: JSON.stringify(postData),
122 success : function(data){
123 $scope.showbrmsrule = false;
124 $scope.validateSuccess = true;
125 $scope.$apply(function(){
126 $scope.datarule = data.policyData;
129 error : function(data){
130 Notification.error("Error Occured while Showing Rule.");
135 $scope.hideRule = function(){
136 $scope.showbrmsrule = true;
137 $scope.validateSuccess = false;
141 $scope.saveBrmsParamPolicy = function(policy){
142 if(policy.itemContent != undefined){
143 $scope.refreshCheck = true;
144 $scope.policyNavigator = policy.itemContent;
145 policy.itemContent = "";
147 $scope.savebutton = false;
148 var uuu = "policycreation/save_policy";
149 var postData={policyData: policy};
154 contentType: 'application/json',
155 data: JSON.stringify(postData),
156 success : function(data){
157 $scope.$apply(function(){
158 $scope.data=data.policyData;
159 if($scope.data == 'success'){
160 $scope.temp.policy.readOnly = 'true';
161 $scope.safetyChecker = data.policyData.split("#")[2];
162 if ($scope.safetyChecker!=undefined) {
163 Notification.success($scope.safetyChecker);
165 Notification.success("Policy Saved Successfully.");
166 }else if ($scope.data == 'PolicyExists'){
167 $scope.savebutton = true;
168 Notification.error("Policy Already Exists with Same Name in Scope.");
171 console.log($scope.data);
173 error : function(data){
174 Notification.error("Error Occured while saving Policy.");
175 $scope.savebutton = true;
180 $scope.validatePolicy = function(policy){
182 document.getElementById("validate").innerHTML = "";
183 var uuu = "policyController/validate_policy.htm";
184 var postData={policyData: policy};
189 contentType: 'application/json',
190 data: JSON.stringify(postData),
191 success : function(data){
192 $scope.$apply(function(){
193 $scope.validateData = data.data.replace(/\"/g, "");
194 $scope.data=data.data.substring(1,8);
195 var size = data.data.length;
196 if($scope.data == 'success'){
197 Notification.success("Validation Success.");
198 $scope.savebutton = false;
200 var displayWarning = data.data.substring(19,size);
201 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
202 document.getElementById("validate").style.color = "white";
203 document.getElementById("validate").style.backgroundColor = "skyblue";
205 $scope.validateSuccess = false;
207 Notification.error("Validation Failed.");
208 document.getElementById("validate").innerHTML = $scope.validateData;
209 document.getElementById("validate").style.color = "white";
210 document.getElementById("validate").style.backgroundColor = "red";
211 $scope.savebutton = true;
215 console.log($scope.data);
217 error : function(data){
218 Notification.error("Validation Failed.");
219 $scope.savebutton = true;
224 function extend(obj, src) {
225 for (var key in src) {
226 if (src.hasOwnProperty(key)) obj[key] = src[key];
231 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
232 $scope.temp.policy.attributes = [];
234 if($scope.temp.policy.attributes.length == 0){
235 $scope.temp.policy.attributes = [];
239 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
240 $scope.addNewChoice = function() {
241 var newItemNo = $scope.temp.policy.attributes.length+1;
242 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
244 $scope.removeChoice = function() {
245 var lastItem = $scope.temp.policy.attributes.length-1;
246 $scope.temp.policy.attributes.splice(lastItem);