[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / BRMSControllerDictController.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('editBRMSControllerController' ,  function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21     if(message.brmsControllerDictionaryDatas==null)
22         $scope.label='Add New BRMS Controller'
23     else{
24         if(message.disabled){
25                 $scope.label='View BRMS Controller'
26         }else{
27                 $scope.label='Edit BRMS Controller'
28         }
29         $scope.disableCd=true;
30     }
31     $scope.editBRMSController = message.brmsControllerDictionaryDatas;
32     $scope.disabled = message.disabled;
33         
34         /*getting user info from session*/
35         var userid = null;
36         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
37                 .then(function (response) {                     
38                         userid = response.userid;               
39          });
40    
41     $scope.saveBRMSController = function(brmsControllerDictionaryData) {
42         var regex = new RegExp("^[a-zA-Z0-9_]*$");
43                 if(!regex.test(brmsControllerDictionaryData.controllerName)) {
44                         Notification.error("Enter Valid Controller Name without spaces or special characters");
45                 }else{
46                         var uuu =  "saveDictionary/brms_dictionary/save_BRMSControllerData";
47                         if(brmsControllerDictionaryData && brmsControllerDictionaryData.controllerName){
48                                 if(brmsControllerDictionaryData.controller){
49                                         var postData={brmsControllerDictionaryData: brmsControllerDictionaryData, userid: userid};
50                                         $.ajax({
51                                                 type : 'POST',
52                                                 url : uuu,
53                                                 dataType: 'json',
54                                                 contentType: 'application/json',
55                                                 data: JSON.stringify(postData),
56                                                 success : function(data){
57                                                         $scope.$apply(function(){
58                                                                 $scope.brmsControllerDictionaryDatas=data.brmsControllerDictionaryDatas;});
59                                                         if($scope.brmsControllerDictionaryDatas == "Duplicate"){
60                                                                 Notification.error("BRMS Controller Dictionary exists with Same Controller Name.")
61                                                         }else if($scope.brmsControllerDictionaryDatas == "Error"){
62                                                                 Notification.error("BRMS Controller is not in proper required format");
63                                                         }else{      
64                                                                 console.log($scope.brmsControllerDictionaryDatas);
65                                                                 $modalInstance.close({brmsControllerDictionaryDatas:$scope.brmsControllerDictionaryDatas});
66                                                         }
67                                                 },
68                                                 error : function(data){
69                                                         alert("Error while saving.");
70                                                 }
71                                         });
72                                 }else{
73                                         Notification.error("Controller Field is Empty.");
74                                 }
75                         }else{
76                                 Notification.error("BRMS Controller Name should be given.");
77                         }
78                 }
79     };
80
81     $scope.close = function() {
82         $modalInstance.close();
83     };
84 });