PluginProbe
MailerLite – WooCommerce integration / 1.8.7
MailerLite – WooCommerce integration v1.8.7
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / public / js / admin.js

admin.js in MailerLite – WooCommerce integration 1.8.7, at public/js/admin.js

262 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function(a) {
2 var c = a("#woocommerce_mailerlite_group");
3
4 if (0 !== c.length) {
5 var d = c.next(".select2-container");
6 a('<span id="woo-ml-refresh-groups" class="woo-ml-icon-refresh" data-woo-ml-refresh-groups="true"></span>').insertAfter(d);
7 }
8
9 var e = !1;
10
11 a(document).on("click", "[data-woo-ml-refresh-groups]", function(b) {
12 if (b.preventDefault(), !e) {
13 refreshGroups();
14 }
15 });
16
17 let i = 0, j = a("#woo-ml-sync-untracked-resources-progress-bar");
18
19 a(document).on("click", "[data-woo-ml-sync-untracked-resources]", function(c) {
20
21 c.preventDefault();
22
23 syncResources(this);
24 });
25
26 var syncResources = function(el) {
27
28 var d = a(el);
29
30 orders_tracked = d.data("woo-ml-untracked-resources-count");
31 all_untracked_orders_left = d.data("woo-ml-untracked-resources-left");
32
33 i = d.data("woo-ml-untracked-resources-cycle");
34
35 fail = a('#woo-ml-sync-untracked-resources-fail');
36 success = a("#woo-ml-sync-untracked-resources-success");
37
38 let r = 0;
39
40 console.log("inside the loop!");
41
42 a.ajax({
43 url: woo_ml_post.ajax_url,
44 type: "post",
45 beforeSend: function() {
46 d.prop("disabled", !0);
47 j.show();
48 r++;
49 },
50 data: {
51 action: "post_woo_ml_sync_untracked_resources"
52 },
53 async: 1,
54 success: function(data) {
55
56 var response = JSON.parse(data);
57
58 if (response.allDone) {
59
60 console.log("done!");
61 console.log("Response: True");
62 d.hide();
63 j.hide();
64 fail.hide();
65 success.show();
66 } else if (response.error) {
67
68 if (response.message) {
69 fail.html(response.message);
70 }
71
72 d.prop('disabled', 0);
73 j.hide();
74 fail.show();
75 } else {
76
77 if (response.completed) {
78 let untracked = parseInt(d.data("woo-ml-untracked-resources-left")) - parseInt(response.completed);
79
80 d.data("woo-ml-untracked-resources-left", untracked);
81 d.html('Synchronize ' + untracked.toString() + ' untracked resources');
82 }
83
84 syncResources(el);
85 }
86 }
87 });
88 };
89
90 a(document).on('click', '[data-woo-ml-reset-resources-sync]', function(event) {
91
92 event.preventDefault();
93
94 a(this).prop('disabled', true);
95 a(this).text("Please wait. Do not close this window until the reset finishes.");
96
97 resetResourcesSync();
98 });
99
100 var resetResourcesSync = function() {
101
102 a.ajax({
103 url: woo_ml_post.ajax_url,
104 type: 'post',
105 data: {
106 action: 'post_woo_ml_reset_resources_sync'
107 },
108 async: true,
109 success: function (responseStr) {
110
111 var response = responseStr;
112
113 if (typeof responseStr === "string"){
114 response = parseJSON(responseStr);
115 }
116
117 if (response.allDone) {
118
119 window.location.reload();
120 } else {
121
122 resetResourcesSync();
123 }
124 }
125 });
126 }
127
128 var field = a("#woocommerce_mailerlite_api_key");
129
130 a('<button id="woo-ml-validate-key" class="button-primary">Validate Key</button>').insertAfter(field);
131
132 a(document).on("click", "#woo-ml-validate-key", function(b) {
133 if (b.preventDefault(), !e) {
134 var key = a("#woocommerce_mailerlite_api_key").val();
135 a.ajax({
136 url: woo_ml_post.ajax_url,
137 type:"post",
138 data: {
139 action: "post_woo_ml_validate_key",
140 key:key
141 },
142 async: !1,
143 success: function(a) {
144 location.reload()
145 }
146 })
147 }
148 });
149
150 if (a('#woocommerce_mailerlite_group').length > 0) {
151 a('#woocommerce_mailerlite_group').select2();
152 }
153
154 if (a('#woocommerce_mailerlite_ignore_product_list').length > 0) {
155 a('#woocommerce_mailerlite_ignore_product_list').select2();
156 }
157
158 var cs_field = a('#woocommerce_mailerlite_consumer_secret');
159
160 if (0 !== cs_field.length) {
161 var field_desc = cs_field.next(".description");
162 field_desc.closest('tr').after(
163 '<h2>Integration Details</h2>\
164 <p class="section-description">Customize MailerLite integration for WooCommerce</p>');
165 }
166
167 var ml_platform = '';
168
169 if (a('#ml_platform').length > 0) {
170 ml_platform = a('#ml_platform').val();
171 }
172
173 var tracking_field = a('#woocommerce_mailerlite_popups');
174
175 tracking_field.closest('tr').before(
176 '<h2>Popups</h2>\
177 <p class="section-description">Display pop-up subscribe forms created within MailerLite</p>');
178
179 var button = a('[name="save"]');
180
181 if (field.length !== 0 && (cs_field.length === 0 && ml_platform !== '2')) {
182 button.hide();
183 } else {
184 button.show();
185 }
186
187 var ignored_p_field = a('#woocommerce_mailerlite_ignore_product_list');
188
189 if (ignored_p_field.length !== 0) {
190 ignored_p_field.closest('tr').before(
191 '<h2>E-commerce Automations</h2>\
192 <p class="section-description">Customize settings for your e-commerce automations created in MailerLite </p>'
193 )
194 }
195
196 var auto_update_field = a('#woocommerce_mailerlite_auto_update_plugin');
197
198 if (auto_update_field.length !== 0) {
199 auto_update_field.closest('tr').before(
200 '<h2>Plugin Updates</h2>\
201 <p class="section-description">Customize settings for MailerLite plugin </p>'
202 )
203 }
204
205 var refreshGroups = function() {
206 var c = a(this);
207 c.removeClass("error"), c.addClass("running");
208 a.ajax({
209 url: woo_ml_post.ajax_url,
210 type: "post",
211 dataType: 'JSON',
212 data: {
213 action: "post_woo_ml_refresh_groups"
214 },
215 success: function(res) {
216 c.removeClass("running");
217
218 let has_group = false;
219
220 if (res.groups) {
221 a('#woocommerce_mailerlite_group').empty();
222
223 for (const [id, name] of Object.entries(res.groups)) {
224
225 if (res.current && parseInt(res.current) === parseInt(id)) {
226 has_group = true;
227 }
228
229 a('#woocommerce_mailerlite_group').append(a('<option>', {
230 value: id,
231 text: name
232 }));
233 }
234 }
235
236 if (res.current && has_group) {
237 a('#woocommerce_mailerlite_group').val(res.current);
238 }
239 },
240 error: function(x, status) {
241 c.addClass("error");
242 }
243 });
244 }
245
246 var parseJSON = function(jsonStr){
247 try {
248 var parsed = JSON.parse(jsonStr);
249
250 if (parsed && typeof parsed === "object") {
251 return parsed;
252 }
253 }
254 catch (e) { }
255
256 return false;
257 }
258
259 if (a('#woocommerce_mailerlite_api_key').length > 0) {
260 refreshGroups();
261 }
262 });