2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 app.controller('editRainyDayDictController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
22 if(message.rainyDayDictionaryData==null)
23 $scope.label='Add Allowed Treatments',
24 $scope.treatments = [];
26 $scope.treatments = [];
27 $scope.label='Edit Treatment'
28 $scope.disableCd=true;
29 var headers = message.rainyDayDictionaryData.treatments;
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});
40 $scope.treatments.push({'treatment': key});
46 /*getting user info from session*/
48 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
49 .then(function (response) {
50 userid = response.userid;
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};
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.")
70 console.log($scope.rainyDayDictionaryDatas);
71 $modalInstance.close({rainyDayDictionaryDatas:$scope.rainyDayDictionaryDatas});
74 error : function(data){
75 alert("Error while saving.");
80 function extend(obj, src) {
81 for (var key in src) {
82 if (src.hasOwnProperty(key)) obj[key] = src[key];
87 $scope.treatmentDatas = [{"userDataTypeValues" : $scope.treatments}];
88 $scope.addNewTreatment = function() {
89 $scope.treatments.push({});
91 $scope.removeTreatment = function() {
92 var lastItem = $scope.treatments.length-1;
93 $scope.treatments.splice(lastItem);
97 $scope.close = function() {
98 $modalInstance.close();