2 * ============LICENSE_START=======================================================
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
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',
21 ['$scope', '$window', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification',
22 function ($scope, $window, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
25 $scope.policyNavigator;
26 $scope.savebutton = true;
27 $scope.refreshCheck = false;
29 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
30 $scope.temp.policy = {
31 policyType : "Config",
32 configPolicyType : "BRMS_Param"
36 $scope.refresh = function(){
37 if($scope.refreshCheck){
38 $scope.policyNavigator.refresh();
40 $scope.modal('createNewPolicy', true);
41 $scope.temp.policy = "";
44 $scope.modal = function(id, hide) {
45 return $('#' + id).modal(hide ? 'hide' : 'show');
48 $('#ttlDate').datepicker({
49 dateFormat: 'dd/mm/yy',
52 onSelect: function(date) {
53 angular.element($('#ttlDate')).triggerHandler('input');
57 $scope.validateSuccess = true;
58 var readValue = $scope.temp.policy.readOnly;
60 $scope.validateSuccess = false;
63 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
65 $scope.data = JSON.parse(j.data);
66 console.log($scope.data);
67 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
68 console.log($scope.brmsControllerDatas);
70 console.log("failed");
73 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
75 $scope.data = JSON.parse(j.data);
76 console.log($scope.data);
77 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
78 console.log($scope.brmsDependencyDatas);
80 console.log("failed");
83 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
85 $scope.data = JSON.parse(j.data);
86 console.log($scope.data);
87 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
88 console.log($scope.brmsParamDictionaryDatas);
90 console.log("failed");
93 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
95 $scope.data = JSON.parse(j.data);
96 console.log($scope.data);
97 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
98 console.log($scope.riskTypeDictionaryDatas);
100 console.log("failed");
103 $scope.temp.policy.dynamicLayoutMap = {};
104 $scope.addDataToFields = function(ruleName){
105 console.log(ruleName);
106 if(ruleName != null){
107 var uuu = "policyController/getBRMSTemplateData.htm";
108 var postData={policyData: ruleName};
113 contentType: 'application/json',
114 data: JSON.stringify(postData),
115 success : function(data){
116 $scope.$apply(function(){
117 $scope.temp.policy.dynamicLayoutMap = data.policyData;
119 console.log( $scope.temp.policy.dynamicLayoutMap);
121 error : function(data){
122 Notification.error("Error While Retriving the Template Layout Pattren.");
128 $scope.showbrmsrule = true;
130 $scope.ShowRule = function(policy){
132 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
133 var postData={policyData: policy};
138 contentType: 'application/json',
139 data: JSON.stringify(postData),
140 success : function(data){
141 $scope.showbrmsrule = false;
142 $scope.validateSuccess = true;
143 $scope.$apply(function(){
144 $scope.datarule = data.policyData;
147 error : function(data){
148 Notification.error("Error Occured while Showing Rule.");
153 $scope.hideRule = function(){
154 $scope.showbrmsrule = true;
155 $scope.validateSuccess = false;
159 $scope.saveBrmsParamPolicy = function(policy){
160 if(policy.itemContent != undefined){
161 $scope.refreshCheck = true;
162 $scope.policyNavigator = policy.itemContent;
163 policy.itemContent = "";
165 $scope.savebutton = false;
166 var uuu = "policycreation/save_policy";
167 var postData={policyData: policy};
172 contentType: 'application/json',
173 data: JSON.stringify(postData),
174 success : function(data){
175 $scope.$apply(function(){
176 $scope.data=data.policyData;
177 if($scope.data == 'success'){
178 $scope.temp.policy.readOnly = 'true';
179 $scope.safetyChecker = data.policyData.split("#")[2];
180 if ($scope.safetyChecker!=undefined) {
181 Notification.success($scope.safetyChecker);
183 Notification.success("Policy Saved Successfully.");
184 }else if ($scope.data == 'PolicyExists'){
185 $scope.savebutton = true;
186 Notification.error("Policy Already Exists with Same Name in Scope.");
189 console.log($scope.data);
191 error : function(data){
192 Notification.error("Error Occured while saving Policy.");
193 $scope.savebutton = true;
198 $scope.validatePolicy = function(policy){
200 document.getElementById("validate").innerHTML = "";
201 var uuu = "policyController/validate_policy.htm";
202 var postData={policyData: policy};
207 contentType: 'application/json',
208 data: JSON.stringify(postData),
209 success : function(data){
210 $scope.$apply(function(){
211 $scope.validateData = data.data.replace(/\"/g, "");
212 $scope.data=data.data.substring(1,8);
213 var size = data.data.length;
214 if($scope.data == 'success'){
215 Notification.success("Validation Success.");
216 $scope.savebutton = false;
218 var displayWarning = data.data.substring(19,size);
219 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
220 document.getElementById("validate").style.color = "white";
221 document.getElementById("validate").style.backgroundColor = "skyblue";
223 $scope.validateSuccess = false;
225 Notification.error("Validation Failed.");
226 document.getElementById("validate").innerHTML = $scope.validateData;
227 document.getElementById("validate").style.color = "white";
228 document.getElementById("validate").style.backgroundColor = "red";
229 $scope.savebutton = true;
233 console.log($scope.data);
235 error : function(data){
236 Notification.error("Validation Failed.");
237 $scope.savebutton = true;
242 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
243 $scope.temp.policy.attributes = [];
245 if($scope.temp.policy.attributes.length == 0){
246 $scope.temp.policy.attributes = [];
250 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
251 $scope.addNewChoice = function() {
252 var newItemNo = $scope.temp.policy.attributes.length+1;
253 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
255 $scope.removeChoice = function() {
256 var lastItem = $scope.temp.policy.attributes.length-1;
257 $scope.temp.policy.attributes.splice(lastItem);