Merge "Add a semicolon at the end of this statement"
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / deleteResumeDialogController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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 "use strict";
22
23 var deleteResumeDialogController = function( COMPONENT, FIELD, $scope, $http, $timeout, $log, DataService,
24                                              DeleteResumeService, CreationService, UtilityService) {
25
26     $scope.isDialogVisible = false;
27     $scope.summaryControl = {};
28     $scope.userProvidedControl = {};
29
30     var callbackFunction = undefined;
31     var componentId = undefined;
32     var volumeGroups = undefined;
33     $scope.dialogMethod = COMPONENT.DELETE;
34
35     $scope.$on(COMPONENT.DELETE_RESUME_COMPONENT, function(event, request) {
36
37         $scope.isE2EService = false;
38         $scope.isDataVisible = false;
39         $scope.isSpinnerVisible = false;
40         $scope.isErrorVisible = false;
41         $scope.isDialogVisible = true;
42         $scope.popup.isVisible = true;
43         $scope.isConfirmEnabled = false;
44         $scope.dialogMethod = request.dialogMethod;
45         $scope.serviceStatus = request.serviceStatus;
46         callbackFunction = request.callbackFunction;
47         componentId = request.componentId;
48         volumeGroups = request.volumeGroups ? request.volumeGroups : [];
49         DeleteResumeService.initializeComponent(request.componentId);
50
51         $scope.componentName = DeleteResumeService.getComponentDisplayName();
52         $scope.summaryControl.setList(DeleteResumeService.getSummaryList());
53
54         DeleteResumeService.getParameters(handleGetParametersResponse);
55
56     });
57
58     var handleGetParametersResponse = function(parameters, dontshow) {
59         $scope.summaryControl.setList(parameters.summaryList);
60         $scope.userProvidedControl.setList(parameters.userProvidedList);
61
62         $scope.isSpinnerVisible = false;
63         if (dontshow)
64             $scope.isDataVisible = false;
65         else
66             $scope.isDataVisible = true;
67         $scope.isConfirmEnabled = true;
68     };
69
70     $scope.userParameterChanged = function(id) {
71         DeleteResumeService.updateUserParameterList(id, $scope.userProvidedControl);
72     }
73
74     $scope.confirm = function() {
75         DataService.setE2EService($scope.isE2EService); //VoLTE support
76         var requiredFields = $scope.userProvidedControl.getRequiredFields();
77         if (requiredFields === "") {
78             $scope.isErrorVisible = false;
79         } else {
80             showError(FIELD.ERROR.MISSING_DATA, requiredFields);
81             return;
82         }
83
84
85
86         var  callbackAfterMSO = function(isSuccessful) {
87             if (isSuccessful) {
88                 $scope.popup.isVisible = false;
89                 runCallback(true);
90             } else {
91                 $scope.isDialogVisible = true;
92             }
93         };
94
95
96         $scope.isDialogVisible = false;
97
98         if ($scope.dialogMethod == COMPONENT.DELETE)
99         {
100
101             var requestDetails = DeleteResumeService.getMsoRequestDetails($scope.userProvidedControl.getList());
102
103             if(!DataService.getE2EService() && DeleteResumeService.isMacro === true){
104                 requestDetails.requestParameters.aLaCarte = false;
105             }
106
107             $scope.$broadcast(COMPONENT.MSO_DELETE_REQ, {
108                 url : DeleteResumeService.getMsoUrl($scope.serviceStatus),
109                 requestDetails : requestDetails,
110                 componentId: componentId,
111                 callbackFunction : callbackAfterMSO
112             });
113         }
114         else
115         if ($scope.dialogMethod == COMPONENT.RESUME)
116         {
117             CreationService.initializeComponent(componentId);
118             CreationService.setInventoryInfo();
119
120             var parameterList = $scope.userProvidedControl.getList();
121
122             if (volumeGroups && volumeGroups.length > 0) {
123                 var volumeGroupList = FIELD.PARAMETER.AVAILABLE_VOLUME_GROUP;
124                 volumeGroupList.value = _.map(volumeGroups, function (volumeGroup) {
125                     return volumeGroup.name;
126                 });
127                 parameterList.push(volumeGroupList);
128             }
129
130             var requestDetails = CreationService.getMsoRequestDetails(parameterList);
131
132             $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
133                 url : CreationService.getMsoUrl(),
134                 requestDetails : requestDetails,
135                 componentId: componentId,
136                 callbackFunction : callbackAfterMSO
137             });
138
139
140         }
141
142     }
143
144     $scope.cancel = function() {
145         $scope.isDialogVisible = false;
146         $scope.popup.isVisible = false;
147         runCallback(false);
148     }
149
150     var runCallback = function(isSuccessful) {
151         if (angular.isFunction(callbackFunction)) {
152             callbackFunction({
153                 isSuccessful : isSuccessful
154             });
155         }
156     }
157 }
158
159 appDS2.controller("deleteResumeDialogController", [ "COMPONENT", "FIELD", "$scope", "$http",
160     "$timeout", "$log", "DataService", "DeleteResumeService","CreationService", "UtilityService",
161     deleteResumeDialogController]);