PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3.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
mainwp / assets / js / mainwp-plugins-themes.js

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

1,087 lines 43.9 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="green check 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 red icon"></i> ' + __('Undefined error occured while saving your note') + ': ' + response.error);
258 } else {
259 jQuery('#mainwp-notes-status').html('<i class="times 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="green check 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 red icon"></i> ' + __('Undefined error occured while saving your note!') + ': ' + response.error);
304 } else {
305 jQuery('#mainwp-notes-status').html('<i class="times 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(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(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 start_row = '<div class="one wide center aligned middle aligned column"></div><div class="thirteen wide left aligned middle aligned column">';
721 var end_row = '</div>';
722 jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + __('Please wait...') + end_row);
723 jQuery.post(ajaxurl, data, function (response) {
724 if (response && response.error) {
725 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);
726 } else if (response && response.result) {
727 if (what == 'delete') {
728 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + '</div>');
729 setTimeout(function () {
730 jQuery(rowElement).fadeOut(1000);
731 }, 1000);
732
733 } else {
734 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + end_row);
735 }
736 setTimeout(function () {
737 mainwp_fetch_plugins();
738 }, 3000);
739 } else {
740 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);
741 }
742 }, 'json');
743
744 return false;
745 };
746
747
748 manage_plugins_upgrade = function (slug, websiteid) {
749 var msg = __('Are you sure you want to update the plugin on the selected site?');
750 mainwp_confirm(msg, function () {
751 return manage_plugins_upgrade_int(slug, websiteid);
752 }, false, 1);
753 };
754
755
756 manage_plugins_upgrade_int = function (slug, websiteId) {
757 var websiteHolder = jQuery('.mainwp-manage-plugin-item-website[plugin-slug="' + slug + '"][site-id="' + websiteId + '"]');
758 websiteHolder.find('.column.update-column').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...'));
759
760 manage_plugins_upgrade_continueAfterBackup = function () {
761 console.log('plugin upgrade continue');
762 return function () {
763 var data = mainwp_secure_data({
764 action: 'mainwp_upgradeplugintheme',
765 websiteId: websiteId,
766 type: 'plugin',
767 slug: slug
768 });
769 jQuery.ajax({
770 type: "POST",
771 url: ajaxurl,
772 data: data,
773 success: function (siteHolder) {
774 return function (response) {
775 if (response.error) {
776 var extErr = getErrorMessageInfo(response.error, 'ui')
777 siteHolder.find('.column.update-column').html(extErr);
778 } else {
779 var res = response.result;
780 var res_error = response.result_error;
781 if (res[slug]) {
782 siteHolder.attr('updated', 1);
783 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>');
784 } else if (res_error[slug]) {
785 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>');
786 } else {
787 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
788 }
789 setTimeout(function () {
790 mainwp_fetch_plugins();
791 }, 3000);
792 }
793 }
794 }(websiteHolder),
795 tryCount: 0,
796 retryLimit: 3,
797 endError: function (siteHolder) {
798 return function () {
799 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
800 }
801 }(websiteHolder),
802 error: function (xhr) {
803 this.tryCount++;
804 if (this.tryCount >= this.retryLimit) {
805 this.endError();
806 return;
807 }
808
809 var fnc = function (pRqst, pXhr) {
810 return function () {
811 if (pXhr.status == 404) {
812 //handle error
813 jQuery.ajax(pRqst);
814 } else if (pXhr.status == 500) {
815 //handle error
816 } else {
817 //handle error
818 }
819 }
820 }(this, xhr);
821 setTimeout(fnc, 500);
822 },
823 dataType: 'json'
824 });
825
826 manage_plugins_upgrade_continueAfterBackup = undefined;
827 }();
828 };
829
830 if (mainwpParams['disable_checkBackupBeforeUpgrade'] == true) {
831 if (manage_plugins_upgrade_continueAfterBackup != undefined) {
832 manage_plugins_upgrade_continueAfterBackup();
833 }
834 return false;
835 }
836
837 var sitesToUpdate = [websiteId]; var siteNames = []
838 var siteNames = []
839 siteNames[websiteId] = jQuery(websiteHolder).attr('site-name');
840
841 return mainwp_manages_checkBackups(sitesToUpdate, siteNames, manage_plugins_upgrade_continueAfterBackup);
842 };
843
844
845 /**
846 * Themes manage.
847 */
848 jQuery(function () {
849 jQuery(document).on('click', '.mainwp-manages-theme-activate', function () {
850 manages_themeAction(jQuery(this), 'activate');
851 return false;
852 });
853 jQuery(document).on('click', '.mainwp-manages-theme-delete', function () {
854 manages_themeAction(jQuery(this), 'delete');
855 return false;
856 });
857 });
858
859 manages_themeAction = function (elem, what) {
860 var rowElement = jQuery(elem).closest('.mainwp-manage-theme-item-website');
861 var theme = rowElement.attr('theme-slug');
862 var websiteId = rowElement.attr('site-id');
863
864 var data = mainwp_secure_data({
865 action: 'mainwp_widget_theme_' + what, // same with theme widget.
866 theme: theme,
867 websiteId: websiteId
868 });
869
870 var start_row = '<div class="one wide center aligned middle aligned column"></div><div class="thirteen wide left aligned middle aligned column">';
871 var end_row = '</div>';
872
873 jQuery(rowElement).html(start_row + '<i class="notched circle loading icon"></i>' + __('Please wait...') + end_row);
874 jQuery.post(ajaxurl, data, function (response) {
875 if (response && response.error) {
876 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);
877 } else if (response && response.result) {
878 if (what == 'delete') {
879 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + end_row);
880 setTimeout(function () {
881 jQuery(rowElement).fadeOut(1000);
882 }, 1000);
883
884 } else {
885 jQuery(rowElement).html(start_row + '<i class="green check icon"></i> ' + response.result + end_row);
886 }
887 setTimeout(function () {
888 mainwp_fetch_themes();
889 }, 3000);
890 } else {
891 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);
892 }
893 }, 'json');
894
895 return false;
896 };
897
898
899 manage_themes_upgrade_theme = function (slug, websiteid) {
900 var msg = __('Are you sure you want to update the theme on the selected site?');
901 mainwp_confirm(msg, function () {
902 return manage_themes_upgrade_int(slug, websiteid);
903 }, false, 1);
904 };
905
906
907 manage_themes_upgrade_int = function (slug, websiteId) {
908 var websiteHolder = jQuery('.mainwp-manage-theme-item-website[theme-slug="' + slug + '"][site-id="' + websiteId + '"]');
909 websiteHolder.find('.column.update-column').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...'));
910 manage_themes_upgrade_continueAfterBackup = function () {
911 console.log('theme upgrade continue');
912 return function () {
913 var data = mainwp_secure_data({
914 action: 'mainwp_upgradeplugintheme',
915 websiteId: websiteId,
916 type: 'theme',
917 slug: slug
918 });
919 jQuery.ajax({
920 type: "POST",
921 url: ajaxurl,
922 data: data,
923 success: function (pSlug, siteHolder) {
924 return function (response) {
925 if (response.error) {
926 var extErr = getErrorMessageInfo(response.error, 'ui')
927 siteHolder.find('.column.update-column').html(extErr);
928 } else {
929 var res = response.result;
930 if (res[pSlug]) {
931 siteHolder.attr('updated', 1);
932 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>');
933 } else {
934 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
935 }
936 setTimeout(function () {
937 mainwp_fetch_themes();
938 }, 3000);
939 }
940 }
941 }(slug, websiteHolder),
942 tryCount: 0,
943 retryLimit: 3,
944 endError: function (siteHolder) {
945 return function () {
946 siteHolder.find('.column.update-column').html('<i class="red times icon"></i>');
947 }
948 }(websiteHolder),
949 error: function (xhr) {
950 this.tryCount++;
951 if (this.tryCount >= this.retryLimit) {
952 this.endError();
953 return;
954 }
955 var fnc = function (pRqst, pXhr) {
956 return function () {
957 if (pXhr.status == 404) {
958 //handle error
959 jQuery.ajax(pRqst);
960 } else if (pXhr.status == 500) {
961 //handle error
962 } else {
963 //handle error
964 }
965 }
966 }(this, xhr);
967 setTimeout(fnc, 500);
968 },
969 dataType: 'json'
970 });
971 manage_themes_upgrade_continueAfterBackup = undefined;
972 }();
973 };
974
975 if (mainwpParams['disable_checkBackupBeforeUpgrade'] == true) {
976 if (manage_themes_upgrade_continueAfterBackup != undefined) {
977 manage_themes_upgrade_continueAfterBackup();
978 }
979 return false;
980 }
981
982 var sitesToUpdate = [websiteId];
983 var siteNames = []
984 siteNames[websiteId] = jQuery(websiteHolder).attr('site-name');
985
986 return mainwp_manages_checkBackups(sitesToUpdate, siteNames, manage_themes_upgrade_continueAfterBackup);
987 };
988
989
990 /**
991 * Check Backups.
992 */
993 mainwp_manages_checkBackups = function (sitesToUpdate, siteNames, continueAfterBackup) {
994 managesitesShowBusyFunction = function () {
995 var output = __('Checking if a backup is required for the selected updates...');
996 mainwpPopup('#managesites-backup-box').getContentEl().html(output);
997 jQuery('#managesites-backup-all').hide();
998 jQuery('#managesites-backup-ignore').hide();
999 mainwpPopup('#managesites-backup-box').init({
1000 title: __("Checking backup settings..."), callback: function () {
1001 bulkManageSitesTaskRunning = false;
1002 window.location.href = location.href;
1003 }
1004 });
1005
1006 };
1007
1008 var managesitesShowBusyTimeout = setTimeout(managesitesShowBusyFunction, 300);
1009
1010 //Step 2: Check if backups are ok.
1011 var data = mainwp_secure_data({
1012 action: 'mainwp_checkbackups',
1013 sites: sitesToUpdate
1014 });
1015
1016 jQuery.ajax({
1017 type: "POST",
1018 url: ajaxurl,
1019 data: data,
1020 success: function (pSiteNames) {
1021 return function (response) {
1022 clearTimeout(managesitesShowBusyTimeout);
1023
1024 mainwpPopup('#managesites-backup-box').close();
1025 var siteFeedback = undefined;
1026
1027 if (response['result'] && response['result']['sites'] != undefined) {
1028 siteFeedback = [];
1029 for (var currSiteId in response['result']['sites']) {
1030 if (response['result']['sites'][currSiteId] == false) {
1031 siteFeedback.push(currSiteId);
1032 }
1033 }
1034 if (siteFeedback.length == 0)
1035 siteFeedback = undefined;
1036 }
1037
1038 if (siteFeedback != undefined) {
1039 var backupPrimary = '';
1040 if (response['result']['primary_backup'] && response['result']['primary_backup'] != undefined)
1041 backupPrimary = response['result']['primary_backup'];
1042
1043 if (backupPrimary == '') {
1044 jQuery('#managesites-backup-all').show();
1045 jQuery('#managesites-backup-ignore').show();
1046 } else {
1047 var backupLink = mainwp_get_primaryBackup_link(backupPrimary);
1048 jQuery('#managesites-backup-now').attr('href', backupLink).show();
1049 jQuery('#managesites-backup-ignore').val(__('Proceed with Updates')).show();
1050 }
1051
1052 var output = '<span class="mainwp-red">' + __('A full backup has not been taken in the last days for the following sites:') + '</span><br /><br />';
1053 if (backupPrimary == '') { // default backup feature
1054 for (var j = 0; j < siteFeedback.length; j++) {
1055 output += '<span class="managesites-backup-site" siteid="' + siteFeedback[j] + '">' + decodeURIComponent(pSiteNames[siteFeedback[j]]) + '</span><br />';
1056 }
1057 } else {
1058 for (var j = 0; j < siteFeedback.length; j++) {
1059 output += '<span>' + decodeURIComponent(pSiteNames[siteFeedback[j]]) + '</span><br />';
1060 }
1061 }
1062 mainwpPopup('#managesites-backup-box').getContentEl().html(output);
1063 console.log(typeof continueAfterBackup);
1064 mainwpPopup('#managesites-backup-box').init({
1065 title: __("Full backup required!"), callback: function () {
1066 continueAfterBackup = undefined;
1067 window.location.href = location.href;
1068 }
1069 });
1070
1071 return false;
1072 }
1073 if (continueAfterBackup != undefined) {
1074 continueAfterBackup();
1075 }
1076
1077 }
1078 }(siteNames),
1079 error: function () {
1080 mainwpPopup('#managesites-backup-box').close(true);
1081 },
1082 dataType: 'json'
1083 });
1084
1085 return false;
1086 };
1087