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);
34 $scope.modal = function(id, hide) {
35 return $('#' + id).modal(hide ? 'hide' : 'show');
38 $scope.validateSuccess = true;
39 var readValue = $scope.temp.policy.readOnly;
41 $scope.validateSuccess = false;
44 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
46 $scope.data = JSON.parse(j.data);
47 console.log($scope.data);
48 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
49 console.log($scope.brmsControllerDatas);
51 console.log("failed");
54 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
56 $scope.data = JSON.parse(j.data);
57 console.log($scope.data);
58 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
59 console.log($scope.brmsDependencyDatas);
61 console.log("failed");
64 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
66 $scope.data = JSON.parse(j.data);
67 console.log($scope.data);
68 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
69 console.log($scope.brmsParamDictionaryDatas);
71 console.log("failed");
74 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
76 $scope.data = JSON.parse(j.data);
77 console.log($scope.data);
78 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
79 console.log($scope.riskTypeDictionaryDatas);
81 console.log("failed");
84 $scope.temp.policy.dynamicLayoutMap = {};
85 $scope.addDataToFields = function(ruleName){
86 console.log(ruleName);
88 var uuu = "policyController/getBRMSTemplateData.htm";
89 var postData={policyData: ruleName};
94 contentType: 'application/json',
95 data: JSON.stringify(postData),
96 success : function(data){
97 $scope.$apply(function(){
98 $scope.temp.policy.dynamicLayoutMap = data.policyData;
100 console.log( $scope.temp.policy.dynamicLayoutMap);
102 error : function(data){
103 alert("Error While Retriving the Template Layout Pattren.");
109 $scope.ShowRule = function(policy){
111 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
112 var postData={policyData: policy};
117 contentType: 'application/json',
118 data: JSON.stringify(postData),
119 success : function(data){
120 $scope.$apply(function(){
121 $scope.datarule = data.policyData;
122 var modalInstance = $modal.open({
123 backdrop: 'static', keyboard: false,
124 templateUrl : 'brmsshowrule',
125 controller: 'showrulecontroller',
127 message: function () {
129 datas: $scope.datarule
137 error : function(data){
138 Notification.error("Error Occured while Showing Rule.");
143 $scope.saveBrmsParamPolicy = function(policy){
144 if(policy.itemContent != undefined){
145 $scope.refreshCheck = true;
146 $scope.policyNavigator = policy.itemContent;
147 policy.itemContent = "";
149 $scope.savebutton = false;
150 var uuu = "policycreation/save_policy";
151 var postData={policyData: policy};
156 contentType: 'application/json',
157 data: JSON.stringify(postData),
158 success : function(data){
159 $scope.$apply(function(){
160 $scope.data=data.policyData;
161 if($scope.data == 'success'){
162 $scope.temp.policy.readOnly = 'true';
163 $scope.safetyChecker = data.policyData.split("#")[2];
164 if ($scope.safetyChecker!=undefined) {
165 Notification.success($scope.safetyChecker);
167 Notification.success("Policy Saved Successfully.");
168 }else if ($scope.data == 'PolicyExists'){
169 $scope.savebutton = true;
170 Notification.error("Policy Already Exists with Same Name in Scope.");
173 console.log($scope.data);
175 error : function(data){
176 Notification.error("Error Occured while saving Policy.");
177 $scope.savebutton = true;
182 $scope.validatePolicy = function(policy){
184 document.getElementById("validate").innerHTML = "";
185 var uuu = "policyController/validate_policy.htm";
186 var postData={policyData: policy};
191 contentType: 'application/json',
192 data: JSON.stringify(postData),
193 success : function(data){
194 $scope.$apply(function(){
195 $scope.validateData = data.data.replace(/\"/g, "");
196 $scope.data=data.data.substring(1,8);
197 var size = data.data.length;
198 if($scope.data == 'success'){
199 Notification.success("Validation Success.");
200 $scope.savebutton = false;
202 var displayWarning = data.data.substring(19,size);
203 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
204 document.getElementById("validate").style.color = "white";
205 document.getElementById("validate").style.backgroundColor = "skyblue";
207 $scope.validateSuccess = false;
209 Notification.error("Validation Failed.");
210 document.getElementById("validate").innerHTML = $scope.validateData;
211 document.getElementById("validate").style.color = "white";
212 document.getElementById("validate").style.backgroundColor = "red";
213 $scope.savebutton = true;
217 console.log($scope.data);
219 error : function(data){
220 Notification.error("Validation Failed.");
221 $scope.savebutton = true;
226 function extend(obj, src) {
227 for (var key in src) {
228 if (src.hasOwnProperty(key)) obj[key] = src[key];
233 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
234 $scope.temp.policy.attributes = [];
236 if($scope.temp.policy.attributes.length == 0){
237 $scope.temp.policy.attributes = [];
241 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
242 $scope.addNewChoice = function() {
243 var newItemNo = $scope.temp.policy.attributes.length+1;
244 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
246 $scope.removeChoice = function() {
247 var lastItem = $scope.temp.policy.attributes.length-1;
248 $scope.temp.policy.attributes.splice(lastItem);
252 app.controller('showrulecontroller' , function ($scope, $modalInstance, message){
253 if(message.datas!=null){
254 $scope.datarule=message.datas;
257 $scope.close = function() {
258 $modalInstance.close();