CLAMP Model policy creation support
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / MSDictionaryController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2019 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('editMSDictController' ,  function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21     if(message.microServiceDictionaryDatas==null)
22         $scope.label='Add Dictionary input'
23     else{
24         $scope.label='Edit Dictionary input'
25         $scope.disableCd=true;
26     }
27     
28         
29         /*getting user info from session*/
30         var userid = null;
31         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
32                 .then(function (response) {                     
33                         userid = response.userid;               
34          });
35         
36     $scope.editMSDictData = message.microServiceDictionaryDatas;
37
38     $scope.saveMSDictionatyData = function(microServiceDictionaryDatas) {
39         var regex = new RegExp("^[a-zA-Z0-9_]*$");
40         if(!regex.test(microServiceDictionaryDatas.name)) {
41                 Notification.error("Enter Valid Dictionary Name without spaces or special characters");
42         }else{
43                 var uuu = "saveDictionary/ms_dictionary/save_DictionaryData";
44                 var postData={microServiceDictionaryDatas: microServiceDictionaryDatas, userid: userid};
45                 $.ajax({
46                         type : 'POST',
47                         url : uuu,
48                         dataType: 'json',
49                         contentType: 'application/json',
50                         data: JSON.stringify(postData),
51                         success : function(data){
52                                 $scope.$apply(function(){
53                                         $scope.microServiceDictionaryDatas=data.microServiceDictionaryDatas;});
54                                 if($scope.microServiceDictionaryDatas == "Duplicate"){
55                                         Notification.error("MS Dictionary data exists with Same Name.")
56                                 }else{      
57                                         console.log($scope.microServiceDictionaryDatas);
58                                         $modalInstance.close({microServiceDictionaryDatas:$scope.microServiceDictionaryDatas});
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 });