|
2 | 2 | var vm = this;
|
3 | 3 |
|
4 | 4 | vm.oauthConfig = {};
|
| 5 | + vm.oauthSuccessEventCount = 0; |
5 | 6 |
|
6 | 7 | umbracoCmsIntegrationsCrmDynamicsResource.checkOAuthConfiguration().then(function (response) {
|
7 | 8 | if (response && response.isAuthorized) {
|
|
39 | 40 | // authorization listener
|
40 | 41 | window.addEventListener("message", function (event) {
|
41 | 42 | if (event.data.type === "hubspot:oauth:success") {
|
42 |
| - |
43 |
| - umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) { |
44 |
| - if (response.startsWith("Error:")) { |
45 |
| - |
46 |
| - // if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window. |
47 |
| - // if directive runs from data type, the notifications are displayed |
48 |
| - if (typeof $scope.connected === "undefined") |
49 |
| - notificationsService.error("Dynamics Configuration", response); |
50 |
| - } else { |
51 |
| - vm.oauthConfig.isConnected = true; |
52 |
| - |
53 |
| - // if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window. |
54 |
| - // if directive runs from data type, the notifications are displayed |
55 |
| - if (typeof $scope.connected === "undefined") |
56 |
| - notificationsService.success("Dynamics Configuration", "OAuth connected."); |
57 |
| - |
58 |
| - umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function(response) { |
59 |
| - vm.oauthConfig.fullName = response; |
60 |
| - }); |
61 |
| - |
62 |
| - if (typeof $scope.connected === "function") |
63 |
| - $scope.connected(); |
64 |
| - } |
65 |
| - }); |
| 43 | + vm.oauthSuccessEventCount += 1; |
| 44 | + |
| 45 | + if (vm.oauthSuccessEventCount == 1) { |
| 46 | + umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) { |
| 47 | + |
| 48 | + if (response.startsWith("Error:")) { |
| 49 | + |
| 50 | + // if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window. |
| 51 | + // if directive runs from data type, the notifications are displayed |
| 52 | + if (typeof $scope.connected === "undefined") |
| 53 | + notificationsService.error("Dynamics Configuration", response); |
| 54 | + } else { |
| 55 | + vm.oauthConfig.isConnected = true; |
| 56 | + |
| 57 | + // if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window. |
| 58 | + // if directive runs from data type, the notifications are displayed |
| 59 | + if (typeof $scope.connected === "undefined") |
| 60 | + notificationsService.success("Dynamics Configuration", "OAuth connected."); |
| 61 | + |
| 62 | + umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function (response) { |
| 63 | + vm.oauthConfig.fullName = response; |
| 64 | + }); |
| 65 | + |
| 66 | + if (typeof $scope.connected === "function") |
| 67 | + $scope.connected(); |
| 68 | + } |
| 69 | + }); |
| 70 | + } |
66 | 71 | }
|
67 | 72 | }, false);
|
68 | 73 | }
|
|
0 commit comments