Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / CLServiceDictController.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 editCLServiceController =  function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){
24     if(message.closedLoopServiceDictionaryData==null)
25         $scope.label='Add Service Name'
26     else{
27         $scope.label='Edit Service Name'
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.editCLService = message.closedLoopServiceDictionaryData;
46
47     $scope.saveCLServiceDict = function(closedLoopServiceDictionaryData) {
48         var uuu = papUrl + "/ecomp/cl_dictionary/save_service.htm";
49         var postData={closedLoopServiceDictionaryData: closedLoopServiceDictionaryData, loginId: loginId};
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.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;});
59                 if($scope.closedLoopServiceDictionaryDatas == "Duplicate"){
60                         Notification.error("ClosedLoop Service Dictionary exists with Same Service Name.")
61                 }else{      
62                          console.log($scope.closedLoopServiceDictionaryDatas);
63                      $modalInstance.close({closedLoopServiceDictionaryDatas:$scope.closedLoopServiceDictionaryDatas});
64                 }
65             },
66             error : function(data){
67                 alert("Error while saving.");
68             }
69         });
70     };
71
72     $scope.close = function() {
73         $modalInstance.close();
74     };
75 }