Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / MSLocationDictController.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 editMSLocationController =  function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){
24     if(message.microServiceLocationDictionaryData==null)
25         $scope.label='Add Micro Service Location'
26     else{
27         $scope.label='Edit Micro Service Location'
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         
39         /*getting user info from session*/
40         var loginId = null;
41         UserInfoService.getFunctionalMenuStaticDetailSession()
42                 .then(function (response) {                     
43                         loginId = response.userid;              
44          });
45         
46     $scope.editMSLocation = message.microServiceLocationDictionaryData;
47
48     $scope.saveMSLocation = function(microServiceLocationDictionaryData) {
49         var uuu = papUrl + "/ecomp/ms_dictionary/save_location.htm";
50         var postData={microServiceLocationDictionaryData: microServiceLocationDictionaryData, loginId: loginId};
51         $.ajax({
52             type : 'POST',
53             url : uuu,
54             dataType: 'json',
55             contentType: 'application/json',
56             data: JSON.stringify(postData),
57             success : function(data){
58                 $scope.$apply(function(){
59                     $scope.microServiceLocationDictionaryDatas=data.microServiceLocationDictionaryDatas;});
60                 if($scope.microServiceLocationDictionaryDatas == "Duplicate"){
61                         Notification.error("MS Location Dictionary exists with Same Location Name.")
62                 }else{      
63                         console.log($scope.microServiceLocationDictionaryDatas);
64                     $modalInstance.close({microServiceLocationDictionaryDatas:$scope.microServiceLocationDictionaryDatas});
65                 }
66             },
67             error : function(data){
68                 alert("Error while saving.");
69             }
70         });
71     };
72
73     $scope.close = function() {
74         $modalInstance.close();
75     };
76 }