PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / activecampaign / assets / js / automatorwp-activecampaign.js

automatorwp-activecampaign.js in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.3, at integrations/activecampaign/assets/js/automatorwp-activecampaign.js

141 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2
3 var prefix = 'automatorwp-';
4 var _prefix = 'automatorwp_activecampaign_';
5
6 // On click authorize button
7 $('body').on('click', '.automatorwp_settings #' + _prefix + 'authorize', function(e) {
8 e.preventDefault();
9
10 var button = $(this);
11 var wrapper = button.parent();
12
13 var url = $('#' + _prefix + 'url').val();
14 var key = $('#' + _prefix + 'key').val();
15
16 // Check if response div exists
17 var response_wrap = wrapper.find('#' + _prefix + 'response');
18
19 if( ! response_wrap.length ) {
20 wrapper.append( '<div id="' + _prefix + 'response" style="display: none; margin-top: 10px;"></div>' );
21 response_wrap = wrapper.find('#' + _prefix + 'response');
22 }
23
24 // Show error message if not correctly configured
25 if( url.length === 0 || key.length === 0 ) {
26 response_wrap.addClass( 'automatorwp-notice-error' );
27 response_wrap.html( 'All fields are required to connect with ActiveCampaign' );
28 response_wrap.slideDown('fast');
29 return;
30 }
31
32 response_wrap.slideUp('fast');
33 response_wrap.attr('class', '');
34
35 // Show spinner
36 wrapper.append('<span class="spinner is-active" style="float: none;"></span>');
37
38 // Disable button
39 button.prop('disabled', true);
40
41 $.post(
42 ajaxurl,
43 {
44 action: 'automatorwp_activecampaign_authorize',
45 nonce: automatorwp_activecampaign.nonce,
46 url: url,
47 key: key,
48 },
49 function( response ) {
50
51 // Add class automatorwp-notice-success on successful unlock, if not will add the class automatorwp-notice-error
52 response_wrap.addClass( 'automatorwp-notice-' + ( response.success === true ? 'success' : 'error' ) );
53 response_wrap.html( ( response.data.message !== undefined ? response.data.message : response.data ) );
54 response_wrap.slideDown('fast');
55
56 // Hide spinner
57 wrapper.find('.spinner').remove();
58
59 // Redirect on success
60 if( response.success === true && response.data.redirect_url !== undefined ) {
61 window.location = response.data.redirect_url;
62 return;
63 }
64
65
66 // Enable button
67 button.prop('disabled', false);
68
69 }
70 );
71
72
73 });
74
75 // On click refresh button
76 $('body').on('click', '.automatorwp_settings #' + _prefix + 'refresh', function(e) {
77 e.preventDefault();
78
79 var button = $(this);
80 var wrapper = button.parent();
81
82 var webhook = $('#' + _prefix + 'webhook').val();
83
84 // Check if response div exists
85 var response_wrap = wrapper.find('#' + _prefix + 'response');
86
87 if( ! response_wrap.length ) {
88 wrapper.append( '<div id="' + _prefix + 'response" style="display: none; margin-top: 10px;"></div>' );
89 response_wrap = wrapper.find('#' + _prefix + 'response');
90 }
91
92 response_wrap.slideUp('fast');
93 response_wrap.attr('class', '');
94
95 // Show spinner
96 $('<span class="spinner is-active" style="float: none;"></span>').insertAfter( button );
97
98 // Disable button
99 button.prop('disabled', true);
100
101 $.post(
102 ajaxurl,
103 {
104 action: 'automatorwp_activecampaign_refresh',
105 nonce: automatorwp_activecampaign.nonce,
106 webhook: webhook,
107 },
108 function( response ) {
109
110 // Add class automatorwp-notice-success on successful unlock, if not will add the class automatorwp-notice-error
111 response_wrap.addClass( 'automatorwp-notice-' + ( response.success === true ? 'success' : 'error' ) );
112 response_wrap.html( ( response.data.message !== undefined ? response.data.message : response.data ) );
113 response_wrap.slideDown('fast');
114
115 // Hide spinner
116 wrapper.find('.spinner').remove();
117
118 // Redirect on success
119 if( response.success === true && response.data.redirect_url !== undefined ) {
120 window.location = response.data.redirect_url;
121 return;
122 }
123
124
125 // Enable button
126 button.prop('disabled', false);
127
128 }
129 );
130
131 });
132
133 // View webhook on triggers
134 $('body').on('click', '.automatorwp-view-webhook', function(e) {
135 e.preventDefault();
136
137 $(this).parent().next().slideDown('fast');
138
139 });
140
141 })( jQuery );