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', function ($scope, $window, PolicyAppService, modalService, $modal, Notification) {
23 $scope.savebutton = true;
24 $scope.finalPath = null;
26 $scope.validateSuccess = true;
27 var readValue = $scope.temp.policy.readOnly;
29 $scope.validateSuccess = false;
32 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
34 $scope.data = JSON.parse(j.data);
35 console.log($scope.data);
36 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
37 console.log($scope.brmsControllerDatas);
39 console.log("failed");
42 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
44 $scope.data = JSON.parse(j.data);
45 console.log($scope.data);
46 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
47 console.log($scope.brmsDependencyDatas);
49 console.log("failed");
52 PolicyAppService.getData('getDictionary/get_BRMSParamDataByName').then(function (data) {
54 $scope.data = JSON.parse(j.data);
55 console.log($scope.data);
56 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
57 console.log($scope.brmsParamDictionaryDatas);
59 console.log("failed");
62 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
64 $scope.data = JSON.parse(j.data);
65 console.log($scope.data);
66 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
67 console.log($scope.riskTypeDictionaryDatas);
69 console.log("failed");
72 $scope.temp.policy.dynamicLayoutMap = {};
73 $scope.addDataToFields = function(ruleName){
74 console.log(ruleName);
76 var uuu = "policyController/getBRMSTemplateData.htm";
77 var postData={policyData: ruleName};
82 contentType: 'application/json',
83 data: JSON.stringify(postData),
84 success : function(data){
85 $scope.$apply(function(){
86 $scope.temp.policy.dynamicLayoutMap = data.policyData;
88 console.log( $scope.temp.policy.dynamicLayoutMap);
90 error : function(data){
91 alert("Error While Retriving the Template Layout Pattren.");
97 $scope.ShowRule = function(policy){
99 var uuu = "policyController/ViewBRMSParamPolicyRule.htm";
100 var postData={policyData: policy};
105 contentType: 'application/json',
106 data: JSON.stringify(postData),
107 success : function(data){
108 $scope.$apply(function(){
109 $scope.datarule = data.policyData;
110 var modalInstance = $modal.open({
111 backdrop: 'static', keyboard: false,
112 templateUrl : 'brmsshowrule',
113 controller: 'showrulecontroller',
115 message: function () {
117 datas: $scope.datarule
125 error : function(data){
126 Notification.error("Error Occured while Showing Rule.");
131 $scope.saveBrmsParamPolicy = function(policy){
133 $scope.savebutton = false;
134 var uuu = "policycreation/save_policy";
135 var postData={policyData: policy};
140 contentType: 'application/json',
141 data: JSON.stringify(postData),
142 success : function(data){
143 $scope.$apply(function(){
144 $scope.data=data.policyData;
145 if($scope.data == 'success'){
146 $scope.temp.policy.readOnly = 'true';
147 $scope.safetyChecker = data.policyData.split("#")[2];
148 if ($scope.safetyChecker!=undefined) {
149 Notification.success($scope.safetyChecker);
151 Notification.success("Policy Saved Successfully.");
152 }else if ($scope.data == 'PolicyExists'){
153 $scope.savebutton = true;
154 Notification.error("Policy Already Exists with Same Name in Scope.");
157 console.log($scope.data);
159 error : function(data){
160 Notification.error("Error Occured while saving Policy.");
161 $scope.savebutton = true;
166 $scope.validatePolicy = function(policy){
168 document.getElementById("validate").innerHTML = "";
169 var uuu = "policyController/validate_policy.htm";
170 var postData={policyData: policy};
175 contentType: 'application/json',
176 data: JSON.stringify(postData),
177 success : function(data){
178 $scope.$apply(function(){
179 $scope.validateData = data.data.replace(/\"/g, "");
180 $scope.data=data.data.substring(1,8);
181 var size = data.data.length;
182 if($scope.data == 'success'){
183 Notification.success("Validation Success.");
184 $scope.savebutton = false;
186 var displayWarning = data.data.substring(19,size);
187 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
188 document.getElementById("validate").style.color = "white";
189 document.getElementById("validate").style.backgroundColor = "skyblue";
191 $scope.validateSuccess = false;
193 Notification.error("Validation Failed.");
194 document.getElementById("validate").innerHTML = $scope.validateData;
195 document.getElementById("validate").style.color = "white";
196 document.getElementById("validate").style.backgroundColor = "red";
197 $scope.savebutton = true;
201 console.log($scope.data);
203 error : function(data){
204 Notification.error("Validation Failed.");
205 $scope.savebutton = true;
210 function extend(obj, src) {
211 for (var key in src) {
212 if (src.hasOwnProperty(key)) obj[key] = src[key];
217 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
218 $scope.temp.policy.attributes = [];
220 if($scope.temp.policy.attributes.length == 0){
221 $scope.temp.policy.attributes = [];
225 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
226 $scope.addNewChoice = function() {
227 var newItemNo = $scope.temp.policy.attributes.length+1;
228 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
230 $scope.removeChoice = function() {
231 var lastItem = $scope.temp.policy.attributes.length-1;
232 $scope.temp.policy.attributes.splice(lastItem);
236 app.controller('showrulecontroller' , function ($scope, $modalInstance, message){
237 if(message.datas!=null){
238 $scope.datarule=message.datas;
241 $scope.close = function() {
242 $modalInstance.close();