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