[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / PSTypeDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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('editPSTypeController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21     if(message.psTypeDictionaryData==null)
22         $scope.label='Add New Type'
23     else{
24         $scope.label='Edit Type'
25         $scope.disableCd=true;
26     }
27         
28         /*getting user info from session*/
29         var userid = null;
30         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
31                 .then(function (response) {                     
32                         userid = response.userid;               
33          });
34         
35     $scope.editPSType = message.psTypeDictionaryData;
36
37     $scope.savePSType = function(psTypeDictionaryData) {
38         var regex = new RegExp("^[a-zA-Z0-9_]*$");
39         if(!regex.test(psTypeDictionaryData.name)) {
40                 Notification.error("Enter Valid PS Type Name without spaces or special characters");
41         }else{
42                 var uuu = "saveDictionary/ps_dictionary/save_psType";
43                 var postData={psTypeDictionaryData: psTypeDictionaryData, 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.psTypeDictionaryDatas=data.psTypeDictionaryDatas;});
53                                 console.log($scope.psTypeDictionaryDatas);
54                                 if($scope.psTypeDictionaryDatas == "Duplicate"){
55                                         Notification.error("Type Dictionary exists with Same Type Name.")
56                                 }else{      
57                                         console.log($scope.psTypeDictionaryDatas);
58                                         $modalInstance.close({psTypeDictionaryDatas:$scope.psTypeDictionaryDatas});
59                                 } 
60                         },
61                         error : function(data){
62                                 alert("Error while saving.");
63                         }
64                 });
65         }
66     };
67
68     $scope.close = function() {
69         $modalInstance.close();
70     };
71 });