Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / BRMSParamDictController.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
21 /**
22  */
23 var editBRMSParamController =  function ($scope, $modalInstance, message, $http, PapUrlService, UserInfoService, Notification){
24     if(message.brmsParamDictionaryData==null)
25         $scope.label='Add BRMS Rule'
26     else{
27         $scope.label='Edit BRMS Rule'
28         $scope.disableCd=true;
29     }
30     
31         var papUrl;
32         PapUrlService.getPapUrl().then(function(data) {
33                 var config = data;
34                 papUrl = config.PAP_URL;
35                 console.log(papUrl);
36         });
37         
38         /*getting user info from session*/
39         var loginId = null;
40         UserInfoService.getFunctionalMenuStaticDetailSession()
41                 .then(function (response) {                     
42                         loginId = response.userid;              
43          });
44         
45     $scope.editBRMSParam = message.brmsParamDictionaryData;
46     
47     $scope.uploadFile = function(files) {
48         var fd = new FormData();
49         fd.append("file", files[0]);
50         $http.post(papUrl + "/ecomp/brms_dictionary/set_BRMSParamData.htm", fd, {
51             withCredentials: false,
52             headers: {'Content-Type': undefined },
53             transformRequest: angular.identity
54         }).success().error( );
55
56     };
57         
58     $scope.MyFile = [];
59     $scope.saveBRMSParam = function(brmsParamDictionaryData) {
60         var file  = $scope.MyFile;
61         var uuu = papUrl + "/ecomp/brms_dictionary/save_BRMSParam.htm";
62         var postData={brmsParamDictionaryData: brmsParamDictionaryData, loginId: loginId};
63         $.ajax({
64             type : 'POST',
65             url : uuu,
66             dataType: 'json',
67             contentType: 'application/json',
68             data: JSON.stringify(postData),
69             success : function(data){
70                 $scope.$apply(function(){
71                     $scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
72                                         if($scope.brmsParamDictionaryDatas == "Duplicate"){
73                                                 Notification.error("BRMSParan Dictionary exists with Same Name.")
74                                         }else{      
75                                                 console.log($scope.brmsParamDictionaryDatas);
76                                                 $modalInstance.close({brmsParamDictionaryDatas:$scope.brmsParamDictionaryDatas});
77                                         }
78             },
79             error : function(data){
80                 alert("Error while saving.");
81             }
82         });
83     };
84
85     $scope.close = function() {
86         $modalInstance.close();
87     };
88 }