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('brmsRawPolicyController',
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_Raw"
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 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
59 $scope.data = JSON.parse(j.data);
60 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
63 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
65 $scope.data = JSON.parse(j.data);
66 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
69 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
75 $scope.saveBrmsRawPolicy = function(policy){
76 if(policy.itemContent != undefined){
77 $scope.refreshCheck = true;
78 $scope.policyNavigator = policy.itemContent;
79 policy.itemContent = "";
81 $scope.savebutton = false;
82 var uuu = "policycreation/save_policy";
83 var postData={policyData: policy};
88 contentType: 'application/json',
89 data: JSON.stringify(postData),
90 success : function(data){
91 $scope.$apply(function(){
92 $scope.data=data.policyData;
93 if($scope.data == 'success'){
94 $scope.temp.policy.readOnly = 'true';
95 Notification.success("Policy Saved Successfully.");
96 }else if ($scope.data == 'PolicyExists'){
97 $scope.savebutton = true;
98 Notification.error("Policy Already Exists with Same Name in Scope.");
102 error : function(data){
103 Notification.error("Error Occured while saving Policy.");
104 $scope.savebutton = true;
109 $scope.validatePolicy = function(policy){
110 document.getElementById("validate").innerHTML = "";
111 var uuu = "policyController/validate_policy.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.validateData = data.data.replace(/\"/g, "");
122 $scope.data=data.data.substring(1,8);
123 var size = data.data.length;
124 if($scope.data == 'success'){
125 Notification.success("Validation Success.");
126 $scope.savebutton = false;
128 var displayWarning = data.data.substring(19,size);
129 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
130 document.getElementById("validate").style.color = "white";
131 document.getElementById("validate").style.backgroundColor = "skyblue";
134 Notification.error("Validation Failed.");
135 document.getElementById("validate").innerHTML = $scope.validateData;
136 document.getElementById("validate").style.color = "white";
137 document.getElementById("validate").style.backgroundColor = "red";
138 $scope.savebutton = true;
143 error : function(data){
144 Notification.error("Validation Failed.");
149 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
150 $scope.temp.policy.attributes = [];
152 if($scope.temp.policy.attributes.length == 0){
153 $scope.temp.policy.attributes = [];
156 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
157 $scope.addNewChoice = function() {
158 var newItemNo = $scope.temp.policy.attributes.length+1;
159 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
161 $scope.removeChoice = function() {
162 var lastItem = $scope.temp.policy.attributes.length-1;
163 $scope.temp.policy.attributes.splice(lastItem);