|
1 |
| -/* eslint-disable no-console */ |
| 1 | +/* eslint-disable prefer-template, no-console */ |
2 | 2 | (function ($) {
|
3 | 3 | const params = window.mailchimp_sf_admin_params || {};
|
4 | 4 | const oauthBaseUrl = 'https://woocommerce.mailchimpapp.com';
|
|
11 | 11 | * @param {string} token - Token from the Oauth service.
|
12 | 12 | */
|
13 | 13 | function openMailChimpOauthPopup(token) {
|
14 |
| - const startUrl = `${oauthBaseUrl}/auth/start/${token}`; |
| 14 | + const startUrl = oauthBaseUrl + '/auth/start/' + token; |
15 | 15 | const width = 800;
|
16 | 16 | const height = 600;
|
17 | 17 | const screenSizes = window.screen || { width: 1024, height: 768 };
|
18 | 18 | const left = (screenSizes.width - width) / 2;
|
19 | 19 | const top = (screenSizes.height - height) / 4;
|
20 |
| - const windowOptions = `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${ |
21 |
| - width |
22 |
| - }, height=${height}, top=${top}, left=${left}, domain=${oauthBaseUrl.replace('https://', '')}`; |
| 20 | + const windowOptions = |
| 21 | + 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + |
| 22 | + width + |
| 23 | + ', height=' + |
| 24 | + height + |
| 25 | + ', top=' + |
| 26 | + top + |
| 27 | + ', left=' + |
| 28 | + left + |
| 29 | + ', domain=' + |
| 30 | + oauthBaseUrl.replace('https://', ''); |
23 | 31 |
|
24 | 32 | // Open Mailchimp OAuth popup.
|
25 | 33 | const popup = window.open(startUrl, params.oauth_window_name, windowOptions);
|
|
58 | 66 | window.clearInterval(oauthInterval);
|
59 | 67 |
|
60 | 68 | // Check status of OAuth connection.
|
61 |
| - $.post(`${oauthBaseUrl}/api/status/${token}`, function (statusData) { |
| 69 | + const statusUrl = oauthBaseUrl + '/api/status/' + token; |
| 70 | + $.post(statusUrl, function (statusData) { |
62 | 71 | if (statusData && statusData.status === 'accepted') {
|
63 | 72 | const finishData = {
|
64 | 73 | action: 'mailchimp_sf_oauth_finish',
|
|
83 | 92 | }
|
84 | 93 | $(errorSelector).show();
|
85 | 94 | }
|
| 95 | + $(spinner).removeClass('is-active'); |
86 | 96 | }).fail(function () {
|
87 | 97 | console.error('Error calling OAuth finish endpoint.');
|
88 | 98 | $(errorSelector).html(params.generic_error);
|
89 | 99 | $(errorSelector).show();
|
| 100 | + $(spinner).removeClass('is-active'); |
90 | 101 | });
|
91 | 102 | } else {
|
92 | 103 | console.log(
|
93 | 104 | 'Error calling OAuth status endpoint. No credentials provided at login popup? Data:',
|
94 | 105 | statusData,
|
95 | 106 | );
|
| 107 | + $(spinner).removeClass('is-active'); |
96 | 108 | }
|
97 |
| - $(spinner).removeClass('is-active'); |
98 | 109 | }).fail(function () {
|
99 | 110 | $(errorSelector).html(params.generic_error);
|
100 | 111 | $(errorSelector).show();
|
|
0 commit comments