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('editPEPOptionsController', function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21 if(message.pepOptionsDictionaryData==null)
22 $scope.label='Add PEP Options',
25 $scope.label='Edit PEP Options'
26 $scope.disableCd=true;
28 var headers = message.pepOptionsDictionaryData.actions;
29 var SplitChars = ':#@';
30 if (headers.indexOf(SplitChars) >= 0) {
31 var splitHeader = headers.split(SplitChars);
32 var singleHeader = splitHeader;
33 var splitEqual = '=#@';
34 for(i = 0; i < singleHeader.length; i++){
35 if (singleHeader[i].indexOf(splitEqual) >= 0) {
36 var splitValue = singleHeader[i].split(splitEqual);
37 var key = splitValue[0];
38 var value = splitValue[1];
39 var newItemNo = $scope.choices.length+1;
40 $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value });
44 var splitEqual = '=#@';
45 if (headers.indexOf(splitEqual) >= 0) {
46 var splitValue = headers.split(splitEqual);
47 var key = splitValue[0];
48 var value = splitValue[1];
49 $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value });
54 /*getting user info from session*/
56 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
57 .then(function (response) {
58 userid = response.userid;
61 $scope.editPEPOptions = message.pepOptionsDictionaryData;
63 $scope.saveCLPepOptions = function(pepOptionsDictionaryData) {
64 var regex = new RegExp("^[a-zA-Z0-9_]*$");
65 if(!regex.test(pepOptionsDictionaryData.pepName)) {
66 Notification.error("Enter Valid PEP Name without spaces or special characters");
68 var finalData = extend(pepOptionsDictionaryData, $scope.actions[0]);
69 var uuu = "saveDictionary/cl_dictionary/save_pepOptions";
70 var postData={pepOptionsDictionaryData: finalData, userid: userid};
75 contentType: 'application/json',
76 data: JSON.stringify(postData),
77 success : function(data){
78 $scope.$apply(function(){
79 $scope.pepOptionsDictionaryDatas=data.pepOptionsDictionaryDatas;});
80 if($scope.pepOptionsDictionaryDatas == "Duplicate"){
81 Notification.error("PEP Options Dictionary exists with Same PEP Name.")
83 console.log($scope.pepOptionsDictionaryDatas);
84 $modalInstance.close({pepOptionsDictionaryDatas:$scope.pepOptionsDictionaryDatas});
87 error : function(data){
88 alert("Error while saving.");
94 $scope.close = function() {
95 $modalInstance.close();
98 function extend(obj, src) {
99 for (var key in src) {
100 if (src.hasOwnProperty(key)) obj[key] = src[key];
105 $scope.actions = [{"attributes" : $scope.choices}];
106 $scope.addNewChoice = function() {
107 var newItemNo = $scope.choices.length+1;
108 $scope.choices.push({'id':'choice'+newItemNo});
110 $scope.removeChoice = function() {
111 var lastItem = $scope.choices.length-1;
112 $scope.choices.splice(lastItem);