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('brmsRawPolicyController', ['$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_Raw"
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 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
60 console.log($scope.brmsControllerDatas);
62 console.log("failed");
65 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
70 console.log($scope.brmsDependencyDatas);
72 console.log("failed");
75 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 console.log($scope.data);
79 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
80 console.log($scope.riskTypeDictionaryDatas);
82 console.log("failed");
85 $scope.saveBrmsRawPolicy = function(policy){
86 if(policy.itemContent != undefined){
87 $scope.refreshCheck = true;
88 $scope.policyNavigator = policy.itemContent;
89 policy.itemContent = "";
91 $scope.savebutton = false;
92 var uuu = "policycreation/save_policy";
93 var postData={policyData: policy};
98 contentType: 'application/json',
99 data: JSON.stringify(postData),
100 success : function(data){
101 $scope.$apply(function(){
102 $scope.data=data.policyData;
103 if($scope.data == 'success'){
104 $scope.temp.policy.readOnly = 'true';
105 Notification.success("Policy Saved Successfully.");
106 }else if ($scope.data == 'PolicyExists'){
107 $scope.savebutton = true;
108 Notification.error("Policy Already Exists with Same Name in Scope.");
111 console.log($scope.data);
113 error : function(data){
114 Notification.error("Error Occured while saving Policy.");
115 $scope.savebutton = true;
120 $scope.validatePolicy = function(policy){
122 document.getElementById("validate").innerHTML = "";
123 var uuu = "policyController/validate_policy.htm";
124 var postData={policyData: policy};
129 contentType: 'application/json',
130 data: JSON.stringify(postData),
131 success : function(data){
132 $scope.$apply(function(){
133 $scope.validateData = data.data.replace(/\"/g, "");
134 $scope.data=data.data.substring(1,8);
135 var size = data.data.length;
136 if($scope.data == 'success'){
137 Notification.success("Validation Success.");
138 $scope.savebutton = false;
140 var displayWarning = data.data.substring(19,size);
141 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
142 document.getElementById("validate").style.color = "white";
143 document.getElementById("validate").style.backgroundColor = "skyblue";
146 Notification.error("Validation Failed.");
147 document.getElementById("validate").innerHTML = $scope.validateData;
148 document.getElementById("validate").style.color = "white";
149 document.getElementById("validate").style.backgroundColor = "red";
150 $scope.savebutton = true;
154 console.log($scope.data);
156 error : function(data){
157 Notification.error("Validation Failed.");
162 function extend(obj, src) {
163 for (var key in src) {
164 if (src.hasOwnProperty(key)) obj[key] = src[key];
169 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
170 $scope.temp.policy.attributes = [];
172 if($scope.temp.policy.attributes.length == 0){
173 $scope.temp.policy.attributes = [];
176 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
177 $scope.addNewChoice = function() {
178 var newItemNo = $scope.temp.policy.attributes.length+1;
179 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
181 $scope.removeChoice = function() {
182 var lastItem = $scope.temp.policy.attributes.length-1;
183 $scope.temp.policy.attributes.splice(lastItem);