[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / ModelAttributeDictController.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('editModelAttributeController' ,  function ($scope, $modalInstance, message, PolicyAppService, UserInfoServiceDS2, Notification){
21     if(message.modelAttributeDictionaryData==null)
22         $scope.label='Add New Dictionary Entry'
23     else{
24         $scope.label='Edit Dictionary Entry'
25         $scope.disableCd=true;
26     }
27                 
28     PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
29         var j = data;
30         $scope.data = JSON.parse(j.data);
31         console.log($scope.data);
32         $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
33         console.log($scope.microServiceAttributeDictionaryDatas);
34     }, function (error) {
35         console.log("failed");
36     });
37
38     PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataServiceVersion').then(function (data) {
39         var j = data;
40         $scope.data = JSON.parse(j.data);
41         console.log($scope.data);
42         $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
43         console.log($scope.microServiceModelsDictionaryDatas);
44     }, function (error) {
45         console.log("failed");
46     });
47         
48         /*getting user info from session*/
49         var userid = null;
50         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
51                 .then(function (response) {                     
52                         userid = response.userid;               
53          });
54         
55     $scope.editModelAttribute = message.modelAttributeDictionaryData;
56     $scope.editModelAttribute1 = {microservice: []};
57     if($scope.edit){
58         if(message.modelAttributeDictionaryData.groupList != null){
59                 var splitValue = message.modelAttributeDictionaryData.groupList.split(",");
60                 console.log(splitValue);
61         }       
62     }
63     $scope.saveModelAttribute = function(modelAttributeDictionaryData) {
64         var regex = new RegExp("^[a-zA-Z0-9_]*$");
65         if(!regex.test(modelAttributeDictionaryData.name)) {
66                 Notification.error("Enter Valid Micro Service Name without spaces or special characters");
67         }else{
68                 var uuu = "saveDictionary/ms_dictionary/save_modelAttribute";
69                 var postData={modelAttributeDictionaryData: modelAttributeDictionaryData, userid: userid};
70                 $.ajax({
71                         type : 'POST',
72                         url : uuu,
73                         dataType: 'json',
74                         contentType: 'application/json',
75                         data: JSON.stringify(postData),
76                         success : function(data){
77                                 $scope.$apply(function(){
78                                         $scope.microServiceAttributeDictionaryDatas=data.microServiceAttributeDictionaryDatas;});
79                                 if($scope.microServiceAttributeDictionaryDatas == "Duplicate"){
80                                         Notification.error("Model Attribute Dictionary exists with Same Attribute Name.")
81                                 }else{      
82                                         console.log($scope.microServiceAttributeDictionaryDatas);
83                                         $modalInstance.close({microServiceAttributeDictionaryDatas:$scope.microServiceAttributeDictionaryDatas});
84                                 }
85                         },
86                         error : function(data){
87                                 alert("Error while saving.");
88                         }
89                 });
90         }
91     };
92
93     $scope.close = function() {
94         $modalInstance.close();
95     };
96 });