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 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
69 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
75 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
81 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
83 $scope.data = JSON.parse(j.data);
84 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
87 $scope.temp.policy.dynamicLayoutMap = {};
88 $scope.addDataToFields = function(ruleName){
90 var uuu = "policyController/getBRMSTemplateData.htm";
91 var postData={policyData: ruleName};
96 contentType: 'application/json',
97 data: JSON.stringify(postData),
98 success : function(data){
99 $scope.$apply(function(){
100 $scope.temp.policy.dynamicLayoutMap = data.policyData;
103 error : function(data){
104 Notification.error("Error While Retriving the Template Layout Pattren.");
110 $scope.showbrmsrule = true;
112 $scope.ShowRule = function(policy){
113 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
114 var postData={policyData: policy};
119 contentType: 'application/json',
120 data: JSON.stringify(postData),
121 success : function(data){
122 $scope.showbrmsrule = false;
123 $scope.validateSuccess = true;
124 $scope.$apply(function(){
125 $scope.datarule = data.policyData;
128 error : function(data){
129 Notification.error("Error Occured while Showing Rule.");
134 $scope.hideRule = function(){
135 $scope.showbrmsrule = true;
136 $scope.validateSuccess = false;
140 $scope.saveBrmsParamPolicy = function(policy){
141 if(policy.itemContent != undefined){
142 $scope.refreshCheck = true;
143 $scope.policyNavigator = policy.itemContent;
144 policy.itemContent = "";
146 $scope.savebutton = false;
147 var uuu = "policycreation/save_policy";
148 var postData={policyData: policy};
153 contentType: 'application/json',
154 data: JSON.stringify(postData),
155 success : function(data){
156 $scope.$apply(function(){
157 $scope.data=data.policyData;
158 if($scope.data == 'success'){
159 $scope.temp.policy.readOnly = 'true';
160 $scope.safetyChecker = data.policyData.split("#")[2];
161 if ($scope.safetyChecker!=undefined) {
162 Notification.success($scope.safetyChecker);
164 Notification.success("Policy Saved Successfully.");
165 }else if ($scope.data == 'PolicyExists'){
166 $scope.savebutton = true;
167 Notification.error("Policy Already Exists with Same Name in Scope.");
171 error : function(data){
172 Notification.error("Error Occured while saving Policy.");
173 $scope.savebutton = true;
178 $scope.validatePolicy = function(policy){
179 document.getElementById("validate").innerHTML = "";
180 var uuu = "policyController/validate_policy.htm";
181 var postData={policyData: policy};
186 contentType: 'application/json',
187 data: JSON.stringify(postData),
188 success : function(data){
189 $scope.$apply(function(){
190 $scope.validateData = data.data.replace(/\"/g, "");
191 $scope.data=data.data.substring(1,8);
192 var size = data.data.length;
193 if($scope.data == 'success'){
194 Notification.success("Validation Success.");
195 $scope.savebutton = false;
197 var displayWarning = data.data.substring(19,size);
198 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
199 document.getElementById("validate").style.color = "white";
200 document.getElementById("validate").style.backgroundColor = "skyblue";
202 $scope.validateSuccess = false;
204 Notification.error("Validation Failed.");
205 document.getElementById("validate").innerHTML = $scope.validateData;
206 document.getElementById("validate").style.color = "white";
207 document.getElementById("validate").style.backgroundColor = "red";
208 $scope.savebutton = true;
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 = [];
223 if($scope.temp.policy.attributes.length == 0){
224 $scope.temp.policy.attributes = [];
228 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
229 $scope.addNewChoice = function() {
230 var newItemNo = $scope.temp.policy.attributes.length+1;
231 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
233 $scope.removeChoice = function() {
234 var lastItem = $scope.temp.policy.attributes.length-1;
235 $scope.temp.policy.attributes.splice(lastItem);