[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / DecisionRainyDayDictController.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('editRainyDayDictController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21
22         if(message.rainyDayDictionaryData==null)
23         $scope.label='Add Allowed Treatments',
24         $scope.treatments = [];
25     else{
26         $scope.treatments = [];
27         $scope.label='Edit Treatment'
28         $scope.disableCd=true;
29         var headers = message.rainyDayDictionaryData.treatments;
30         var splitEqual = ',';
31         if(headers != null && headers != ""){
32                 if (headers.indexOf(splitEqual) >= 0) {
33                         var splitValue = headers.split(splitEqual);
34                         for(i = 0; i < splitValue.length; i++){
35                                 var key  = splitValue[i];
36                                 $scope.treatments.push({'treatment': key});
37                         }
38                 }else{
39                  var key  = headers;
40                  $scope.treatments.push({'treatment': key});
41             }
42         }
43     }
44     
45         
46         /*getting user info from session*/
47         var userid = null;
48         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
49                 .then(function (response) {                     
50                         userid = response.userid;               
51          });
52     
53     $scope.editRainyDayTreatment = message.rainyDayDictionaryData;
54     $scope.saveDecisionTreatments = function(rainyDayDictionaryData) {
55                 var finalData = extend(rainyDayDictionaryData, $scope.treatmentDatas[0]);
56                 var uuu = "saveDictionary/decision_dictionary/save_RainyDay";
57                 var postData={rainyDayDictionaryData: rainyDayDictionaryData, userid: userid};
58                 $.ajax({
59                         type : 'POST',
60                         url : uuu,
61                         dataType: 'json',
62                         contentType: 'application/json',
63                         data: JSON.stringify(postData),
64                         success : function(data){
65                                 $scope.$apply(function(){
66                                         $scope.rainyDayDictionaryDatas=data.rainyDayDictionaryDatas;});
67                                 if($scope.rainyDayDictionaryDatas == "Duplicate"){
68                                         Notification.error("Allowed Treatments Dictionary exists with Same Building Block and Workstep.")
69                                 }else{      
70                                         console.log($scope.rainyDayDictionaryDatas);
71                                         $modalInstance.close({rainyDayDictionaryDatas:$scope.rainyDayDictionaryDatas});
72                                 }
73                         },
74                         error : function(data){
75                                 alert("Error while saving.");
76                         }
77                 });
78     };
79     
80     function extend(obj, src) {
81         for (var key in src) {
82             if (src.hasOwnProperty(key)) obj[key] = src[key];
83         }
84         return obj;
85     }
86     
87     $scope.treatmentDatas = [{"userDataTypeValues" : $scope.treatments}];
88     $scope.addNewTreatment = function() {
89       $scope.treatments.push({});
90     };    
91     $scope.removeTreatment = function() {
92       var lastItem = $scope.treatments.length-1;
93       $scope.treatments.splice(lastItem);
94     };
95     
96
97     $scope.close = function() {
98         $modalInstance.close();
99     };
100 });