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 app.controller('editFWServiceGroupController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, PolicyAppService, Notification){
21 if(message.serviceGroupDictionaryData==null){
22 $scope.slchoices = [];
23 $scope.label='Add Service Group'
25 $scope.label='Edit Service Group'
26 $scope.disableCd=true;
27 $scope.slchoices = [];
28 var headers = message.serviceGroupDictionaryData.serviceList;
31 if (headers.indexOf(splitEqual) >= 0) {
32 var splitValue = headers.split(splitEqual);
33 for(i = 0; i < splitValue.length; i++){
34 var key = splitValue[i];
35 $scope.slchoices.push({'id':'choice'+i+1, 'option': key});
39 $scope.slchoices.push({'id':'choice'+1, 'option': key});
45 PolicyAppService.getData('getDictionary/get_ServiceListDictionaryDataByName').then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
50 console.log($scope.serviceListDictionaryDatas);
52 console.log("failed");
56 /*getting user info from session*/
58 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
59 .then(function (response) {
60 userid = response.userid;
63 $scope.editServiceGroup = message.serviceGroupDictionaryData;
65 $scope.saveFWServiceGroup = function(serviceGroupDictionaryData) {
66 var regex = new RegExp("^[a-zA-Z0-9_]*$");
67 if(!regex.test(serviceGroupDictionaryData.groupName)) {
68 Notification.error("Enter Valid Service Group Name without spaces or special characters");
70 var finalData = extend(serviceGroupDictionaryData, $scope.attributeDatas[0]);
71 var uuu = "saveDictionary/fw_dictionary/save_serviceGroup";
72 var postData={serviceGroupDictionaryData: finalData, userid: userid};
77 contentType: 'application/json',
78 data: JSON.stringify(postData),
79 success : function(data){
80 $scope.$apply(function(){
81 $scope.serviceGroupDictionaryDatas=data.serviceGroupDictionaryDatas;});
82 if($scope.serviceGroupDictionaryDatas == "Duplicate"){
83 Notification.error("FW Service Group Dictionary exists with Same Group Name.")
85 console.log($scope.serviceGroupDictionaryDatas);
86 $modalInstance.close({serviceGroupDictionaryDatas:$scope.serviceGroupDictionaryDatas});
89 error : function(data){
90 alert("Error while saving.");
96 $scope.close = function() {
97 $modalInstance.close();
100 function extend(obj, src) {
101 for (var key in src) {
102 if (src.hasOwnProperty(key)) obj[key] = src[key];
109 $scope.attributeDatas = [{"attributes" : $scope.slchoices}];
110 $scope.addServiceGroupNewChoice = function() {
111 var newItemNo = $scope.slchoices.length+1;
112 $scope.slchoices.push({'id':'choice'+newItemNo});
114 $scope.removeServiceGroupChoice = function() {
115 var lastItem = $scope.slchoices.length-1;
116 $scope.slchoices.splice(lastItem);