[VID-3] Setting docker image tag
[vid.git] / vid / src / main / webapp / app / vid / scripts / controller / deletionDialogController.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 deletionDialogController = function($scope, $http, $timeout, $log,
24         DeletionService, UtilityService) {
25
26     $scope.isDialogVisible = false;
27     $scope.summaryControl = {};
28     $scope.userProvidedControl = {};
29     
30     var callbackFunction = undefined;
31
32     $scope.$on("deleteComponent", function(event, request) {
33
34     $scope.isDataVisible = false;
35         $scope.isSpinnerVisible = false;
36         $scope.isErrorVisible = false;
37         $scope.isDialogVisible = true;
38         $scope.popup.isVisible = true;
39         $scope.isConfirmEnabled = false;
40
41         callbackFunction = request.callbackFunction;
42
43         DeletionService.initializeComponent(request.componentId);
44
45         $scope.componentName = DeletionService.getComponentDisplayName();
46
47         $scope.summaryControl.setList(DeletionService.getSummaryList());
48         
49         DeletionService.getParameters(handleGetParametersResponse);
50
51     });
52     
53     var handleGetParametersResponse = function(parameters, dontshow) {
54                 $scope.summaryControl.setList(parameters.summaryList);
55                 $scope.userProvidedControl.setList(parameters.userProvidedList);
56
57                 $scope.isSpinnerVisible = false;
58                 if (dontshow)
59                   $scope.isDataVisible = false;
60                 else
61                         $scope.isDataVisible = true;
62                 $scope.isConfirmEnabled = true;
63         };
64
65         $scope.userParameterChanged = function(id) {
66                 DeletionService.updateUserParameterList(id, $scope.userProvidedControl);
67         }
68
69     $scope.confirm = function() {
70
71         var requiredFields = $scope.userProvidedControl.getRequiredFields();
72                 if (requiredFields === "") {
73                         $scope.isErrorVisible = false;
74                 } else {
75                         showError("Missing data", requiredFields);
76                         return;
77                 }
78
79                 
80         var requestDetails = DeletionService.getMsoRequestDetails($scope.userProvidedControl.getList());
81
82         $scope.isDialogVisible = false;
83
84         $scope.$broadcast("deleteInstance", {
85             url : DeletionService.getMsoUrl(),
86             requestDetails : requestDetails,
87             callbackFunction : function(isSuccessful) {
88                 if (isSuccessful) {
89                     $scope.popup.isVisible = false;
90                     runCallback(true);
91                 } else {
92                     $scope.isDialogVisible = true;
93                 }
94             }
95         });
96
97     }
98
99     $scope.cancel = function() {
100         $scope.isDialogVisible = false;
101         $scope.popup.isVisible = false;
102         runCallback(false);
103     }
104
105     var runCallback = function(isSuccessful) {
106         if (angular.isFunction(callbackFunction)) {
107             callbackFunction({
108                 isSuccessful : isSuccessful
109             });
110         }
111     }
112 }
113
114 app
115         .controller("deletionDialogController", [ "$scope", "$http",
116                 "$timeout", "$log", "DeletionService", "UtilityService",
117                 deletionDialogController ]);