PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | assets/js/mainwp-plugins-themes.js +258 -139 5.2 → 6.2.2 View file →
@@ -1,7 +1,7 @@
1 -/* eslint complexity: ["error", 100] */
1 +/* eslint-disable complexity */
2 2
3 -window.mainwpVars = window.mainwpVars || {};
3 +globalThis.mainwpVars = globalThis.mainwpVars || {};
4 4
5 5 //Ignore plugin
6 6 jQuery(function () {
7 7 jQuery(document).on('click', 'input[name="plugins"]', function () {
@@ -77,27 +77,27 @@
77 77 });
78 78
79 79
80 80 // Manage Plugins -- Fetch plugins
81 -window.mainwp_fetch_plugins = function () {
81 +globalThis.mainwp_fetch_plugins = function (notFetchContent) {
82 82 let errors = [];
83 83 let selected_sites = [];
84 84 let selected_groups = [];
85 85 let selected_clients = [];
86 86
87 - if (jQuery('#select_by').val() == 'site') {
87 + if (jQuery('input[name="select_by"]').val() == 'site') {
88 88 jQuery("input[name='selected_sites[]']:checked").each(function () {
89 89 selected_sites.push(jQuery(this).val());
90 90 });
91 91 if (selected_sites.length == 0) {
92 - errors.push(__('Please select at least one website or group or client.'));
92 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
93 93 }
94 - } else if (jQuery('#select_by').val() == 'client') {
94 + } else if (jQuery('input[name="select_by"]').val() == 'client') {
95 95 jQuery("input[name='selected_clients[]']:checked").each(function () {
96 96 selected_clients.push(jQuery(this).val());
97 97 });
98 98 if (selected_clients.length == 0) {
99 - errors.push(__('Please select at least one website or group or client.'));
99 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
100 100 }
101 101 } else {
102 102 jQuery("input[name='selected_groups[]']:checked").each(function () {
103 103 selected_groups.push(jQuery(this).val());
@@ -102,9 +102,9 @@
102 102 jQuery("input[name='selected_groups[]']:checked").each(function () {
103 103 selected_groups.push(jQuery(this).val());
104 104 });
105 105 if (selected_groups.length == 0) {
106 - errors.push(__('Please select at least one website or group or client.'));
106 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
107 107 }
108 108 }
109 109
110 110
@@ -110,9 +110,9 @@
110 110
111 111 let _status = jQuery("#mainwp_plugins_search_by_status").dropdown("get value");
112 112
113 113 if (_status == null) {
114 - errors.push(__('Please select at least one plugin status.'));
114 + errors.push(MainWP.I18n.t('Please select at least one plugin status.'));
115 115 }
116 116
117 117 if (errors.length > 0) {
118 118 mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'yellow');
@@ -129,18 +129,26 @@
129 129 'sites[]': selected_sites,
130 130 'clients[]': selected_clients
131 131 });
132 132
133 - jQuery('#mainwp-loading-plugins-row').show();
133 + if (notFetchContent) {
134 + data.not_fetchdata = 1;
135 + }
134 136
137 + if (!notFetchContent) {
138 + jQuery('#mainwp-loading-plugins-row').show(); //Silience.
139 + }
140 +
135 141 jQuery.post(ajaxurl, data, function (response) {
136 - jQuery('#mainwp-loading-plugins-row').hide();
137 - jQuery('#mainwp-plugins-main-content').show();
142 + if (!notFetchContent) {
143 + jQuery('#mainwp-loading-plugins-row').hide();
144 + jQuery('#mainwp-plugins-main-content').show();
138 145
139 - if (response?.result) {
140 - jQuery('#mainwp-plugins-content').html(response.result);
141 - jQuery('#mainwp-plugins-bulk-actions-wapper').html(response.bulk_actions);
142 - jQuery('#mainwp-plugins-bulk-actions-wapper .ui.dropdown').dropdown();
146 + if (response?.result) {
147 + jQuery('#mainwp-plugins-content').html(response.result);
148 + jQuery('#mainwp-plugins-bulk-actions-wapper').html(response.bulk_actions);
149 + jQuery('#mainwp-plugins-bulk-actions-wapper .ui.dropdown').dropdown();
150 + }
143 151 }
144 152 }, 'json');
145 153 };
146 154
@@ -147,8 +155,16 @@
147 155
148 156 /**
149 157 * MainWP_Plugins.page
150 158 */
159 +
160 +let pluginCountSent;
161 +let pluginCountReceived;
162 +let pluginResetAllowed = true;
163 +let pluginCurrentProccesingQueueIndex = 0;
164 +let pluginCountCurrentProcces = 0;
165 +let pluginMaxProcces = mainwpVars.maxThreads;
166 +
151 167 jQuery(function () {
152 168 jQuery(document).on('click', '#mainwp-show-plugins', function () {
153 169 mainwp_fetch_plugins();
154 170 });
@@ -160,9 +176,9 @@
160 176 return val;
161 177 }).get();
162 178
163 179 let selectedIds = [];
164 - if (checkedVals instanceof Array) {
180 + if (Array.isArray(checkedVals)) {
165 181 jQuery.grep(checkedVals, function (val) {
166 182 if (jQuery.inArray(val, selectedIds) == -1) {
167 183 selectedIds.push(val);
168 184 }
@@ -167,11 +183,10 @@
167 183 selectedIds.push(val);
168 184 }
169 185 });
170 186 }
171 - console.log(selectedIds);
172 187 if (selectedIds.length == 0) {
173 - feedback('mainwp-message-zone', __('Please select at least one website.'), 'yellow');
188 + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website.'), 'yellow');
174 189 } else {
175 190 jQuery('#mainwp-message-zone').fadeOut(5000);
176 191 let ids = selectedIds.join("-");
177 192 let kwd = jQuery('#mainwp_plugin_search_by_keyword').val();
@@ -194,15 +209,11 @@
194 209 mainwp_fetch_all_active_plugins();
195 210 return false;
196 211 });
197 212
198 - let pluginCountSent;
199 - let pluginCountReceived;
200 - let pluginResetAllowed = true;
201 213
202 214 jQuery(document).on('click', '#mainwp-do-plugins-bulk-actions', function () {
203 215 let action = jQuery("#mainwp-bulk-actions").dropdown("get value");
204 - console.log(action);
205 216 if (action == '') {
206 217 return false;
207 218 }
208 219
@@ -212,9 +223,10 @@
212 223 pluginCountSent = 0;
213 224 pluginCountReceived = 0;
214 225 let selectedSites = [];
215 226 let selectedSitePlugins = [];
216 -
227 + pluginCurrentProccesingQueueIndex = 0;
228 + pluginCountCurrentProcces = 0;
217 229 //Find all checked boxes
218 230 jQuery('.mainwp-selected-plugin-site:checked').each(function () {
219 231 let rowElement = jQuery(this).closest('.mainwp-manage-plugin-item-website');
220 232 let websiteId = jQuery(rowElement).attr('site-id');
@@ -219,67 +231,22 @@
219 231 let rowElement = jQuery(this).closest('.mainwp-manage-plugin-item-website');
220 232 let websiteId = jQuery(rowElement).attr('site-id');
221 233 let pluginSlug = jQuery(rowElement).attr('plugin-slug');
222 234 selectedSitePlugins.push({ 'siteid': websiteId, 'plugin': pluginSlug });
223 - if (selectedSites.indexOf(websiteId) < 0) {
235 + if (!selectedSites.includes(websiteId)) {
224 236 selectedSites.push(websiteId);
225 237 }
226 238 });
227 239
228 - jQuery(selectedSites).each(function (idx, val) {
229 - let websiteId = val;
230 - let selectedPlugins = [];
231 -
232 - jQuery(selectedSitePlugins).each(function (idx, val) {
233 - if (val.siteid == websiteId) {
234 - if (jQuery('.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]').length > 0) {
235 - selectedPlugins.push(jQuery('.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]')[0]);
236 - }
237 - }
238 - });
239 -
240 - if (selectedPlugins.length == 0)
241 - return;
242 -
243 -
244 - if ((action == 'activate') || (action == 'delete') || (action == 'deactivate') || (action == 'ignore_updates')) {
245 - let pluginsToSend = [];
246 - let namesToSend = [];
247 - for (let ss of selectedPlugins) {
248 - pluginsToSend.push(jQuery(ss).attr('plugin-slug'));
249 - namesToSend.push(jQuery(ss).attr('plugin-name'));
250 - }
251 -
252 - let data = mainwp_secure_data({
253 - action: 'mainwp_plugin_' + action,
254 - plugins: pluginsToSend,
255 - websiteId: websiteId
256 - });
257 -
258 - if (action == 'ignore_updates') {
259 - data['names'] = namesToSend;
260 - }
261 -
262 - pluginCountSent++;
263 - jQuery.post(ajaxurl, data, function () {
264 - pluginCountReceived++;
265 - if (pluginResetAllowed && pluginCountReceived == pluginCountSent) {
266 - pluginCountReceived = 0;
267 - pluginCountSent = 0;
268 - jQuery('#mainwp_bulk_action_loading').hide();
269 - mainwp_fetch_plugins();
270 - }
271 - }, 'json');
240 + jQuery(selectedSitePlugins).each(function (idx, val) {
241 + let itselector = '.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]';
242 + if (jQuery(itselector).length > 0) {
243 + jQuery(itselector).html('<span><i class="clock outline icon"></i> Please wait…</span>');
272 244 }
273 245 });
274 246
247 + mainwp_manage_plugins_bulk_actions_perform(action, selectedSites, selectedSitePlugins);
275 248 pluginResetAllowed = true;
276 - if (pluginCountReceived == pluginCountSent) {
277 - pluginCountReceived = 0;
278 - pluginCountSent = 0;
279 - jQuery('#mainwp_bulk_action_loading').hide();
280 - mainwp_fetch_plugins();
281 - }
282 249 });
283 250
284 251 jQuery(document).on('click', '.mainwp-edit-plugin-note', function () {
285 252 let rowEl = jQuery(jQuery(this).parents('tr')[0]);
@@ -286,18 +253,18 @@
286 253 let slug = rowEl.attr('plugin-slug');
287 254 let name = rowEl.attr('plugin-name');
288 255 let note = rowEl.find('.esc-content-note').html();
289 256 jQuery('#mainwp-notes-title').html(decodeURIComponent(name));
290 - jQuery('#mainwp-notes-html').html(note == '' ? __('No saved notes. Click the Edit button to edit plugin notes.') : note);
257 + jQuery('#mainwp-notes-html').html(note == '' ? MainWP.I18n.t('No saved notes. Click the Edit button to edit plugin notes.') : note);
291 258 jQuery('#mainwp-notes-note').val(note);
292 259 jQuery('#mainwp-notes-slug').val(slug);
293 260 mainwp_notes_show();
294 261 });
295 262
296 - window.mainwp_notes_plugin_save = function () {
263 + globalThis.mainwp_notes_plugin_save = function () {
297 264 let slug = jQuery('#mainwp-notes-slug').val();
298 265 let newnote = jQuery('#mainwp-notes-note').val();
299 - newnote = newnote.replace(/(?:\r\n|\r|\n)/g, '<br>');
266 + newnote = newnote.replaceAll(/\r\n|\r|\n/g, '<br>');
300 267 let data = mainwp_secure_data({
301 268 action: 'mainwp_trusted_plugin_notes_save',
302 269 slug: slug,
303 270 note: newnote
@@ -302,16 +269,17 @@
302 269 slug: slug,
303 270 note: newnote
304 271 });
305 272
306 - jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...')).show();
273 + jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Saving note. Please wait...')).show();
307 274
308 275 jQuery.post(ajaxurl, data, function (pSlug) {
309 276 return function (response) {
310 277 let rowEl = jQuery('tr[plugin-slug="' + pSlug + '"]');
311 278 if (response.result == 'SUCCESS') {
312 - jQuery('#mainwp-notes-status').html('<i class="green check icon"></i> ' + __('Note saved!'));
313 - rowEl.find('.esc-content-note').html(jQuery('#mainwp-notes-note').val());
279 + jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Note saved successfully.')).addClass('green');
280 + rowEl.find('.esc-content-note').html(response?.esc_note_content??'');
281 + jQuery('#mainwp-notes-html').html(response?.esc_note_content??'');
314 282
315 283 if (newnote == '') {
316 284 rowEl.find('.mainwp-edit-plugin-note').html('<i class="sticky note outline icon"></i>');
317 285 } else {
@@ -317,15 +285,24 @@
317 285 } else {
318 286 rowEl.find('.mainwp-edit-plugin-note').html('<i class="sticky green note icon"></i>');
319 287 }
320 288
321 - } else if (response.error != undefined) {
322 - jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + __('Undefined error occured while saving your note') + ': ' + response.error);
289 + } else if (response.error === undefined) {
290 + jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + MainWP.I18n.t('Undefined error occurred while saving your note') + '.');
323 291 } else {
324 - jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + __('Undefined error occured while saving your note') + '.');
292 + jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + MainWP.I18n.t('Undefined error occurred while saving your note') + ': ' + response.error);
325 293 }
326 294 }
327 295 }(slug), 'json');
296 + setTimeout(function () {
297 + jQuery('#mainwp-notes-status').fadeOut(300);
298 + }, 3000);
299 +
300 + jQuery('#mainwp-notes-html').show();
301 + jQuery('#mainwp-notes-editor').hide();
302 + jQuery('#mainwp-notes-save').hide();
303 + jQuery('#mainwp-notes-edit').show();
304 +
328 305 return false;
329 306 }
330 307
331 308 jQuery(document).on('click', '.mainwp-edit-theme-note', function () {
@@ -340,12 +317,13 @@
340 317 jQuery('#mainwp-notes-slug').val(slug);
341 318 mainwp_notes_show();
342 319 });
343 320
344 - window.mainwp_notes_theme_save = function () {
321 + globalThis.mainwp_notes_theme_save = function () {
345 322 let slug = jQuery('#mainwp-notes-slug').val();
346 323 let newnote = jQuery('#mainwp-notes-note').val();
347 - newnote = newnote.replace(/(?:\r\n|\r|\n)/g, '<br>');
324 + newnote = newnote.replaceAll(/\r\n|\r|\n/g, '<br>');
325 +
348 326 let data = mainwp_secure_data({
349 327 action: 'mainwp_trusted_theme_notes_save',
350 328 slug: slug,
351 329 note: newnote
@@ -350,33 +328,45 @@
350 328 slug: slug,
351 329 note: newnote
352 330 });
353 331
354 - jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...'));
332 + jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Saving note. Please wait...')).show();
355 333
356 334 jQuery.post(ajaxurl, data, function (pSlug) {
357 335 return function (response) {
358 336 let rowEl = jQuery('tr[theme-slug="' + pSlug + '"]');
359 337 if (response.result == 'SUCCESS') {
360 - jQuery('#mainwp-notes-status').html('<i class="green check icon"></i> ' + __('Note saved!'));
361 - rowEl.find('.esc-content-note').html(jQuery('#mainwp-notes-note').val());
338 + jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Note saved successfully.')).addClass('green');
339 + rowEl.find('.esc-content-note').html(response?.esc_note_content??'');
340 + jQuery('#mainwp-notes-html').html(response?.esc_note_content??'');
362 341 if (newnote == '') {
363 342 rowEl.find('.mainwp-edit-theme-note').html('<i class="sticky note outline icon"></i>');
364 343 } else {
365 344 rowEl.find('.mainwp-edit-theme-note').html('<i class="sticky green note icon"></i>');
366 345 }
367 - } else if (response.error != undefined) {
368 - jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + __('Undefined error occured while saving your note!') + ': ' + response.error);
346 + } else if (response.error === undefined) {
347 + jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + MainWP.I18n.t('Undefined error occurred while saving your note!'));
369 348 } else {
370 - jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + __('Undefined error occured while saving your note!'));
349 + jQuery('#mainwp-notes-status').html('<i class="times red icon"></i> ' + MainWP.I18n.t('Undefined error occurred while saving your note!') + ': ' + response.error);
371 350 }
372 351 }
373 352 }(slug), 'json');
353 + setTimeout(function () {
354 + jQuery('#mainwp-notes-status').fadeOut(300);
355 + }, 3000);
356 +
357 + jQuery('#mainwp-notes-html').show();
358 + jQuery('#mainwp-notes-editor').hide();
359 + jQuery('#mainwp-notes-save').hide();
360 + jQuery('#mainwp-notes-edit').show();
361 +
374 362 return false;
375 363 }
376 364 });
377 365
378 -window.mainwp_show_hide_install_to_selected_sites = function (what) {
366 +
367 +
368 +globalThis.mainwp_show_hide_install_to_selected_sites = function (what) {
379 369 if ('plugin' == what) {
380 370 jQuery('#mainwp-plugins-content .checkbox').on('click', function () {
381 371 if (jQuery('.mainwp-manage-plugin-item-website .checkbox.checked').length > 0) {
382 372 jQuery('#mainwp-install-to-selected-sites').show();
@@ -394,8 +384,110 @@
394 384 });
395 385 }
396 386 }
397 387
388 +let mainwp_manage_plugins_bulk_actions_next = function (action, selectedSites, selectedSitePlugins) {
389 + if (pluginCurrentProccesingQueueIndex < selectedSites.length) {
390 + mainwp_manage_plugins_bulk_actions_perform(action, selectedSites, selectedSitePlugins);
391 + }
392 + mainwp_manage_plugins_bulk_actions_check_done();
393 +};
394 +
395 +let mainwp_manage_plugins_bulk_actions_check_done = function () {
396 + if (pluginCountReceived == pluginCountSent) {
397 + pluginCountReceived = 0;
398 + pluginCountSent = 0;
399 + jQuery('#mainwp_bulk_action_loading').hide();
400 + }
401 +};
402 +
403 +// Bulk processing plugins.
404 +let mainwp_manage_plugins_bulk_actions_perform = function (action, selectedSites, selectedSitePlugins) {
405 +
406 + let websiteId = 0;
407 +
408 + if (selectedSites[pluginCurrentProccesingQueueIndex]) {
409 + websiteId = selectedSites[pluginCurrentProccesingQueueIndex];
410 + }
411 +
412 + pluginCurrentProccesingQueueIndex++;
413 +
414 + if (!websiteId) {
415 + mainwp_manage_plugins_bulk_actions_next(action, selectedSites, selectedSitePlugins);
416 + return;
417 + }
418 +
419 + let selectedPlugins = [];
420 +
421 + jQuery(selectedSitePlugins).each(function (idx, val) {
422 + if (val.siteid == websiteId) {
423 + let itselector = '.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]';
424 + if (jQuery(itselector).length > 0) {
425 + selectedPlugins.push(jQuery(itselector)[0]);
426 + }
427 + }
428 + });
429 +
430 + if (selectedPlugins.length == 0) {
431 + mainwp_manage_plugins_bulk_actions_next(action, selectedSites, selectedSitePlugins);
432 + return;
433 + }
434 +
435 + if ((action == 'activate') || (action == 'delete') || (action == 'deactivate') || (action == 'ignore_updates')) {
436 + let pluginsToSend = [];
437 + let namesToSend = [];
438 + for (let ss of selectedPlugins) {
439 + pluginsToSend.push(jQuery(ss).attr('plugin-slug'));
440 + namesToSend.push(jQuery(ss).attr('plugin-name'));
441 + jQuery(ss).html('<span><i class="ui active inline loader tiny"></i> Please wait…<span>');
442 + }
443 +
444 + let data = mainwp_secure_data({
445 + action: 'mainwp_plugin_' + action,
446 + plugins: pluginsToSend,
447 + websiteId: websiteId
448 + });
449 +
450 + if (action == 'ignore_updates') {
451 + data['names'] = namesToSend;
452 + }
453 + pluginCountCurrentProcces++;
454 + pluginCountSent++;
455 +
456 + jQuery.post(ajaxurl, data, function (response) {
457 + pluginCountCurrentProcces--;
458 + pluginCountReceived++;
459 + for (let ss of selectedPlugins) {
460 + let pslug = jQuery(ss).attr('plugin-slug');
461 + let itselector = '.mainwp-manage-plugin-item-website[site-id="' + websiteId + '"][plugin-slug="' + pslug + '"]';
462 + if (jQuery(itselector).length > 0) {
463 + if (response?.error) {
464 + jQuery(itselector).html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
465 + } else if (response?.result) {
466 + jQuery(itselector).html('<span><i class="green check icon"></i></span>');
467 + } else {
468 + jQuery(itselector).html('<span data-tooltip="Invalid response from the server, please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
469 + }
470 + }
471 + }
472 + if (response?.result) {
473 + for (let ss of selectedPlugins) {
474 + let pslug = jQuery(ss).attr('plugin-slug');
475 + let itselector = '.mainwp-manage-plugin-item-website[site-id="' + websiteId + '"][plugin-slug="' + pslug + '"]';
476 + setTimeout(function () {
477 + jQuery(itselector).fadeOut(1000);
478 + }, 1000);
479 + }
480 + }
481 + if (pluginCountCurrentProcces < pluginMaxProcces) {
482 + mainwp_manage_plugins_bulk_actions_next(action, selectedSites, selectedSitePlugins);
483 + } else {
484 + mainwp_manage_plugins_bulk_actions_check_done();
485 + }
486 + }, 'json');
487 + }
488 +}
489 +
398 490 // Fetch plugins for the Auto Update feature
399 491 let mainwp_fetch_all_active_plugins = function () {
400 492 let data = mainwp_secure_data({
401 493 action: 'mainwp_plugins_search_all_active',
@@ -409,8 +501,13 @@
409 501 jQuery.post(ajaxurl, data, function (response) {
410 502 response = response.trim();
411 503 jQuery('#mainwp-auto-updates-plugins-content').find('.dimmer').removeClass('active');
412 504 jQuery('#mainwp-auto-updates-plugins-table-wrapper').html(response);
505 + if (jQuery('#mainwp-auto-updates-plugins-table-wrapper').find('.mainwp-empty-page-placeholder').length > 0) {
506 + jQuery('#mainwp-plugin-auto-updates .mainwp-actions-bar').hide();
507 + } else {
508 + jQuery('#mainwp-plugin-auto-updates .mainwp-actions-bar').show();
509 + }
413 510 });
414 511 };
415 512
416 513 // Fetch themes for the Auto Update feature
@@ -426,8 +523,13 @@
426 523
427 524 jQuery.post(ajaxurl, data, function (response) {
428 525 jQuery('#mainwp-auto-updates-themes-content').find('.dimmer').removeClass('active');
429 526 jQuery('#mainwp-auto-updates-themes-table-wrapper').html(response);
527 + if (jQuery('#mainwp-auto-updates-themes-table-wrapper').find('.mainwp-empty-page-placeholder').length > 0) {
528 + jQuery('#mainwp-theme-auto-updates .mainwp-actions-bar').hide();
529 + } else {
530 + jQuery('#mainwp-theme-auto-updates .mainwp-actions-bar').show();
531 + }
430 532 });
431 533 };
432 534
433 535 /**
@@ -445,9 +547,9 @@
445 547 return val;
446 548 }).get();
447 549
448 550 let selectedIds = [];
449 - if (checkedVals instanceof Array) {
551 + if (Array.isArray(checkedVals)) {
450 552 jQuery.grep(checkedVals, function (val) {
451 553 if (jQuery.inArray(val, selectedIds) == -1) {
452 554 selectedIds.push(val);
453 555 }
@@ -454,9 +556,9 @@
454 556 });
455 557 }
456 558
457 559 if (selectedIds.length == 0) {
458 - feedback('mainwp-message-zone', __('Please select at least one website.'), 'yellow');
560 + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website.'), 'yellow');
459 561 } else {
460 562 jQuery('#mainwp-message-zone').fadeOut(5000);
461 563 let ids = selectedIds.join("-");
462 564 let kwd = jQuery('#mainwp_theme_search_by_keyword').val();
@@ -486,9 +588,8 @@
486 588 let themeResetAllowed = true;
487 589
488 590 jQuery(document).on('click', '#mainwp-do-themes-bulk-actions', function () {
489 591 let action = jQuery("#mainwp-bulk-actions").dropdown("get value");
490 - console.log(action);
491 592 if (action == '' || action == 'none')
492 593 return;
493 594
494 595 jQuery('#mainwp-do-themes-bulk-actions').attr('disabled', 'true');
@@ -503,10 +604,14 @@
503 604 jQuery('.mainwp-selected-theme-site:checked').each(function () {
504 605 let rowElement = jQuery(this).closest('.mainwp-manage-theme-item-website');
505 606 let websiteId = jQuery(rowElement).attr('site-id');
506 607 let theme = jQuery(rowElement).attr('theme-slug');
608 + if (action == 'activate' && jQuery(rowElement).attr('is-actived') == 1) {
609 + jQuery(rowElement).find('.mainwp-selected-theme-site').attr('checked', false);
610 + return;
611 + }
507 612 selectedSiteThemes.push({ 'siteid': websiteId, 'theme': theme });
508 - if (selectedSites.indexOf(websiteId) < 0) {
613 + if (!selectedSites.includes(websiteId)) {
509 614 selectedSites.push(websiteId);
510 615 }
511 616 });
512 617
@@ -560,9 +665,9 @@
560 665 });
561 666 } else if (action == 'delete') {
562 667 let themesToDelete = [];
563 668 for (let ss of selectedThemes) {
564 - if (jQuery(ss).attr('not-delete') == 1) {
669 + if (jQuery(ss).attr('not-delete') == 1 || jQuery(ss).attr('is-actived') == 1) {
565 670 jQuery(ss).find('.mainwp-selected-theme-site').attr('checked', false);
566 671 continue;
567 672 }
568 673 themesToDelete.push(jQuery(ss).attr('theme-slug'));
@@ -577,12 +682,12 @@
577 682 });
578 683
579 684 themeCountSent++;
580 685 jQuery.post(ajaxurl, data, function (response) {
581 - if (response.error != undefined && response.error == Object(response.error)) { // check if .error is object.
686 + if (response.error != undefined && response.error == new Object(response.error)) { // check if .error is object.
582 687 let entries = Object.entries(response.error);
583 688 for (let entry of entries) {
584 - let warnings = __(entry[0], encodeURIComponent(entry[1])); // entry[0]:id message, entry[1] string value.
689 + let warnings = MainWP.I18n.t(entry[0], encodeURIComponent(entry[1])); // entry[0]:id message, entry[1] string value.
585 690 jQuery('#mainwp-message-zone').after('<div class="ui info message yellow"><i class="ui close icon"></i><span>' + warnings + '</span></div>');
586 691 }
587 692 }
588 693 themeCountReceived++;
@@ -610,27 +715,27 @@
610 715 });
611 716
612 717
613 718 // Manage Themes -- Fetch themes from child sites
614 -window.mainwp_fetch_themes = function () {
719 +globalThis.mainwp_fetch_themes = function (notFetchContent) {
615 720 let errors = [];
616 721 let selected_sites = [];
617 722 let selected_groups = [];
618 723 let selected_clients = [];
619 724
620 - if (jQuery('#select_by').val() == 'site') {
725 + if (jQuery('input[name="select_by"]').val() == 'site') {
621 726 jQuery("input[name='selected_sites[]']:checked").each(function () {
622 727 selected_sites.push(jQuery(this).val());
623 728 });
624 729 if (selected_sites.length == 0) {
625 - errors.push(__('Please select at least one website or group or client.'));
730 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
626 731 }
627 - } else if (jQuery('#select_by').val() == 'client') {
732 + } else if (jQuery('input[name="select_by"]').val() == 'client') {
628 733 jQuery("input[name='selected_clients[]']:checked").each(function () {
629 734 selected_clients.push(jQuery(this).val());
630 735 });
631 736 if (selected_clients.length == 0) {
632 - errors.push(__('Please select at least one website or group or client.'));
737 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
633 738 }
634 739 } else {
635 740 jQuery("input[name='selected_groups[]']:checked").each(function () {
636 741 selected_groups.push(jQuery(this).val());
@@ -635,15 +740,15 @@
635 740 jQuery("input[name='selected_groups[]']:checked").each(function () {
636 741 selected_groups.push(jQuery(this).val());
637 742 });
638 743 if (selected_groups.length == 0) {
639 - errors.push(__('Please select at least one website or group or client.'));
744 + errors.push(MainWP.I18n.t('Please select at least one website or group or client.'));
640 745 }
641 746 }
642 747
643 748 let _status = jQuery("#mainwp_themes_search_by_status").dropdown("get value");
644 749 if (_status == null) {
645 - errors.push(__('Please select at least one theme status.'));
750 + errors.push(MainWP.I18n.t('Please select at least one theme status.'));
646 751 }
647 752
648 753 if (errors.length > 0) {
649 754 mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'yellow');
@@ -661,17 +766,26 @@
661 766 'sites[]': selected_sites,
662 767 'clients[]': selected_clients
663 768 });
664 769
665 - jQuery('#mainwp-loading-themes-row').show();
770 + if (notFetchContent) {
771 + data.not_fetchdata = 1;
772 + }
666 773
774 + if (!notFetchContent) {
775 + jQuery('#mainwp-loading-themes-row').show();
776 + }
777 +
667 778 jQuery.post(ajaxurl, data, function (response) {
668 - jQuery('#mainwp-loading-themes-row').hide();
669 - jQuery('#mainwp-themes-main-content').show();
670 - if (response?.result) {
671 - jQuery('#mainwp-themes-content').html(response.result);
672 - jQuery('#mainwp-themes-bulk-actions-wapper').html(response.bulk_actions);
673 - jQuery('#mainwp-themes-bulk-actions-wapper .ui.dropdown').dropdown();
779 + if (!notFetchContent) {
780 + jQuery('#mainwp-loading-themes-row').hide();
781 + jQuery('#mainwp-themes-main-content').show();
782 + if (response?.result) {
783 + jQuery('#mainwp-themes-content').html(response.result);
784 + jQuery('#mainwp-themes-bulk-actions-wapper').html(response.bulk_actions);
785 + jQuery('#mainwp-themes-bulk-actions-wapper .ui.dropdown').dropdown();
786 + mainwp_show_hide_install_to_selected_sites( 'theme' );
787 + }
674 788 }
675 789 }, 'json');
676 790 };
677 791
@@ -687,13 +801,18 @@
687 801 manage_plugin_Action(jQuery(this), 'activate');
688 802 return false;
689 803 });
690 804 jQuery(document).on('click', '.mainwp-manage-plugin-delete', function () {
691 - manage_plugin_Action(jQuery(this), 'delete');
805 + let name = jQuery(this).closest('.mainwp-manage-plugin-item-website').attr('plugin-name');
806 + let confirmMsg = MainWP.I18n.t('You are about to delete the %1?', name);
807 + mainwp_confirm(confirmMsg,() => {
808 + manage_plugin_Action(jQuery(this), 'delete');
809 + });
692 810 return false;
693 811 });
694 812 });
695 813
814 +
696 815 let manage_plugin_Action = function (elem, what) {
697 816 let rowElement = jQuery(elem).closest('.mainwp-manage-plugin-item-website');
698 817 let plugin = rowElement.attr('plugin-slug');
699 818 let websiteId = rowElement.attr('site-id');
@@ -704,9 +823,9 @@
704 823 websiteId: websiteId
705 824 });
706 825 let start_row = '<div class="one wide center aligned middle aligned column"></div><div class="thirteen wide left aligned middle aligned column">';
707 826 let end_row = '</div>';
708 - jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + __('Please wait...') + end_row);
827 + jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + MainWP.I18n.t('Please wait...') + end_row);
709 828 jQuery.post(ajaxurl, data, function (response) {
710 829 if (response?.error) {
711 830 jQuery(rowElement).html(start_row + '<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
712 831 } else if (response?.result) {
@@ -711,20 +830,19 @@
711 830 jQuery(rowElement).html(start_row + '<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
712 831 } else if (response?.result) {
713 832 if (what == 'delete') {
714 833 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + '</div>');
715 - setTimeout(function () {
716 - jQuery(rowElement).fadeOut(1000);
717 - }, 1000);
718 -
719 834 } else {
720 835 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + end_row);
721 836 }
722 837 setTimeout(function () {
723 - mainwp_fetch_plugins();
838 + jQuery(rowElement).fadeOut(1000);
839 + }, 1000);
840 + setTimeout(function () {
841 + mainwp_fetch_plugins(true);
724 842 }, 3000);
725 843 } else {
726 - jQuery(rowElement).html(start_row + '<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
844 + jQuery(rowElement).html(start_row + '<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
727 845 }
728 846 }, 'json');
729 847
730 848 return false;
@@ -731,9 +849,9 @@
731 849 };
732 850
733 851
734 852 let manage_plugins_upgrade = function (slug, websiteid) {
735 - let msg = __('Are you sure you want to update the plugin on the selected site?');
853 + let msg = MainWP.I18n.t('Are you sure you want to update the plugin on the selected site?');
736 854 mainwp_confirm(msg, function () {
737 855 return manage_plugins_upgrade_int(slug, websiteid);
738 856 }, false, 1);
739 857 };
@@ -738,9 +856,8 @@
738 856 }, false, 1);
739 857 };
740 858
741 859 let manage_plugins_upgrade_continueAfterBackup = function (slug, websiteId, websiteHolder) {
742 - console.log('plugin upgrade continue');
743 860 let siteHolder = websiteHolder;
744 861 return function () {
745 862 let data = mainwp_secure_data({
746 863 action: 'mainwp_upgradeplugintheme',
@@ -760,9 +877,9 @@
760 877 let res = response.result;
761 878 let res_error = response.result_error;
762 879 if (res[slug]) {
763 880 siteHolder.attr('updated', 1);
764 - siteHolder.find('.column.update-column').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>');
881 + siteHolder.find('.column.update-column').html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>');
765 882 } else if (res_error[slug]) {
766 883 let _error = res_error[slug];
767 884 let _icon = '<i class="red times icon"></i>';
768 885 let roll_error = mainwp_updates_get_rollback_msg(_error);
@@ -837,9 +954,13 @@
837 954 manages_themeAction(jQuery(this), 'activate');
838 955 return false;
839 956 });
840 957 jQuery(document).on('click', '.mainwp-manages-theme-delete', function () {
841 - manages_themeAction(jQuery(this), 'delete');
958 + let name = jQuery(this).closest('.mainwp-manage-theme-item-website').attr('theme-name');
959 + let confirmMsg = MainWP.I18n.t('You are about to delete the %1?', name);
960 + mainwp_confirm(confirmMsg, () => {
961 + manages_themeAction(jQuery(this), 'delete');
962 + });
842 963 return false;
843 964 });
844 965 });
845 966
@@ -856,9 +977,9 @@
856 977
857 978 let start_row = '<div class="one wide center aligned middle aligned column"></div><div class="thirteen wide left aligned middle aligned column">';
858 979 let end_row = '</div>';
859 980
860 - jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + __('Please wait...') + end_row);
981 + jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + MainWP.I18n.t('Please wait...') + end_row);
861 982 jQuery.post(ajaxurl, data, function (response) {
862 983 if (response?.error) {
863 984 jQuery(rowElement).html(start_row + '<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
864 985 } else if (response?.result) {
@@ -871,12 +992,12 @@
871 992 } else {
872 993 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + end_row);
873 994 }
874 995 setTimeout(function () {
875 - mainwp_fetch_themes();
876 - }, 3000);
996 + mainwp_fetch_themes(true);
997 + }, 100);
877 998 } else {
878 - jQuery(rowElement).html(start_row + '<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
999 + jQuery(rowElement).html(start_row + '<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>' + end_row);
879 1000 }
880 1001 }, 'json');
881 1002
882 1003 return false;
@@ -883,9 +1004,9 @@
883 1004 };
884 1005
885 1006
886 1007 let manage_themes_upgrade_theme = function (slug, websiteid) {
887 - let msg = __('Are you sure you want to update the theme on the selected site?');
1008 + let msg = MainWP.I18n.t('Are you sure you want to update the theme on the selected site?');
888 1009 mainwp_confirm(msg, function () {
889 1010 return manage_themes_upgrade_int(slug, websiteid);
890 1011 }, false, 1);
891 1012 };
@@ -890,9 +1011,8 @@
890 1011 }, false, 1);
891 1012 };
892 1013
893 1014 let manage_themes_upgrade_continueAfterBackup = function (slug, websiteId, websiteHolder) {
894 - console.log('theme upgrade continue');
895 1015 let siteHolder = websiteHolder;
896 1016 let pSlug = slug;
897 1017 return function () {
898 1018 let data = mainwp_secure_data({
@@ -913,9 +1033,9 @@
913 1033 let res = response.result;
914 1034 let res_error = response.result_error;
915 1035 if (res[pSlug]) {
916 1036 siteHolder.attr('updated', 1);
917 - siteHolder.find('.column.update-column').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>');
1037 + siteHolder.find('.column.update-column').html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>');
918 1038 } else if (res_error ? res_error[slug] : false) {
919 1039 let _error = res_error[slug];
920 1040 let _icon = '<i class="red times icon"></i>';
921 1041 let roll_error = mainwp_updates_get_rollback_msg(_error);
@@ -982,16 +1102,16 @@
982 1102 * Check Backups.
983 1103 */
984 1104 let mainwp_manages_checkBackups = function (sitesToUpdate, siteNames, continueAfterBackup) {
985 1105 let managesitesShowBusyFunction = function () {
986 - let output = __('Checking if a backup is required for the selected updates...');
1106 + let output = MainWP.I18n.t('Checking if a backup is required for the selected updates...');
987 1107 mainwpPopup('#managesites-backup-box').getContentEl().html(output);
988 1108 jQuery('#managesites-backup-all').hide();
989 1109 jQuery('#managesites-backup-ignore').hide();
990 1110 mainwpPopup('#managesites-backup-box').init({
991 - title: __("Checking backup settings..."), callback: function () {
1111 + title: MainWP.I18n.t("Checking backup settings..."), callback: function () {
992 1112 mainwpVars.bulkManageSitesTaskRunning = false;
993 - window.location.href = location.href;
1113 + mainwp_forceReload();
994 1114 }
995 1115 });
996 1116
997 1117 };
@@ -1027,13 +1147,12 @@
1027 1147 }
1028 1148
1029 1149 if (siteFeedback != undefined) {
1030 1150 mainwp_managesites_prepare_backup_popup(response, pSiteNames, siteFeedback);
1031 - console.log(typeof continueAfterBackup);
1032 1151 mainwpPopup('#managesites-backup-box').init({
1033 - title: __("Full backup required!"), callback: function () {
1152 + title: MainWP.I18n.t("Full backup required!"), callback: function () {
1034 1153 continueAfterBackup = undefined;
1035 - window.location.href = location.href;
1154 + mainwp_forceReload();
1036 1155 }
1037 1156 });
1038 1157
1039 1158 return false;