Merge "Add UT to ToscaParserImpl"
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / iframeDialogController.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 iframeDialogController = function (COMPONENT, FIELD, PARAMETER, $scope, $http, $timeout, $log,
24                                          CreationService, UtilityService, DataService, $routeParams) {
25
26     $scope.isDialogVisible = false;
27
28     function receiveMessage(event) {
29         window.removeEventListener("message", receiveMessage, false);
30         $scope.isDialogVisible = false;
31         $scope.popup.isVisible = false;
32
33         if (event.data.eventId == 'submitIframe') {
34             CreationService.initializeComponent(COMPONENT.VNF);
35             var instanceId = $routeParams.serviceInstanceId;
36             DataService.setServiceInstanceId(instanceId);
37             console.log(event.data.data);
38
39             $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
40                 url: CreationService.getMsoUrl(),
41                 requestDetails: event.data.data,
42                 componentId: COMPONENT.VNF,
43                 callbackFunction: function (response) {
44                     // if (response.isSuccessful) {
45                     //     $scope.popup.shouldShowIframePopup = false;
46                     // } else {
47                     $scope.isDialogVisible = false;
48                     $scope.popup.isVisible = false;
49                     // }
50                 }
51             });
52         }
53         $scope.$apply();
54     }
55
56
57     $scope.$on(COMPONENT.IFRAME_DIALOG, function (event, data) {
58         var queryString = Object.keys(data).map(function(key) {
59             return key + '=' + data[key]
60         }).join('&');
61         $scope.url = COMPONENT.SUB_INTERFACE_POPUP_IFRAME_URL + queryString;
62         $scope.isDialogVisible = true;
63         $scope.popup.isVisible = true;
64
65         window.addEventListener("message", receiveMessage, false);
66     });
67 };
68
69 appDS2.controller("iframeDialogController", ["COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
70     "$timeout", "$log", "CreationService", "UtilityService", "DataService", "$routeParams",
71     iframeDialogController]);