Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/admin/assets/js/ep-oauth.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + /**
2 + * Element Pack Google OAuth Admin JavaScript - Server-side flow
3 + */
4 +
5 + (function($) {
6 + 'use strict';
7 +
8 + $(document).ready(function() {
9 +
10 + var EPGoogleOAuth = {
11 +
12 + clientId: '',
13 + ajaxUrl: '',
14 + ajaxNonce: '',
15 +
16 + init: function() {
17 + if (typeof element_pack_oauth_admin !== 'undefined') {
18 + this.clientId = element_pack_oauth_admin.client_id || '';
19 + this.ajaxUrl = element_pack_oauth_admin.ajaxurl || ajaxurl;
20 + this.ajaxNonce = element_pack_oauth_admin.nonce || '';
21 + } else {
22 + return;
23 + }
24 +
25 + this.bindEvents();
26 + },
27 +
28 + bindEvents: function() {
29 + var self = this;
30 +
31 + $('#ep-connect-google').on('click', function(e) {
32 + e.preventDefault();
33 + self.connectToGoogle($(this));
34 + });
35 +
36 + $('#ep-disconnect-google').on('click', function(e) {
37 + e.preventDefault();
38 + self.disconnectFromGoogle($(this));
39 + });
40 + },
41 +
42 + connectToGoogle: function($button) {
43 + if (!this.clientId) {
44 + alert('Please configure your Google OAuth Client ID first.');
45 + return;
46 + }
47 +
48 + $button.prop('disabled', true).text('Connecting...');
49 + $('#ep-oauth-status').html(
50 + '<div class="ep-oauth-loading">' +
51 + '<div class="ep-oauth-spinner"></div>' +
52 + '<span class="ep-oauth-message">Redirecting to Google for authentication...</span>' +
53 + '</div>'
54 + );
55 +
56 + // Redirect to server-side OAuth URL generator
57 + window.location.href = this.ajaxUrl + '?action=ep_get_google_oauth_url&nonce=' + this.ajaxNonce;
58 + },
59 +
60 + disconnectFromGoogle: function($button) {
61 + if (!confirm('Are you sure you want to disconnect your Google account?')) {
62 + return;
63 + }
64 +
65 + $button.prop('disabled', true).text('Disconnecting...');
66 +
67 + $.ajax({
68 + url: this.ajaxUrl,
69 + type: 'POST',
70 + data: {
71 + action: 'ep_disconnect_google_oauth',
72 + nonce: this.ajaxNonce
73 + },
74 + success: function(result) {
75 + if (result.success) {
76 + location.reload();
77 + } else {
78 + alert('Failed to disconnect: ' + result.data);
79 + $button.prop('disabled', false).text('Disconnect');
80 + }
81 + },
82 + error: function() {
83 + alert('AJAX error occurred during disconnect');
84 + $button.prop('disabled', false).text('Disconnect');
85 + }
86 + });
87 + }
88 + };
89 +
90 + EPGoogleOAuth.init();
91 + window.EPGoogleOAuth = EPGoogleOAuth;
92 + });
93 +
94 + })(jQuery);