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 $('#ttlDate').datepicker({
40 dateFormat: 'dd/mm/yy',
43 onSelect: function(date) {
44 angular.element($('#ttlDate')).triggerHandler('input');
48 $scope.validateSuccess = true;
49 var readValue = $scope.temp.policy.readOnly;
51 $scope.validateSuccess = false;
54 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
56 $scope.data = JSON.parse(j.data);
57 console.log($scope.data);
58 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
59 console.log($scope.brmsControllerDatas);
61 console.log("failed");
64 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
66 $scope.data = JSON.parse(j.data);
67 console.log($scope.data);
68 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
69 console.log($scope.brmsDependencyDatas);
71 console.log("failed");
74 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
76 $scope.data = JSON.parse(j.data);
77 console.log($scope.data);
78 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
79 console.log($scope.brmsParamDictionaryDatas);
81 console.log("failed");
84 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
86 $scope.data = JSON.parse(j.data);
87 console.log($scope.data);
88 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
89 console.log($scope.riskTypeDictionaryDatas);
91 console.log("failed");
94 $scope.temp.policy.dynamicLayoutMap = {};
95 $scope.addDataToFields = function(ruleName){
96 console.log(ruleName);
98 var uuu = "policyController/getBRMSTemplateData.htm";
99 var postData={policyData: ruleName};
104 contentType: 'application/json',
105 data: JSON.stringify(postData),
106 success : function(data){
107 $scope.$apply(function(){
108 $scope.temp.policy.dynamicLayoutMap = data.policyData;
110 console.log( $scope.temp.policy.dynamicLayoutMap);
112 error : function(data){
113 alert("Error While Retriving the Template Layout Pattren.");
119 $scope.showbrmsrule = true;
121 $scope.ShowRule = function(policy){
123 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
124 var postData={policyData: policy};
129 contentType: 'application/json',
130 data: JSON.stringify(postData),
131 success : function(data){
132 $scope.showbrmsrule = false;
133 $scope.validateSuccess = true;
134 $scope.$apply(function(){
135 $scope.datarule = data.policyData;
138 error : function(data){
139 Notification.error("Error Occured while Showing Rule.");
144 $scope.hideRule = function(){
145 $scope.showbrmsrule = true;
146 $scope.validateSuccess = false;
150 $scope.saveBrmsParamPolicy = function(policy){
151 if(policy.itemContent != undefined){
152 $scope.refreshCheck = true;
153 $scope.policyNavigator = policy.itemContent;
154 policy.itemContent = "";
156 $scope.savebutton = false;
157 var uuu = "policycreation/save_policy";
158 var postData={policyData: policy};
163 contentType: 'application/json',
164 data: JSON.stringify(postData),
165 success : function(data){
166 $scope.$apply(function(){
167 $scope.data=data.policyData;
168 if($scope.data == 'success'){
169 $scope.temp.policy.readOnly = 'true';
170 $scope.safetyChecker = data.policyData.split("#")[2];
171 if ($scope.safetyChecker!=undefined) {
172 Notification.success($scope.safetyChecker);
174 Notification.success("Policy Saved Successfully.");
175 }else if ($scope.data == 'PolicyExists'){
176 $scope.savebutton = true;
177 Notification.error("Policy Already Exists with Same Name in Scope.");
180 console.log($scope.data);
182 error : function(data){
183 Notification.error("Error Occured while saving Policy.");
184 $scope.savebutton = true;
189 $scope.validatePolicy = function(policy){
191 document.getElementById("validate").innerHTML = "";
192 var uuu = "policyController/validate_policy.htm";
193 var postData={policyData: policy};
198 contentType: 'application/json',
199 data: JSON.stringify(postData),
200 success : function(data){
201 $scope.$apply(function(){
202 $scope.validateData = data.data.replace(/\"/g, "");
203 $scope.data=data.data.substring(1,8);
204 var size = data.data.length;
205 if($scope.data == 'success'){
206 Notification.success("Validation Success.");
207 $scope.savebutton = false;
209 var displayWarning = data.data.substring(19,size);
210 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
211 document.getElementById("validate").style.color = "white";
212 document.getElementById("validate").style.backgroundColor = "skyblue";
214 $scope.validateSuccess = false;
216 Notification.error("Validation Failed.");
217 document.getElementById("validate").innerHTML = $scope.validateData;
218 document.getElementById("validate").style.color = "white";
219 document.getElementById("validate").style.backgroundColor = "red";
220 $scope.savebutton = true;
224 console.log($scope.data);
226 error : function(data){
227 Notification.error("Validation Failed.");
228 $scope.savebutton = true;
233 function extend(obj, src) {
234 for (var key in src) {
235 if (src.hasOwnProperty(key)) obj[key] = src[key];
240 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
241 $scope.temp.policy.attributes = [];
243 if($scope.temp.policy.attributes.length == 0){
244 $scope.temp.policy.attributes = [];
248 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
249 $scope.addNewChoice = function() {
250 var newItemNo = $scope.temp.policy.attributes.length+1;
251 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
253 $scope.removeChoice = function() {
254 var lastItem = $scope.temp.policy.attributes.length-1;
255 $scope.temp.policy.attributes.splice(lastItem);