PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.2
6.2.3 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 All 156 releases
mainwp / assets / js / mainwp-plugins-themes.js

mainwp-plugins-themes.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.2, at assets/js/mainwp-plugins-themes.js

1,085 lines 43.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* eslint complexity: ["error", 100] */
2 //Ignore plugin
3 jQuery(document).ready(function () {
4 jQuery(document).on('click', 'input[name="plugins"]', function () {
5 if (jQuery(this).is(':checked')) {
6 jQuery('input[name="plugins"]').attr('checked', 'checked');
7 jQuery('input[name="plugin[]"]').attr('checked', 'checked');
8 } else {
9 jQuery('input[name="plugins"]').prop("checked", false);
10 jQuery('input[name="plugin[]"]').prop("checked", false);
11 }
12 });
13 jQuery(document).on('click', 'input[name="themes"]', function () {
14 if (jQuery(this).is(':checked')) {
15 jQuery('input[name="themes"]').attr('checked', 'checked');
16 jQuery('input[name="theme[]"]').attr('checked', 'checked');
17 } else {
18 jQuery('input[name="themes"]').prop("checked", false);
19 jQuery('input[name="theme[]"]').prop("checked", false);
20 }
21 });
22
23 jQuery(document).on('click', '#mainwp-bulk-trust-plugins-action-apply', function () {
24
25 var action = jQuery("#mainwp-bulk-actions").dropdown("get value");
26
27 if (action == 'none')
28 return false;
29
30 var slugs = jQuery.map(jQuery("input[name='plugin[]']:checked"), function (el) {
31 return jQuery(el).val();
32 });
33
34 if (slugs.length == 0)
35 return false;
36
37 jQuery('#mainwp-bulk-trust-plugins-action-apply').attr('disabled', 'true');
38
39 var data = mainwp_secure_data({
40 action: 'mainwp_trust_plugin',
41 slugs: slugs,
42 do: action
43 });
44
45 jQuery.post(ajaxurl, data, function () {
46 jQuery('#mainwp-bulk-trust-plugins-action-apply').prop("disabled", false);
47 mainwp_fetch_all_active_plugins();
48 }, 'json');
49
50 return false;
51 });
52 jQuery(document).on('click', '#mainwp-bulk-trust-themes-action-apply', function () {
53 var action = jQuery("#mainwp-bulk-actions").dropdown("get value");
54 if (action == 'none')
55 return false;
56
57 var slugs = jQuery.map(jQuery("input[name='theme[]']:checked"), function (el) {
58 return jQuery(el).val();
59 });
60 if (slugs.length == 0)
61 return false;
62
63 jQuery('#mainwp-bulk-trust-themes-action-apply').attr('disabled', 'true');
64
65 var data = mainwp_secure_data({
66 action: 'mainwp_trust_theme',
67 slugs: slugs,
68 do: action
69 });
70
71 jQuery.post(ajaxurl, data, function () {
72 jQuery('#mainwp-bulk-trust-themes-action-apply').prop("disabled", false);
73 mainwp_fetch_all_themes();
74 }, 'json');
75
76 return false;
77 });
78 });
79
80
81 /**
82 * MainWP_Plugins.page
83 */
84 jQuery(document).ready(function () {
85 jQuery(document).on('click', '#mainwp-show-plugins', function () {
86 mainwp_fetch_plugins();
87 });
88
89 jQuery(document).on('click', '#mainwp-install-to-selected-sites', function () {
90 var checkedVals = jQuery('.mainwp-manage-plugin-item-website .mainwp-selected-plugin-site:checked').map(function () {
91 var rowElement = jQuery(this).closest('.mainwp-manage-plugin-item-website');
92 var val = rowElement.attr("site-id");
93 return val;
94 }).get();
95
96 var selectedIds = [];
97 if (checkedVals instanceof Array) {
98 jQuery.grep(checkedVals, function (val) {
99 if (jQuery.inArray(val, selectedIds) == -1) {
100 selectedIds.push(val);
101 }
102 });
103 }
104 console.log(selectedIds);
105 if (selectedIds.length == 0) {
106 feedback('mainwp-message-zone', __('Please select at least one website.'), 'yellow');
107 return false;
108 } else {
109 jQuery('#mainwp-message-zone').fadeOut(5000);
110 var ids = selectedIds.join("-");
111 var kwd = jQuery('#mainwp_plugin_search_by_keyword').val();
112 if ('' != kwd) {
113 kwd = '&s=' + encodeURIComponent(kwd);
114 }
115 location.href = 'admin.php?page=PluginsInstall&selected_sites=' + ids + kwd;
116 }
117 return false;
118 });
119
120 jQuery('#mainwp-plugins-content .checkbox').on('click', function () {
121 if (jQuery('.mainwp-manage-plugin-item-website .checkbox.checked').length > 0) {
122 jQuery('#mainwp-install-to-selected-sites').show();
123 } else {
124 jQuery('#mainwp-install-to-selected-sites').hide();
125 }
126 });
127
128 jQuery('#mainwp_show_all_active_plugins').on('click', function () {
129 mainwp_fetch_all_active_plugins();
130 return false;
131 });
132
133 var pluginCountSent;
134 var pluginCountReceived;
135 var pluginResetAllowed = true;
136
137 jQuery(document).on('click', '#mainwp-do-plugins-bulk-actions', function () {
138 var action = jQuery("#mainwp-bulk-actions").dropdown("get value");
139 console.log(action);
140 if (action == '') {
141 return false;
142 }
143
144 jQuery(this).attr('disabled', 'true');
145 jQuery('#mainwp_bulk_action_loading').show();
146 pluginResetAllowed = false;
147 pluginCountSent = 0;
148 pluginCountReceived = 0;
149 var selectedSites = [];
150 var selectedSitePlugins = [];
151
152 //Find all checked boxes
153 jQuery('.mainwp-selected-plugin-site:checked').each(function () {
154 var rowElement = jQuery(this).closest('.mainwp-manage-plugin-item-website');
155 var websiteId = jQuery(rowElement).attr('site-id');
156 var pluginSlug = jQuery(rowElement).attr('plugin-slug');
157 selectedSitePlugins.push({ 'siteid': websiteId, 'plugin': pluginSlug });
158 if (selectedSites.indexOf(websiteId) < 0) {
159 selectedSites.push(websiteId);
160 }
161 });
162
163 jQuery(selectedSites).each(function (idx, val) {
164 var websiteId = val;
165 var selectedPlugins = [];
166
167 jQuery(selectedSitePlugins).each(function (idx, val) {
168 if (val.siteid == websiteId) {
169 if (jQuery('.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]').length > 0) {
170 selectedPlugins.push(jQuery('.mainwp-manage-plugin-item-website[site-id="' + val.siteid + '"][plugin-slug="' + val.plugin + '"]')[0]);
171 }
172 }
173 });
174
175 if (selectedPlugins.length == 0)
176 return;
177
178
179 if ((action == 'activate') || (action == 'delete') || (action == 'deactivate') || (action == 'ignore_updates')) {
180 var pluginsToSend = [];
181 var namesToSend = [];
182 for (var i = 0; i < selectedPlugins.length; i++) {
183 pluginsToSend.push(jQuery(selectedPlugins[i]).attr('plugin-slug'));
184 namesToSend.push(jQuery(selectedPlugins[i]).attr('plugin-name'));
185 }
186
187 var data = mainwp_secure_data({
188 action: 'mainwp_plugin_' + action,
189 plugins: pluginsToSend,
190 websiteId: websiteId
191 });
192
193 if (action == 'ignore_updates') {
194 data['names'] = namesToSend;
195 }
196
197 pluginCountSent++;
198 jQuery.post(ajaxurl, data, function () {
199 pluginCountReceived++;
200 if (pluginResetAllowed && pluginCountReceived == pluginCountSent) {
201 pluginCountReceived = 0;
202 pluginCountSent = 0;
203 jQuery('#mainwp_bulk_action_loading').hide();
204 mainwp_fetch_plugins();
205 }
206 }, 'json');
207 }
208 });
209
210 pluginResetAllowed = true;
211 if (pluginCountReceived == pluginCountSent) {
212 pluginCountReceived = 0;
213 pluginCountSent = 0;
214 jQuery('#mainwp_bulk_action_loading').hide();
215 mainwp_fetch_plugins();
216 }
217 });
218
219 jQuery(document).on('click', '.mainwp-edit-plugin-note', function () {
220 var rowEl = jQuery(jQuery(this).parents('tr')[0]);
221 var slug = rowEl.attr('plugin-slug');
222 var name = rowEl.attr('plugin-name');
223 var note = rowEl.find('.esc-content-note').html();
224 jQuery('#mainwp-notes-title').html(decodeURIComponent(name));
225 jQuery('#mainwp-notes-html').html(note == '' ? __('No saved notes. Click the Edit button to edit plugin notes.') : note);
226 jQuery('#mainwp-notes-note').val(note);
227 jQuery('#mainwp-notes-slug').val(slug);
228 mainwp_notes_show();
229 });
230
231 mainwp_notes_plugin_save = function () {
232 var slug = jQuery('#mainwp-notes-slug').val();
233 var newnote = jQuery('#mainwp-notes-note').val();
234 newnote = newnote.replace(/(?:\r\n|\r|\n)/g, '<br>');
235 var data = mainwp_secure_data({
236 action: 'mainwp_trusted_plugin_notes_save',
237 slug: slug,
238 note: newnote
239 });
240
241 jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...'));
242
243 jQuery.post(ajaxurl, data, function (pSlug) {
244 return function (response) {
245 var rowEl = jQuery('tr[plugin-slug="' + pSlug + '"]');
246 if (response.result == 'SUCCESS') {
247 jQuery('#mainwp-notes-status').html('<i class="check circle green icon"></i> ' + __('Note saved!'));
248 rowEl.find('.esc-content-note').html(jQuery('#mainwp-notes-note').val());
249
250 if (newnote == '') {
251 rowEl.find('.mainwp-edit-plugin-note').html('<i class="sticky note outline icon"></i>');
252 } else {
253 rowEl.find('.mainwp-edit-plugin-note').html('<i class="sticky green note icon"></i>');
254 }
255
256 } else if (response.error != undefined) {
257 jQuery('#mainwp-notes-status').html('<i class="times circle red icon"></i> ' + __('Undefined error occured while saving your note') + ': ' + response.error);
258 } else {
259 jQuery('#mainwp-notes-status').html('<i class="times circle red icon"></i> ' + __('Undefined error occured while saving your note') + '.');
260 }
261 }
262 }(slug), 'json');
263 return false;
264 }
265
266 jQuery(document).on('click', '.mainwp-edit-theme-note', function () {
267 var rowEl = jQuery(jQuery(this).parents('tr')[0]);
268 var slug = rowEl.attr('theme-slug');
269 var name = rowEl.attr('theme-name');
270 var note = rowEl.find('.esc-content-note').html();
271 jQuery('#mainwp-notes-modal').removeClass('edit-mode');
272 jQuery('#mainwp-notes-title').html(decodeURIComponent(name));
273 jQuery('#mainwp-notes-html').html(note == '' ? 'No saved notes. Click the Edit button to edit theme notes.' : note);
274 jQuery('#mainwp-notes-note').val(note);
275 jQuery('#mainwp-notes-slug').val(slug);
276 mainwp_notes_show();
277 });
278
279 mainwp_notes_theme_save = function () {
280 var slug = jQuery('#mainwp-notes-slug').val();
281 var newnote = jQuery('#mainwp-notes-note').val();
282 newnote = newnote.replace(/(?:\r\n|\r|\n)/g, '<br>');
283 var data = mainwp_secure_data({
284 action: 'mainwp_trusted_theme_notes_save',
285 slug: slug,
286 note: newnote
287 });
288
289 jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...'));
290
291 jQuery.post(ajaxurl, data, function (pSlug) {
292 return function (response) {
293 var rowEl = jQuery('tr[theme-slug="' + pSlug + '"]');
294 if (response.result == 'SUCCESS') {
295 jQuery('#mainwp-notes-status').html('<i class="check circle green icon"></i> ' + __('Note saved!'));
296 rowEl.find('.esc-content-note').html(jQuery('#mainwp-notes-note').val());
297 if (newnote == '') {
298 rowEl.find('.mainwp-edit-theme-note').html('<i class="sticky note outline icon"></i>');
299 } else {
300 rowEl.find('.mainwp-edit-theme-note').html('<i class="sticky green note icon"></i>');
301 }
302 } else if (response.error != undefined) {
303 jQuery('#mainwp-notes-status').html('<i class="times circle red icon"></i> ' + __('Undefined error occured while saving your note!') + ': ' + response.error);
304 } else {
305 jQuery('#mainwp-notes-status').html('<i class="times circle red icon"></i> ' + __('Undefined error occured while saving your note!'));
306 }
307 }
308 }(slug), 'json');
309 return false;
310 }
311 });
312
313 mainwp_show_hide_install_to_selected_sites = function (what) {
314 if ('plugin' == what) {
315 jQuery('#mainwp-plugins-content .checkbox').on('click', function () {
316 if (jQuery('.mainwp-manage-plugin-item-website .checkbox.checked').length > 0) {
317 jQuery('#mainwp-install-to-selected-sites').show();
318 } else {
319 jQuery('#mainwp-install-to-selected-sites').hide();
320 }
321 });
322 } else {
323 jQuery('#mainwp-themes-content .checkbox').on('click', function () {
324 if (jQuery('.mainwp-manage-theme-item-website .checkbox.checked').length > 0) {
325 jQuery('#mainwp-install-themes-to-selected-sites').show();
326 } else {
327 jQuery('#mainwp-install-themes-to-selected-sites').hide();
328 }
329 });
330 }
331 }
332
333 // Manage Plugins -- Fetch plugins
334 mainwp_fetch_plugins = function () {
335 var errors = [];
336 var selected_sites = [];
337 var selected_groups = [];
338 var selected_clients = [];
339
340 if (jQuery('#select_by').val() == 'site') {
341 jQuery("input[name='selected_sites[]']:checked").each(function () {
342 selected_sites.push(jQuery(this).val());
343 });
344 if (selected_sites.length == 0) {
345 errors.push(__('Please select at least one website or group or client.'));
346 }
347 } else if (jQuery('#select_by').val() == 'client') {
348 jQuery("input[name='selected_clients[]']:checked").each(function () {
349 selected_clients.push(jQuery(this).val());
350 });
351 if (selected_clients.length == 0) {
352 errors.push(__('Please select at least one website or group or client.'));
353 }
354 } else {
355 jQuery("input[name='selected_groups[]']:checked").each(function () {
356 selected_groups.push(jQuery(this).val());
357 });
358 if (selected_groups.length == 0) {
359 errors.push(__('Please select at least one website or group or client.'));
360 }
361 }
362
363
364 var _status = jQuery("#mainwp_plugins_search_by_status").dropdown("get value");
365
366 if (_status == null) {
367 errors.push(__('Please select at least one plugin status.'));
368 }
369
370 if (errors.length > 0) {
371 jQuery('#mainwp-message-zone').html(errors.join('<br />'));
372 jQuery('#mainwp-message-zone').addClass('yellow');
373 jQuery('#mainwp-message-zone').show();
374 return;
375 } else {
376 jQuery('#mainwp-message-zone').html('');
377 jQuery('#mainwp-message-zone').removeClass('yellow');
378 jQuery('#mainwp-message-zone').hide();
379 }
380 var data = mainwp_secure_data({
381 action: 'mainwp_plugins_search',
382 keyword: jQuery('#mainwp_plugin_search_by_keyword').val(),
383 status: _status,
384 not_criteria: jQuery('#display_sites_not_meeting_criteria').is(':checked'),
385 'groups[]': selected_groups,
386 'sites[]': selected_sites,
387 'clients[]': selected_clients
388 });
389
390 jQuery('#mainwp-loading-plugins-row').show();
391
392 jQuery.post(ajaxurl, data, function (response) {
393 jQuery('#mainwp-loading-plugins-row').hide();
394 jQuery('#mainwp-plugins-main-content').show();
395
396 if (response && response.result) {
397 jQuery('#mainwp-plugins-content').html(response.result);
398 jQuery('#mainwp-plugins-bulk-actions-wapper').html(response.bulk_actions);
399 jQuery('#mainwp-plugins-bulk-actions-wapper .ui.dropdown').dropdown();
400 }
401 }, 'json');
402 };
403
404 // Fetch plugins for the Auto Update feature
405 mainwp_fetch_all_active_plugins = function () {
406 var data = mainwp_secure_data({
407 action: 'mainwp_plugins_search_all_active',
408 keyword: jQuery("#mainwp_au_plugin_keyword").val(),
409 status: jQuery("#mainwp_au_plugin_trust_status").val(),
410 plugin_status: jQuery("#mainwp_au_plugin_status").val()
411 });
412
413 jQuery('#mainwp-auto-updates-plugins-content').find('.dimmer').addClass('active');
414
415 jQuery.post(ajaxurl, data, function (response) {
416 response = response.trim();
417 jQuery('#mainwp-auto-updates-plugins-content').find('.dimmer').removeClass('active');
418 jQuery('#mainwp-auto-updates-plugins-table-wrapper').html(response);
419 });
420 };
421
422 // Fetch themes for the Auto Update feature
423 mainwp_fetch_all_themes = function () {
424 var data = mainwp_secure_data({
425 action: 'mainwp_themes_search_all',
426 keyword: jQuery("#mainwp_au_theme_keyword").val(),
427 status: jQuery("#mainwp_au_theme_trust_status").val(),
428 theme_status: jQuery("#mainwp_au_theme_status").val()
429 });
430
431 jQuery('#mainwp-auto-updates-themes-content').find('.dimmer').addClass('active');
432
433 jQuery.post(ajaxurl, data, function (response) {
434 jQuery('#mainwp-auto-updates-themes-content').find('.dimmer').removeClass('active');
435 jQuery('#mainwp-auto-updates-themes-table-wrapper').html(response);
436 });
437 };
438
439
440
441 /**
442 * MainWP_Themes.page
443 */
444 jQuery(document).ready(function () {
445 jQuery(document).on('click', '#mainwp_show_themes', function () {
446 mainwp_fetch_themes();
447 });
448
449 jQuery(document).on('click', '#mainwp-install-themes-to-selected-sites', function () {
450 var checkedVals = jQuery('.mainwp-manage-theme-item-website .mainwp-selected-theme-site:checked').map(function () {
451 var rowElement = jQuery(this).closest('.mainwp-manage-theme-item-website');
452 var val = rowElement.attr('site-id');
453 return val;
454 }).get();
455
456 var selectedIds = [];
457 if (checkedVals instanceof Array) {
458 jQuery.grep(checkedVals, function (val) {
459 if (jQuery.inArray(val, selectedIds) == -1) {
460 selectedIds.push(val);
461 }
462 });
463 }
464
465 if (selectedIds.length == 0) {
466 feedback('mainwp-message-zone', __('Please select at least one website.'), 'yellow');
467 return false;
468 } else {
469 jQuery('#mainwp-message-zone').fadeOut(5000);
470 var ids = selectedIds.join("-");
471 var kwd = jQuery('#mainwp_theme_search_by_keyword').val();
472 if ('' != kwd) {
473 kwd = '&s=' + encodeURIComponent(kwd);
474 }
475 location.href = 'admin.php?page=ThemesInstall&selected_sites=' + ids + kwd;
476 }
477 return false;
478 });
479
480 jQuery('#mainwp-themes-content .checkbox').on('click', function () {
481 if (jQuery('.mainwp-manage-theme-item-website .checkbox.checked').length > 0) {
482 jQuery('#mainwp-install-themes-to-selected-sites').show();
483 } else {
484 jQuery('#mainwp-install-themes-to-selected-sites').hide();
485 }
486 });
487
488
489 jQuery(document).on('click', '#mainwp_show_all_active_themes', function () {
490 mainwp_fetch_all_themes();
491 return false;
492 });
493
494 var themeCountSent;
495 var themeCountReceived;
496 var themeResetAllowed = true;
497
498 jQuery(document).on('click', '#mainwp-do-themes-bulk-actions', function () {
499 var action = jQuery("#mainwp-bulk-actions").dropdown("get value");
500 console.log(action);
501 if (action == '' || action == 'none')
502 return;
503
504 jQuery('#mainwp-do-themes-bulk-actions').attr('disabled', 'true');
505 jQuery('#mainwp_bulk_action_loading').show();
506 themeResetAllowed = false;
507 themeCountSent = 0;
508 themeCountReceived = 0;
509 var selectedSites = [];
510 var selectedSiteThemes = [];
511
512 //Find all checked boxes
513 jQuery('.mainwp-selected-theme-site:checked').each(function () {
514 var rowElement = jQuery(this).closest('.mainwp-manage-theme-item-website');
515 var websiteId = jQuery(rowElement).attr('site-id');
516 var theme = jQuery(rowElement).attr('theme-slug');
517 selectedSiteThemes.push({ 'siteid': websiteId, 'theme': theme });
518 if (selectedSites.indexOf(websiteId) < 0) {
519 selectedSites.push(websiteId);
520 }
521 });
522
523
524 jQuery(selectedSites).each(function (idx, val) {
525 var websiteId = val;
526 var selectedThemes = [];
527
528 jQuery(selectedSiteThemes).each(function (idx, val) {
529 if (val.siteid == websiteId) {
530 if (jQuery('.mainwp-manage-theme-item-website[site-id="' + val.siteid + '"][theme-slug="' + val.theme + '"]').length > 0) {
531 selectedThemes.push(jQuery('.mainwp-manage-theme-item-website[site-id="' + val.siteid + '"][theme-slug="' + val.theme + '"]')[0]);
532 }
533 }
534 });
535
536 if (selectedThemes.length == 0)
537 return;
538
539 if (action == 'activate' || action == 'ignore_updates') {
540 var themeToActivate = jQuery(selectedThemes[0]).attr('theme-slug');
541 var themesToSend = [];
542 var namesToSend = [];
543
544 var data = mainwp_secure_data({
545 action: 'mainwp_theme_' + action,
546 websiteId: websiteId
547 });
548
549 if (action == 'ignore_updates') {
550 for (var i = 0; i < selectedThemes.length; i++) {
551 themesToSend.push(jQuery(selectedThemes[i]).attr('theme-slug'));
552 namesToSend.push(jQuery(selectedThemes[i]).attr('theme-name'));
553 }
554 data['themes'] = themesToSend;
555 data['names'] = namesToSend;
556 } else {
557 data['theme'] = themeToActivate;
558 }
559
560 themeCountSent++;
561 jQuery.post(ajaxurl, data, function () {
562 themeCountReceived++;
563 if (themeResetAllowed && themeCountReceived == themeCountSent) {
564 themeCountReceived = 0;
565 themeCountSent = 0;
566 jQuery('#mainwp_bulk_action_loading').hide();
567 jQuery('#mainwp_themes_loading_info').show();
568 mainwp_fetch_themes();
569 }
570 });
571 } else if (action == 'delete') {
572 var themesToDelete = [];
573 for (var i = 0; i < selectedThemes.length; i++) {
574 if (jQuery(selectedThemes[i]).attr('not-delete') == 1) {
575 jQuery(selectedThemes[i]).find('.mainwp-selected-theme-site').attr('checked', false);
576 continue;
577 }
578 themesToDelete.push(jQuery(selectedThemes[i]).attr('theme-slug'));
579 }
580 if (themesToDelete.length == 0) {
581 return;
582 }
583 var data = mainwp_secure_data({
584 action: 'mainwp_theme_delete',
585 themes: themesToDelete,
586 websiteId: websiteId
587 });
588
589 themeCountSent++;
590 jQuery.post(ajaxurl, data, function (response) {
591 if (response.error != undefined && response.error == Object(response.error)) { // check if .error is object.
592 entries = Object.entries(response.error);
593 for (var entry of entries) {
594 warnings = __(entry[0], encodeURIComponent(entry[1])); // entry[0]:id message, entry[1] string value.
595 jQuery('#mainwp-message-zone').after('<div class="ui info message yellow"><i class="ui close icon"></i><span>' + warnings + '</span></div>');
596 }
597 }
598 themeCountReceived++;
599 if (themeResetAllowed && themeCountReceived == themeCountSent) {
600 themeCountReceived = 0;
601 themeCountSent = 0;
602 jQuery('#mainwp_bulk_action_loading').hide();
603 jQuery('#mainwp_themes_loading_info').show();
604 mainwp_fetch_themes();
605 }
606 });
607 }
608 });
609
610 themeResetAllowed = true;
611 if (themeCountReceived == themeCountSent) {
612 themeCountReceived = 0;
613 themeCountSent = 0;
614 jQuery('#mainwp_bulk_action_loading').hide();
615 jQuery('#mainwp_themes_loading_info').show();
616 mainwp_fetch_themes();
617 }
618 });
619
620 });
621
622
623 // Manage Themes -- Fetch themes from child sites
624 mainwp_fetch_themes = function () {
625 var errors = [];
626 var selected_sites = [];
627 var selected_groups = [];
628 var selected_clients = [];
629
630 if (jQuery('#select_by').val() == 'site') {
631 jQuery("input[name='selected_sites[]']:checked").each(function () {
632 selected_sites.push(jQuery(this).val());
633 });
634 if (selected_sites.length == 0) {
635 errors.push(__('Please select at least one website or group or client.'));
636 }
637 } else if (jQuery('#select_by').val() == 'client') {
638 jQuery("input[name='selected_clients[]']:checked").each(function () {
639 selected_clients.push(jQuery(this).val());
640 });
641 if (selected_clients.length == 0) {
642 errors.push(__('Please select at least one website or group or client.'));
643 }
644 } else {
645 jQuery("input[name='selected_groups[]']:checked").each(function () {
646 selected_groups.push(jQuery(this).val());
647 });
648 if (selected_groups.length == 0) {
649 errors.push(__('Please select at least one website or group or client.'));
650 }
651 }
652
653 var _status = jQuery("#mainwp_themes_search_by_status").dropdown("get value");
654 if (_status == null) {
655 errors.push(__('Please select at least one theme status.'));
656 }
657
658 if (errors.length > 0) {
659 jQuery('#mainwp-message-zone').html(errors.join('<br />'));
660 jQuery('#mainwp-message-zone').addClass('yellow');
661 jQuery('#mainwp-message-zone').show();
662 return;
663 } else {
664 jQuery('#mainwp-message-zone').html('');
665 jQuery('#mainwp-message-zone').removeClass('yellow');
666 jQuery('#mainwp-message-zone').hide();
667 }
668
669 var data = mainwp_secure_data({
670 action: 'mainwp_themes_search',
671 keyword: jQuery('#mainwp_theme_search_by_keyword').val(),
672 status: _status,
673 not_criteria: jQuery('#display_sites_not_meeting_criteria').is(':checked'),
674 'groups[]': selected_groups,
675 'sites[]': selected_sites,
676 'clients[]': selected_clients
677 });
678
679 jQuery('#mainwp-loading-themes-row').show();
680
681 jQuery.post(ajaxurl, data, function (response) {
682 jQuery('#mainwp-loading-themes-row').hide();
683 jQuery('#mainwp-themes-main-content').show();
684 if (response && response.result) {
685 jQuery('#mainwp-themes-content').html(response.result);
686 jQuery('#mainwp-themes-bulk-actions-wapper').html(response.bulk_actions);
687 jQuery('#mainwp-themes-bulk-actions-wapper .ui.dropdown').dropdown();
688 }
689 }, 'json');
690 };
691
692 /**
693 * Plugins manages.
694 */
695 jQuery(document).ready(function () {
696 jQuery(document).on('click', '.mainwp-manage-plugin-deactivate', function () {
697 manage_plugin_Action(jQuery(this), 'deactivate');
698 return false;
699 });
700 jQuery(document).on('click', '.mainwp-manage-plugin-activate', function () {
701 manage_plugin_Action(jQuery(this), 'activate');
702 return false;
703 });
704 jQuery(document).on('click', '.mainwp-manage-plugin-delete', function () {
705 manage_plugin_Action(jQuery(this), 'delete');
706 return false;
707 });
708 });
709
710 manage_plugin_Action = function (elem, what) {
711 var rowElement = jQuery(elem).closest('.mainwp-manage-plugin-item-website');
712 var plugin = rowElement.attr('plugin-slug');
713 var websiteId = rowElement.attr('site-id');
714
715 var data = mainwp_secure_data({
716 action: 'mainwp_widget_plugin_' + what, // same with the widgets.
717 plugin: plugin,
718 websiteId: websiteId
719 });
720 var parent = jQuery(elem).closest('.column.column-actions');
721 jQuery(parent).html('<i class="notched circle loading icon"></i>' + __('Please wait...') + '</div>');
722 jQuery.post(ajaxurl, data, function (response) {
723 if (response && response.error) {
724 jQuery(parent).html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
725 } else if (response && response.result) {
726 if (what == 'delete') {
727 jQuery(rowElement).html('<i class="check circle green icon"></i> ' + response.result);
728 setTimeout(function () {
729 jQuery(rowElement).fadeOut(1000);
730 }, 1000);
731
732 } else {
733 jQuery(parent).html('<i class="check circle green icon"></i> ' + response.result);
734 }
735 setTimeout(function () {
736 mainwp_fetch_plugins();
737 }, 3000);
738 } else {
739 jQuery(parent).html('<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
740 }
741 }, 'json');
742
743 return false;
744 };
745
746
747 manage_plugins_upgrade = function (slug, websiteid) {
748 var msg = __('Are you sure you want to update the plugin on the selected site?');
749 mainwp_confirm(msg, function () {
750 return manage_plugins_upgrade_int(slug, websiteid);
751 }, false, 1);
752 };
753
754
755 manage_plugins_upgrade_int = function (slug, websiteId) {
756 var websiteHolder = jQuery('.mainwp-manage-plugin-item-website[plugin-slug="' + slug + '"][site-id="' + websiteId + '"]');
757 websiteHolder.find('.column.update-column').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...'));
758
759 manage_plugins_upgrade_continueAfterBackup = function () {
760 console.log('plugin upgrade continue');
761 return function () {
762 var data = mainwp_secure_data({
763 action: 'mainwp_upgradeplugintheme',
764 websiteId: websiteId,
765 type: 'plugin',
766 slug: slug
767 });
768 jQuery.ajax({
769 type: "POST",
770 url: ajaxurl,
771 data: data,
772 success: function (siteHolder) {
773 return function (response) {
774 if (response.error) {
775 var extErr = getErrorMessageInfo(response.error, 'ui')
776 siteHolder.find('.column.update-column').html(extErr);
777 } else {
778 var res = response.result;
779 var res_error = response.result_error;
780 if (res[slug]) {
781 siteHolder.attr('updated', 1);
782 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>');
783 } else if (res_error[slug]) {
784 siteHolder.find('.column.update-column').html('<span data-inverted="" data-position="left center" data-tooltip="' + res_error[slug] + '"><i class="red times icon"></i></span>');
785 } else {
786 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
787 }
788 setTimeout(function () {
789 mainwp_fetch_plugins();
790 }, 3000);
791 }
792 }
793 }(websiteHolder),
794 tryCount: 0,
795 retryLimit: 3,
796 endError: function (siteHolder) {
797 return function () {
798 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
799 }
800 }(websiteHolder),
801 error: function (xhr) {
802 this.tryCount++;
803 if (this.tryCount >= this.retryLimit) {
804 this.endError();
805 return;
806 }
807
808 var fnc = function (pRqst, pXhr) {
809 return function () {
810 if (pXhr.status == 404) {
811 //handle error
812 jQuery.ajax(pRqst);
813 } else if (pXhr.status == 500) {
814 //handle error
815 } else {
816 //handle error
817 }
818 }
819 }(this, xhr);
820 setTimeout(fnc, 500);
821 },
822 dataType: 'json'
823 });
824
825 manage_plugins_upgrade_continueAfterBackup = undefined;
826 }();
827 };
828
829 if (mainwpParams['disable_checkBackupBeforeUpgrade'] == true) {
830 if (manage_plugins_upgrade_continueAfterBackup != undefined) {
831 manage_plugins_upgrade_continueAfterBackup();
832 }
833 return false;
834 }
835
836 var sitesToUpdate = [websiteId]; var siteNames = []
837 var siteNames = []
838 siteNames[websiteId] = jQuery(websiteHolder).attr('site-name');
839
840 return mainwp_manages_checkBackups(sitesToUpdate, siteNames, manage_plugins_upgrade_continueAfterBackup);
841 };
842
843
844 /**
845 * Themes manage.
846 */
847 jQuery(document).ready(function () {
848 jQuery(document).on('click', '.mainwp-manages-theme-activate', function () {
849 manages_themeAction(jQuery(this), 'activate');
850 return false;
851 });
852 jQuery(document).on('click', '.mainwp-manages-theme-delete', function () {
853 manages_themeAction(jQuery(this), 'delete');
854 return false;
855 });
856 });
857
858 manages_themeAction = function (elem, what) {
859 var rowElement = jQuery(elem).closest('.mainwp-manage-theme-item-website');
860 var theme = rowElement.attr('theme-slug');
861 var websiteId = rowElement.attr('site-id');
862
863 var data = mainwp_secure_data({
864 action: 'mainwp_widget_theme_' + what, // same with theme widget.
865 theme: theme,
866 websiteId: websiteId
867 });
868
869 var parent = jQuery(elem).closest('.column.column-actions');
870 jQuery(parent).html('<i class="notched circle loading icon"></i>' + __('Please wait...') + '</div>');
871
872 jQuery.post(ajaxurl, data, function (response) {
873 if (response && response.error) {
874 jQuery(parent).html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
875 } else if (response && response.result) {
876 if (what == 'delete') {
877 jQuery(rowElement).html('<i class="check circle green icon"></i> ' + response.result);
878 setTimeout(function () {
879 jQuery(rowElement).fadeOut(1000);
880 }, 1000);
881
882 } else {
883 jQuery(parent).html('<i class="check circle green icon"></i> ' + response.result);
884 }
885 setTimeout(function () {
886 mainwp_fetch_themes();
887 }, 3000);
888 } else {
889 jQuery(parent).html('<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
890 }
891 }, 'json');
892
893 return false;
894 };
895
896
897 manage_themes_upgrade_theme = function (slug, websiteid) {
898 var msg = __('Are you sure you want to update the theme on the selected site?');
899 mainwp_confirm(msg, function () {
900 return manage_themes_upgrade_int(slug, websiteid);
901 }, false, 1);
902 };
903
904
905 manage_themes_upgrade_int = function (slug, websiteId) {
906 var websiteHolder = jQuery('.mainwp-manage-theme-item-website[theme-slug="' + slug + '"][site-id="' + websiteId + '"]');
907 websiteHolder.find('.column.update-column').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...'));
908 manage_themes_upgrade_continueAfterBackup = function () {
909 console.log('theme upgrade continue');
910 return function () {
911 var data = mainwp_secure_data({
912 action: 'mainwp_upgradeplugintheme',
913 websiteId: websiteId,
914 type: 'theme',
915 slug: slug
916 });
917 jQuery.ajax({
918 type: "POST",
919 url: ajaxurl,
920 data: data,
921 success: function (pSlug, siteHolder) {
922 return function (response) {
923 if (response.error) {
924 var extErr = getErrorMessageInfo(response.error, 'ui')
925 siteHolder.find('.column.update-column').html(extErr);
926 } else {
927 var res = response.result;
928 if (res[pSlug]) {
929 siteHolder.attr('updated', 1);
930 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>');
931 } else {
932 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
933 }
934 setTimeout(function () {
935 mainwp_fetch_themes();
936 }, 3000);
937 }
938 }
939 }(slug, websiteHolder),
940 tryCount: 0,
941 retryLimit: 3,
942 endError: function (siteHolder) {
943 return function () {
944 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
945 }
946 }(websiteHolder),
947 error: function (xhr) {
948 this.tryCount++;
949 if (this.tryCount >= this.retryLimit) {
950 this.endError();
951 return;
952 }
953 var fnc = function (pRqst, pXhr) {
954 return function () {
955 if (pXhr.status == 404) {
956 //handle error
957 jQuery.ajax(pRqst);
958 } else if (pXhr.status == 500) {
959 //handle error
960 } else {
961 //handle error
962 }
963 }
964 }(this, xhr);
965 setTimeout(fnc, 500);
966 },
967 dataType: 'json'
968 });
969 manage_themes_upgrade_continueAfterBackup = undefined;
970 }();
971 };
972
973 if (mainwpParams['disable_checkBackupBeforeUpgrade'] == true) {
974 if (manage_themes_upgrade_continueAfterBackup != undefined) {
975 manage_themes_upgrade_continueAfterBackup();
976 }
977 return false;
978 }
979
980 var sitesToUpdate = [websiteId];
981 var siteNames = []
982 siteNames[websiteId] = jQuery(websiteHolder).attr('site-name');
983
984 return mainwp_manages_checkBackups(sitesToUpdate, siteNames, manage_themes_upgrade_continueAfterBackup);
985 };
986
987
988 /**
989 * Check Backups.
990 */
991 mainwp_manages_checkBackups = function (sitesToUpdate, siteNames, continueAfterBackup) {
992 managesitesShowBusyFunction = function () {
993 var output = __('Checking if a backup is required for the selected updates...');
994 mainwpPopup('#managesites-backup-box').getContentEl().html(output);
995 jQuery('#managesites-backup-all').hide();
996 jQuery('#managesites-backup-ignore').hide();
997 mainwpPopup('#managesites-backup-box').init({
998 title: __("Checking backup settings..."), callback: function () {
999 bulkManageSitesTaskRunning = false;
1000 window.location.href = location.href;
1001 }
1002 });
1003
1004 };
1005
1006 var managesitesShowBusyTimeout = setTimeout(managesitesShowBusyFunction, 300);
1007
1008 //Step 2: Check if backups are ok.
1009 var data = mainwp_secure_data({
1010 action: 'mainwp_checkbackups',
1011 sites: sitesToUpdate
1012 });
1013
1014 jQuery.ajax({
1015 type: "POST",
1016 url: ajaxurl,
1017 data: data,
1018 success: function (pSiteNames) {
1019 return function (response) {
1020 clearTimeout(managesitesShowBusyTimeout);
1021
1022 mainwpPopup('#managesites-backup-box').close();
1023 var siteFeedback = undefined;
1024
1025 if (response['result'] && response['result']['sites'] != undefined) {
1026 siteFeedback = [];
1027 for (var currSiteId in response['result']['sites']) {
1028 if (response['result']['sites'][currSiteId] == false) {
1029 siteFeedback.push(currSiteId);
1030 }
1031 }
1032 if (siteFeedback.length == 0)
1033 siteFeedback = undefined;
1034 }
1035
1036 if (siteFeedback != undefined) {
1037 var backupPrimary = '';
1038 if (response['result']['primary_backup'] && response['result']['primary_backup'] != undefined)
1039 backupPrimary = response['result']['primary_backup'];
1040
1041 if (backupPrimary == '') {
1042 jQuery('#managesites-backup-all').show();
1043 jQuery('#managesites-backup-ignore').show();
1044 } else {
1045 var backupLink = mainwp_get_primaryBackup_link(backupPrimary);
1046 jQuery('#managesites-backup-now').attr('href', backupLink).show();
1047 jQuery('#managesites-backup-ignore').val(__('Proceed with Updates')).show();
1048 }
1049
1050 var output = '<span class="mainwp-red">' + __('A full backup has not been taken in the last days for the following sites:') + '</span><br /><br />';
1051 if (backupPrimary == '') { // default backup feature
1052 for (var j = 0; j < siteFeedback.length; j++) {
1053 output += '<span class="managesites-backup-site" siteid="' + siteFeedback[j] + '">' + decodeURIComponent(pSiteNames[siteFeedback[j]]) + '</span><br />';
1054 }
1055 } else {
1056 for (var j = 0; j < siteFeedback.length; j++) {
1057 output += '<span>' + decodeURIComponent(pSiteNames[siteFeedback[j]]) + '</span><br />';
1058 }
1059 }
1060 mainwpPopup('#managesites-backup-box').getContentEl().html(output);
1061 console.log(typeof continueAfterBackup);
1062 mainwpPopup('#managesites-backup-box').init({
1063 title: __("Full backup required!"), callback: function () {
1064 continueAfterBackup = undefined;
1065 window.location.href = location.href;
1066 }
1067 });
1068
1069 return false;
1070 }
1071 if (continueAfterBackup != undefined) {
1072 continueAfterBackup();
1073 }
1074
1075 }
1076 }(siteNames),
1077 error: function () {
1078 mainwpPopup('#managesites-backup-box').close(true);
1079 },
1080 dataType: 'json'
1081 });
1082
1083 return false;
1084 };
1085