UI Feature flagging support
[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 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,
24     DeleteResumeService, CreationService, DataService, UtilityService) {
25
26     $scope.isDialogVisible = false;
27     $scope.summaryControl = {};
28     $scope.userProvidedControl = {};
29
30     var callbackFunction = undefined;
31     var componentId = undefined;
32     $scope.dialogMethod = COMPONENT.DELETE;
33
34     $scope.$on(COMPONENT.DELETE_RESUME_COMPONENT, function(event, request) {
35
36     $scope.isE2EService = false;
37         $scope.isDataVisible = false;
38         $scope.isSpinnerVisible = false;
39         $scope.isErrorVisible = false;
40         $scope.isDialogVisible = true;
41         $scope.popup.isVisible = true;
42         $scope.isConfirmEnabled = false;
43         $scope.dialogMethod = request.dialogMethod;
44         $scope.serviceStatus = request.serviceStatus;
45         callbackFunction = request.callbackFunction;
46         componentId = request.componentId;
47
48         DeleteResumeService.initializeComponent(request.componentId);
49
50         $scope.componentName = DeleteResumeService.getComponentDisplayName();
51         $scope.summaryControl.setList(DeleteResumeService.getSummaryList());
52
53         DeleteResumeService.getParameters(handleGetParametersResponse);
54
55     });
56
57     var handleGetParametersResponse = function(parameters, dontshow) {
58         $scope.summaryControl.setList(parameters.summaryList);
59         $scope.userProvidedControl.setList(parameters.userProvidedList);
60
61         $scope.isSpinnerVisible = false;
62         if (dontshow)
63             $scope.isDataVisible = false;
64         else
65             $scope.isDataVisible = true;
66         $scope.isConfirmEnabled = true;
67     };
68
69     $scope.userParameterChanged = function(id) {
70         DeleteResumeService.updateUserParameterList(id, $scope.userProvidedControl);
71     }
72
73     $scope.confirm = function() {
74         DataService.setE2EService($scope.isE2EService); //VoLTE support
75         var requiredFields = $scope.userProvidedControl.getRequiredFields();
76         if (requiredFields === "") {
77             $scope.isErrorVisible = false;
78         } else {
79             showError(FIELD.ERROR.MISSING_DATA, requiredFields);
80             return;
81         }
82
83
84
85         var  callbackAfterMSO = function(isSuccessful) {
86             if (isSuccessful) {
87                 $scope.popup.isVisible = false;
88                 runCallback(true);
89             } else {
90                 $scope.isDialogVisible = true;
91             }
92         };
93
94
95         $scope.isDialogVisible = false;
96
97         if ($scope.dialogMethod == COMPONENT.DELETE)
98         {
99
100             var requestDetails = DeleteResumeService.getMsoRequestDetails($scope.userProvidedControl.getList());
101
102             if(!DataService.getE2EService() && DeleteResumeService.isMacro === true){
103                 requestDetails.requestParameters.aLaCarte = false;
104             }
105
106             $scope.$broadcast(COMPONENT.MSO_DELETE_REQ, {
107                 url : DeleteResumeService.getMsoUrl($scope.serviceStatus),
108                 requestDetails : requestDetails,
109                 componentId: componentId,
110                 callbackFunction : callbackAfterMSO
111             });
112         }
113         else
114         if ($scope.dialogMethod == COMPONENT.RESUME)
115         {
116             CreationService.initializeComponent(componentId);
117             CreationService.setInventoryInfo();
118
119             var requestDetails = CreationService.getMsoRequestDetails($scope.userProvidedControl.getList());
120
121
122             $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
123                 url : CreationService.getMsoUrl(),
124                 requestDetails : requestDetails,
125                 componentId: componentId,
126                 callbackFunction : callbackAfterMSO
127             });
128
129
130         }
131
132     }
133
134     $scope.cancel = function() {
135         $scope.isDialogVisible = false;
136         $scope.popup.isVisible = false;
137         runCallback(false);
138     }
139
140     var runCallback = function(isSuccessful) {
141         if (angular.isFunction(callbackFunction)) {
142             callbackFunction({
143                 isSuccessful : isSuccessful
144             });
145         }
146     }
147 }
148
149 appDS2.controller("deleteResumeDialogController", [ "COMPONENT", "FIELD", "$scope", "$http",
150                 "$timeout", "$log", "DeleteResumeService","CreationService", "DataService", "UtilityService",
151     deleteResumeDialogController]);