[POLICY-122] Policy GUI Fixes
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / ecompNameEditorController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 app.controller('editEcompNameController' ,  function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21     if(message.ecompNameDictionaryData==null)
22         $scope.label='Add New Ecomp Name'
23     else{
24         $scope.label='Edit Ecomp Name'
25         $scope.disableCd=true;
26     }
27     $scope.editEcompName = message.ecompNameDictionaryData;
28     
29         
30         /*getting user info from session*/
31         var userid = null;
32         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
33                 .then(function (response) {                     
34                         userid = response.userid;               
35          });
36    
37     $scope.saveEcompName = function(ecompNameDictionaryData) {
38         var regex = new RegExp("^[a-zA-Z0-9_]*$");
39                 if(!regex.test(ecompNameDictionaryData.ecompName)) {
40                         Notification.error("Enter Valid Ecomp Name without spaces or special characters");
41                 }else{
42                         var uuu = "saveDictionary/ecomp_dictionary/save_ecompName";
43                         var postData={ecompNameDictionaryData: ecompNameDictionaryData, userid: userid};
44                         $.ajax({
45                                 type : 'POST',
46                                 url : uuu,
47                                 dataType: 'json',
48                                 contentType: 'application/json',
49                                 data: JSON.stringify(postData),
50                                 success : function(data){
51                                         $scope.$apply(function(){
52                                                 $scope.ecompNameDictionaryDatas=data.ecompNameDictionaryDatas;});
53                                         if($scope.ecompNameDictionaryDatas == "Duplicate"){
54                                                 Notification.error("EcompName Dictionary exists with Same Ecomp Name.")
55                                         }else{      
56                                                 console.log($scope.ecompNameDictionaryDatas);
57                                                 $modalInstance.close({ecompNameDictionaryDatas:$scope.ecompNameDictionaryDatas});
58                                         }
59                                 },
60                                 error : function(data){
61                                         alert("Error while saving.");
62                                 }
63                         });
64                 }
65     };
66
67     $scope.close = function() {
68         $modalInstance.close();
69     };
70 });