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 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
28 $scope.temp.policy = {
29 policyType : "Config",
30 configPolicyType : "BRMS_Param"
34 $scope.refresh = function(){
35 if($scope.refreshCheck){
36 $scope.policyNavigator.refresh();
38 $scope.modal('createNewPolicy', true);
39 $scope.temp.policy = "";
42 $scope.modal = function(id, hide) {
43 return $('#' + id).modal(hide ? 'hide' : 'show');
46 $('#ttlDate').datepicker({
47 dateFormat: 'dd/mm/yy',
50 onSelect: function(date) {
51 angular.element($('#ttlDate')).triggerHandler('input');
55 $scope.validateSuccess = true;
56 var readValue = $scope.temp.policy.readOnly;
58 $scope.validateSuccess = false;
61 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
63 $scope.data = JSON.parse(j.data);
64 console.log($scope.data);
65 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
66 console.log($scope.brmsControllerDatas);
68 console.log("failed");
71 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
73 $scope.data = JSON.parse(j.data);
74 console.log($scope.data);
75 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
76 console.log($scope.brmsDependencyDatas);
78 console.log("failed");
81 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
83 $scope.data = JSON.parse(j.data);
84 console.log($scope.data);
85 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
86 console.log($scope.brmsParamDictionaryDatas);
88 console.log("failed");
91 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
93 $scope.data = JSON.parse(j.data);
94 console.log($scope.data);
95 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
96 console.log($scope.riskTypeDictionaryDatas);
98 console.log("failed");
101 $scope.temp.policy.dynamicLayoutMap = {};
102 $scope.addDataToFields = function(ruleName){
103 console.log(ruleName);
104 if(ruleName != null){
105 var uuu = "policyController/getBRMSTemplateData.htm";
106 var postData={policyData: ruleName};
111 contentType: 'application/json',
112 data: JSON.stringify(postData),
113 success : function(data){
114 $scope.$apply(function(){
115 $scope.temp.policy.dynamicLayoutMap = data.policyData;
117 console.log( $scope.temp.policy.dynamicLayoutMap);
119 error : function(data){
120 alert("Error While Retriving the Template Layout Pattren.");
126 $scope.showbrmsrule = true;
128 $scope.ShowRule = function(policy){
130 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
131 var postData={policyData: policy};
136 contentType: 'application/json',
137 data: JSON.stringify(postData),
138 success : function(data){
139 $scope.showbrmsrule = false;
140 $scope.validateSuccess = true;
141 $scope.$apply(function(){
142 $scope.datarule = data.policyData;
145 error : function(data){
146 Notification.error("Error Occured while Showing Rule.");
151 $scope.hideRule = function(){
152 $scope.showbrmsrule = true;
153 $scope.validateSuccess = false;
157 $scope.saveBrmsParamPolicy = function(policy){
158 if(policy.itemContent != undefined){
159 $scope.refreshCheck = true;
160 $scope.policyNavigator = policy.itemContent;
161 policy.itemContent = "";
163 $scope.savebutton = false;
164 var uuu = "policycreation/save_policy";
165 var postData={policyData: policy};
170 contentType: 'application/json',
171 data: JSON.stringify(postData),
172 success : function(data){
173 $scope.$apply(function(){
174 $scope.data=data.policyData;
175 if($scope.data == 'success'){
176 $scope.temp.policy.readOnly = 'true';
177 $scope.safetyChecker = data.policyData.split("#")[2];
178 if ($scope.safetyChecker!=undefined) {
179 Notification.success($scope.safetyChecker);
181 Notification.success("Policy Saved Successfully.");
182 }else if ($scope.data == 'PolicyExists'){
183 $scope.savebutton = true;
184 Notification.error("Policy Already Exists with Same Name in Scope.");
187 console.log($scope.data);
189 error : function(data){
190 Notification.error("Error Occured while saving Policy.");
191 $scope.savebutton = true;
196 $scope.validatePolicy = function(policy){
198 document.getElementById("validate").innerHTML = "";
199 var uuu = "policyController/validate_policy.htm";
200 var postData={policyData: policy};
205 contentType: 'application/json',
206 data: JSON.stringify(postData),
207 success : function(data){
208 $scope.$apply(function(){
209 $scope.validateData = data.data.replace(/\"/g, "");
210 $scope.data=data.data.substring(1,8);
211 var size = data.data.length;
212 if($scope.data == 'success'){
213 Notification.success("Validation Success.");
214 $scope.savebutton = false;
216 var displayWarning = data.data.substring(19,size);
217 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
218 document.getElementById("validate").style.color = "white";
219 document.getElementById("validate").style.backgroundColor = "skyblue";
221 $scope.validateSuccess = false;
223 Notification.error("Validation Failed.");
224 document.getElementById("validate").innerHTML = $scope.validateData;
225 document.getElementById("validate").style.color = "white";
226 document.getElementById("validate").style.backgroundColor = "red";
227 $scope.savebutton = true;
231 console.log($scope.data);
233 error : function(data){
234 Notification.error("Validation Failed.");
235 $scope.savebutton = true;
240 function extend(obj, src) {
241 for (var key in src) {
242 if (src.hasOwnProperty(key)) obj[key] = src[key];
247 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
248 $scope.temp.policy.attributes = [];
250 if($scope.temp.policy.attributes.length == 0){
251 $scope.temp.policy.attributes = [];
255 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
256 $scope.addNewChoice = function() {
257 var newItemNo = $scope.temp.policy.attributes.length+1;
258 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
260 $scope.removeChoice = function() {
261 var lastItem = $scope.temp.policy.attributes.length-1;
262 $scope.temp.policy.attributes.splice(lastItem);