PluginProbe
MailerLite – WooCommerce integration / 1.8.8
MailerLite – WooCommerce integration v1.8.8
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.8, at public/js/admin.js

261 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 success: function(a) {
143 location.reload()
144 }
145 })
146 }
147 });
148
149 if (a('#woocommerce_mailerlite_group').length > 0) {
150 a('#woocommerce_mailerlite_group').select2();
151 }
152
153 if (a('#woocommerce_mailerlite_ignore_product_list').length > 0) {
154 a('#woocommerce_mailerlite_ignore_product_list').select2();
155 }
156
157 var cs_field = a('#woocommerce_mailerlite_consumer_secret');
158
159 if (0 !== cs_field.length) {
160 var field_desc = cs_field.next(".description");
161 field_desc.closest('tr').after(
162 '<h2>Integration Details</h2>\
163 <p class="section-description">Customize MailerLite integration for WooCommerce</p>');
164 }
165
166 var ml_platform = '';
167
168 if (a('#ml_platform').length > 0) {
169 ml_platform = a('#ml_platform').val();
170 }
171
172 var tracking_field = a('#woocommerce_mailerlite_popups');
173
174 tracking_field.closest('tr').before(
175 '<h2>Popups</h2>\
176 <p class="section-description">Display pop-up subscribe forms created within MailerLite</p>');
177
178 var button = a('[name="save"]');
179
180 if (field.length !== 0 && (cs_field.length === 0 && ml_platform !== '2')) {
181 button.hide();
182 } else {
183 button.show();
184 }
185
186 var ignored_p_field = a('#woocommerce_mailerlite_ignore_product_list');
187
188 if (ignored_p_field.length !== 0) {
189 ignored_p_field.closest('tr').before(
190 '<h2>E-commerce Automations</h2>\
191 <p class="section-description">Customize settings for your e-commerce automations created in MailerLite </p>'
192 )
193 }
194
195 var auto_update_field = a('#woocommerce_mailerlite_auto_update_plugin');
196
197 if (auto_update_field.length !== 0) {
198 auto_update_field.closest('tr').before(
199 '<h2>Plugin Updates</h2>\
200 <p class="section-description">Customize settings for MailerLite plugin </p>'
201 )
202 }
203
204 var refreshGroups = function() {
205 var c = a(this);
206 c.removeClass("error"), c.addClass("running");
207 a.ajax({
208 url: woo_ml_post.ajax_url,
209 type: "post",
210 dataType: 'JSON',
211 data: {
212 action: "post_woo_ml_refresh_groups"
213 },
214 success: function(res) {
215 c.removeClass("running");
216
217 let has_group = false;
218
219 if (res.groups) {
220 a('#woocommerce_mailerlite_group').empty();
221
222 for (const [id, name] of Object.entries(res.groups)) {
223
224 if (res.current && parseInt(res.current) === parseInt(id)) {
225 has_group = true;
226 }
227
228 a('#woocommerce_mailerlite_group').append(a('<option>', {
229 value: id,
230 text: name
231 }));
232 }
233 }
234
235 if (res.current && has_group) {
236 a('#woocommerce_mailerlite_group').val(res.current);
237 }
238 },
239 error: function(x, status) {
240 c.addClass("error");
241 }
242 });
243 }
244
245 var parseJSON = function(jsonStr){
246 try {
247 var parsed = JSON.parse(jsonStr);
248
249 if (parsed && typeof parsed === "object") {
250 return parsed;
251 }
252 }
253 catch (e) { }
254
255 return false;
256 }
257
258 if (a('#woocommerce_mailerlite_api_key').length > 0) {
259 refreshGroups();
260 }
261 });