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-posts.js +147 -40 5.1 → 6.2.2 View file →
@@ -5,8 +5,25 @@
5 5
6 6 let countSent = 0;
7 7 let countReceived = 0;
8 8
9 +let updatePagesBulkActionsState = function () {
10 + let checkedCount = jQuery('#mainwp-pages-table input[name="page[]"]:checked').length;
11 + let dropdown = jQuery('#mainwp-manage-pages #mainwp-bulk-actions');
12 + let applyButton = jQuery('#mainwp-do-pages-bulk-actions');
13 +
14 + if (checkedCount > 0) {
15 + dropdown.removeClass('disabled');
16 + dropdown.parent('.ui.dropdown').removeClass('disabled');
17 + applyButton.removeClass('disabled');
18 + } else {
19 + dropdown.addClass('disabled');
20 + dropdown.parent('.ui.dropdown').addClass('disabled');
21 + dropdown.dropdown('set selected', 'none');
22 + applyButton.addClass('disabled');
23 + }
24 +};
25 +
9 26 jQuery(function () {
10 27
11 28 // to fix issue not loaded calendar js library
12 29 if (jQuery('.ui.calendar').length > 0) {
@@ -16,8 +33,14 @@
16 33 mainwp_init_ui_calendar('#mainwp-manage-pages .ui.calendar, #mainwp-manage-posts .ui.calendar');
17 34 }
18 35 }
19 36
37 + updatePagesBulkActionsState();
38 +
39 + jQuery(document).on('change', '#mainwp-pages-table .check-column INPUT:checkbox', function () {
40 + updatePagesBulkActionsState();
41 + });
42 +
20 43 jQuery(document).on('click', '#mainwp_show_pages', function () {
21 44 mainwp_fetch_pages();
22 45 });
23 46 jQuery(document).on('click', '.page_submitpublish', function () {
@@ -57,9 +80,9 @@
57 80 );
58 81 };
59 82
60 83 if (action == 'delete') {
61 - let msg = __('You are about to delete %1 page(s). Are you sure you want to proceed?', countSent);
84 + let msg = MainWP.I18n.t('You are about to delete %1 page(s). Are you sure you want to proceed?', countSent);
62 85 mainwp_confirm(msg, _callback);
63 86 return;
64 87 }
65 88 _callback();
@@ -71,9 +94,9 @@
71 94 let rowElement = jQuery(elem).closest('tr');
72 95 let pageId = rowElement.find('.pageId').val();
73 96 let websiteId = rowElement.find('.websiteId').val();
74 97
75 - if (rowElement.find('.allowedBulkActions').val().indexOf('|' + what + '|') == -1) {
98 + if (!rowElement.find('.allowedBulkActions').val().includes('|' + what + '|')) {
76 99 jQuery(elem).prop("checked", false);
77 100 countReceived++;
78 101
79 102 if (countReceived == countSent) {
@@ -160,15 +183,15 @@
160 183 "columnDefs": [{
161 184 "targets": 'no-sort',
162 185 "orderable": false
163 186 }],
164 - "preDrawCallback": function () {
165 - console.log('preDrawCallback js');
187 + "drawCallback": function () {
166 188 setTimeout(() => {
167 189 jQuery('#mainwp-pages-table .ui.dropdown').dropdown();
168 190 jQuery('#mainwp-pages-table .ui.checkbox').checkbox();
169 191 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
170 - mainwp_datatable_fix_menu_overflow();
192 + mainwp_datatable_fix_menu_overflow('#mainwp-pages-table');
193 + updatePagesBulkActionsState();
171 194 }, 1000);
172 195 },
173 196 select: {
174 197 items: 'row',
@@ -179,8 +202,9 @@
179 202 if ('row' == type) {
180 203 dt.rows(indexes)
181 204 .nodes()
182 205 .to$().find('td.check-column .ui.checkbox').checkbox('set checked');
206 + updatePagesBulkActionsState();
183 207 }
184 208 }).on('deselect', function (e, dt, type, indexes) {
185 209 if ('row' == type) {
186 210 dt.rows(indexes)
@@ -185,16 +209,17 @@
185 209 if ('row' == type) {
186 210 dt.rows(indexes)
187 211 .nodes()
188 212 .to$().find('td.check-column .ui.checkbox').checkbox('set unchecked');
213 + updatePagesBulkActionsState();
189 214 }
190 215 }).on('columns-reordered', function () {
191 - console.log('columns-reordered');
192 216 setTimeout(() => {
193 217 jQuery('#mainwp-pages-table .ui.dropdown').dropdown();
194 218 jQuery('#mainwp-pages-table .ui.checkbox').checkbox();
195 - mainwp_datatable_fix_menu_overflow();
219 + mainwp_datatable_fix_menu_overflow('#mainwp-pages-table');
196 220 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
221 + updatePagesBulkActionsState();
197 222 }, 1000);
198 223 });
199 224 });
200 225 };
@@ -205,21 +230,21 @@
205 230 let selected_sites = [];
206 231 let selected_groups = [];
207 232 let selected_clients = [];
208 233
209 - if (jQuery('#select_by').val() == 'site') {
234 + if (jQuery('input[name="select_by"]').val() == 'site') {
210 235 jQuery("input[name='selected_sites[]']:checked").each(function () {
211 236 selected_sites.push(jQuery(this).val());
212 237 });
213 238 if (selected_sites.length == 0) {
214 - errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
239 + errors.push('<div class="ui yellow message">' + MainWP.I18n.t('Please select websites or groups or clients.') + '</div>');
215 240 }
216 - } else if (jQuery('#select_by').val() == 'client') {
241 + } else if (jQuery('input[name="select_by"]').val() == 'client') {
217 242 jQuery("input[name='selected_clients[]']:checked").each(function () {
218 243 selected_clients.push(jQuery(this).val());
219 244 });
220 245 if (selected_clients.length == 0) {
221 - errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
246 + errors.push('<div class="ui yellow message">' + MainWP.I18n.t('Please select websites or groups or clients.') + '</div>');
222 247 }
223 248 } else {
224 249 jQuery("input[name='selected_groups[]']:checked").each(function () {
225 250 selected_groups.push(jQuery(this).val());
@@ -224,9 +249,9 @@
224 249 jQuery("input[name='selected_groups[]']:checked").each(function () {
225 250 selected_groups.push(jQuery(this).val());
226 251 });
227 252 if (selected_groups.length == 0) {
228 - errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
253 + errors.push('<div class="ui yellow message">' + MainWP.I18n.t('Please select websites or groups or clients.') + '</div>');
229 254 }
230 255 }
231 256
232 257 let _status = '';
@@ -256,9 +281,71 @@
256 281 /**
257 282 * MainWP_Post.page
258 283 */
259 284
285 +let updatePostsBulkActionsState = function () {
286 + let checkedCount = jQuery('#mainwp-posts-table input[name="post[]"]:checked').length;
287 + let dropdown = jQuery('#mainwp-manage-posts #mainwp-bulk-actions');
288 + let applyButton = jQuery('#mainwp-do-posts-bulk-actions');
289 +
290 + if (checkedCount > 0) {
291 + dropdown.removeClass('disabled');
292 + dropdown.parent('.ui.dropdown').removeClass('disabled');
293 + applyButton.removeClass('disabled');
294 + } else {
295 + dropdown.addClass('disabled');
296 + dropdown.parent('.ui.dropdown').addClass('disabled');
297 + dropdown.dropdown('set selected', 'none');
298 + applyButton.addClass('disabled');
299 + }
300 +};
301 +
302 +let mainwp_copyTextToClipboard = function (value) {
303 +
304 + if (!value) {
305 + return Promise.reject(new Error('Empty clipboard value'));
306 + }
307 +
308 + if (navigator.clipboard && globalThis.isSecureContext) {
309 + return navigator.clipboard.writeText(value);
310 + }
311 +
312 + return new Promise(function (resolve, reject) {
313 +
314 + let tempField = jQuery('<textarea readonly class="mainwp-copy-temp-field" aria-hidden="true"></textarea>');
315 + tempField.css({
316 + position: 'absolute',
317 + left: '-9999px',
318 + top: '0'
319 + });
320 + jQuery('body').append(tempField);
321 + tempField.val(value).trigger('focus').trigger('select');
322 +
323 + try {
324 + if (document.execCommand('copy')) {
325 + tempField.remove();
326 + resolve();
327 + return;
328 + }
329 + } catch (err) {
330 + tempField.remove();
331 + reject(err);
332 + return;
333 + }
334 +
335 + tempField.remove();
336 + reject(new Error('Copy command failed'));
337 + });
338 +};
339 +
260 340 jQuery(function () {
341 +
342 + updatePostsBulkActionsState();
343 +
344 + jQuery(document).on('change', '#mainwp-posts-table .check-column INPUT:checkbox', function () {
345 + updatePostsBulkActionsState();
346 + });
347 +
261 348 jQuery(document).on('click', '#mainwp_show_posts', function () {
262 349 mainwp_fetch_posts();
263 350 });
264 351 jQuery(document).on('click', '.post_submitdelete', function () {
@@ -295,8 +382,25 @@
295 382 mainwppost_postAction(jQuery(this), 'get_edit', 'page');
296 383 return false;
297 384 });
298 385
386 + jQuery(document).on('click', '.mainwp-copy-row-value', function () {
387 + let button = jQuery(this);
388 + let rowElement = button.closest('tr');
389 + let target = button.data('copy-target');
390 + let value = '';
391 +
392 + if (target) {
393 + value = rowElement.find(target).val() || '';
394 + }
395 +
396 + mainwp_copyTextToClipboard(value).catch(function () {
397 + alert(MainWP.I18n.t('Unable to copy to clipboard.'));
398 + });
399 +
400 + return false;
401 + });
402 +
299 403 jQuery(document).on('click', '#mainwp-do-posts-bulk-actions', function () {
300 404 let action = jQuery('#mainwp-bulk-actions').val();
301 405 if (action != 'publish' && action != 'unpublish' && action != 'trash' && action != 'restore' && action != 'delete') {
302 406 return;
@@ -316,9 +420,9 @@
316 420 }
317 421 );
318 422 }
319 423 if (action == 'delete') {
320 - let msg = __('You are about to delete %1 post(s). Are you sure you want to proceed?', countSent);
424 + let msg = MainWP.I18n.t('You are about to delete %1 post(s). Are you sure you want to proceed?', countSent);
321 425 mainwp_confirm(msg, _callback);
322 426 return;
323 427 }
324 428 _callback();
@@ -328,9 +432,9 @@
328 432 let mainwppost_postAction = function (elem, what, postType) {
329 433 let rowElement = jQuery(elem).closest('tr');
330 434 let postId = rowElement.find('.postId').val();
331 435 let websiteId = rowElement.find('.websiteId').val();
332 - if (rowElement.find('.allowedBulkActions').val().indexOf('|' + what + '|') == -1) {
436 + if (!rowElement.find('.allowedBulkActions').val().includes('|' + what + '|')) {
333 437 jQuery(elem).prop("checked", false);
334 438 countReceived++;
335 439
336 440 if (countReceived == countSent) {
@@ -352,15 +456,15 @@
352 456 action: 'mainwp_post_' + what,
353 457 postId: postId,
354 458 websiteId: websiteId
355 459 };
356 - if (typeof postType !== "undefined") {
460 + if (postType !== undefined) {
357 461 data['postType'] = postType;
358 462 }
359 463 data = mainwp_secure_data(data);
360 464
361 465 rowElement.html('<td colspan="99"><i class="notched circle loading icon"></i> Please wait...</td>');
362 - jQuery.post(ajaxurl, data, function (response) {
466 + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complexity 11/10.
363 467 if (response.error) {
364 468 rowElement.html('<td colspan="99"><i class="times red icon"></i>' + response.error + '</td>');
365 469 } else if (response.result) {
366 470 rowElement.html('<td colspan="99"><i class="green check icon"></i> ' + response.result + '</td>');
@@ -369,15 +473,19 @@
369 473 }
370 474 } else {
371 475 rowElement.hide();
372 476 if (what == 'get_edit' && response.id) {
477 + let reloadUrl = '';
373 478 if (response.redirect_to) {
374 - location.href = response.redirect_to;
479 + reloadUrl = response.redirect_to;
375 480 } else if (postType == 'post') {
376 - location.href = 'admin.php?page=PostBulkEdit&post_id=' + response.id;
481 + reloadUrl = 'admin.php?page=PostBulkEdit&post_id=' + response.id;
377 482 } else if (postType == 'page') {
378 - location.href = 'admin.php?page=PageBulkEdit&post_id=' + response.id;
483 + reloadUrl = 'admin.php?page=PageBulkEdit&post_id=' + response.id;
379 484 }
485 + if (reloadUrl !== '') {
486 + mainwp_forceReload(reloadUrl);
487 + }
380 488 }
381 489 }
382 490 countReceived++;
383 491 if (countReceived == countSent) {
@@ -400,11 +508,8 @@
400 508 let mainwp_fetch_posts = function (postId, userId, start_sites) {
401 509
402 510 let params = mainwp_fetch_posts_prepare(postId, userId, start_sites);
403 511
404 - console.log('params:');
405 - console.log(params);
406 -
407 512 if (typeof params !== 'object') {
408 513 return;
409 514 }
410 515
@@ -419,9 +524,9 @@
419 524
420 525 let _status = '';
421 526 let statuses = jQuery("#mainwp_post_search_type").dropdown("get value");
422 527 if (statuses == null)
423 - errors.push('<div class="ui yellow message">' + __('Please select at least one post status.') + '</div>');
528 + errors.push('<div class="ui yellow message">' + MainWP.I18n.t('Please select at least one post status.') + '</div>');
424 529 else {
425 530 _status = statuses.join(',');
426 531 }
427 532
@@ -486,19 +591,19 @@
486 591 let selected_clients = [];
487 592
488 593 let i = 0;
489 594 let num_sites = jQuery('#search-bulk-sites').attr('number-sites');
490 - num_sites = parseInt(num_sites);
595 + num_sites = Number.parseInt(num_sites);
491 596
492 - let select_sites_error = '<div class="ui yellow message">' + __('Please select at least one website or group or client.') + '</div>';
597 + let select_sites_error = '<div class="ui yellow message">' + MainWP.I18n.t('Please select at least one website or group or client.') + '</div>';
493 598
494 599 let bulk_search = num_sites > 0;
495 600
496 - if (jQuery('#select_by').val() == 'site' && start_sites == undefined) {
601 + if (jQuery('input[name="select_by"]').val() == 'site' && start_sites == undefined) {
497 602 start_sites = 0;
498 603 }
499 604
500 - if (jQuery('#select_by').val() == 'site') {
605 + if (jQuery('input[name="select_by"]').val() == 'site') {
501 606 jQuery("input[name='selected_sites[]']:checked").each(function () {
502 607 if (bulk_search) {
503 608 if (i >= start_sites && i < start_sites + num_sites) {
504 609 selected_sites.push(jQuery(this).val());
@@ -510,24 +615,23 @@
510 615 });
511 616 if (selected_sites.length == 0 && (!bulk_search || (bulk_search && start_sites == 0))) {
512 617 errors.push(select_sites_error);
513 618 }
514 - } else if (jQuery('#select_by').val() == 'client') {
619 + } else if (jQuery('input[name="select_by"]').val() == 'client') {
515 620 jQuery("input[name='selected_clients[]']:checked").each(function () {
516 621 selected_clients.push(jQuery(this).val());
517 622 });
518 - if(selected_clients.length == 0){
623 + if (selected_clients.length == 0) {
519 624 errors.push(select_sites_error);
520 625 }
521 - } else if (jQuery('#select_by').val() == 'group') {
626 + } else if (jQuery('input[name="select_by"]').val() == 'group') {
522 627 jQuery("input[name='selected_groups[]']:checked").each(function () {
523 628 selected_groups.push(jQuery(this).val());
524 629 });
525 630
526 - if(selected_groups.length == 0){
631 + if (selected_groups.length == 0) {
527 632 errors.push(select_sites_error);
528 633 } else if (selected_groups.length > 0 && bulk_search && start_sites == undefined) {
529 - console.log(num_sites);
530 634 start_sites = 0;
531 635 // get sites of groups.
532 636 let data = mainwp_secure_data({
533 637 action: 'mainwp_get_sites_of_groups',
@@ -589,14 +693,15 @@
589 693 "columnDefs": [{
590 694 "targets": 'no-sort',
591 695 "orderable": false
592 696 }],
593 - "preDrawCallback": function () {
697 + "drawCallback": function () {
594 698 setTimeout(() => {
595 - jQuery('#mainwp-posts-table-wrapper table .ui.dropdown').dropdown();
596 - jQuery('#mainwp-posts-table-wrapper table .ui.checkbox').checkbox();
597 - mainwp_datatable_fix_menu_overflow();
699 + jQuery('#mainwp-posts-table .ui.dropdown').dropdown();
700 + jQuery('#mainwp-posts-table .ui.checkbox').checkbox();
701 + mainwp_datatable_fix_menu_overflow('#mainwp-posts-table');
598 702 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
703 + updatePostsBulkActionsState();
599 704 }, 1000);
600 705 },
601 706 select: {
602 707 items: 'row',
@@ -607,8 +712,9 @@
607 712 if ('row' == type) {
608 713 dt.rows(indexes)
609 714 .nodes()
610 715 .to$().find('td.check-column .ui.checkbox').checkbox('set checked');
716 + updatePostsBulkActionsState();
611 717 }
612 718 }).on('deselect', function (e, dt, type, indexes) {
613 719 if ('row' == type) {
614 720 dt.rows(indexes)
@@ -613,15 +719,16 @@
613 719 if ('row' == type) {
614 720 dt.rows(indexes)
615 721 .nodes()
616 722 .to$().find('td.check-column .ui.checkbox').checkbox('set unchecked');
723 + updatePostsBulkActionsState();
617 724 }
618 725 }).on('columns-reordered', function () {
619 - console.log('columns-reordered');
620 726 setTimeout(() => {
621 - jQuery('#mainwp-posts-table-wrapper table .ui.dropdown').dropdown();
622 - jQuery('#mainwp-posts-table-wrapper table .ui.checkbox').checkbox();
623 - mainwp_datatable_fix_menu_overflow();
727 + jQuery('#mainwp-posts-table .ui.dropdown').dropdown();
728 + jQuery('#mainwp-posts-table .ui.checkbox').checkbox();
729 + mainwp_datatable_fix_menu_overflow('#mainwp-posts-table');
624 730 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
731 + updatePostsBulkActionsState();
625 732 }, 1000);
626 733 });
627 734 }