| @@ -321,16 +321,34 @@ | ||
| 321 | 321 | if (!empty($automations)) : |
| 322 | 322 | ?> |
| 323 | 323 | <div class="funnel-list__wrapper"> |
| 324 | 324 | <div class="funnel__single-list list-header"> |
| 325 | - <!-- <div class="funnel-list__bulk-action"> | |
| 326 | - <div class="funnel-list__bulk-select select-all-funnels" > | |
| 325 | + <div class="bulk-action-wrapper" style="display:none;"> | |
| 326 | + <p> | |
| 327 | + <span class="selected-funnel-count">0 <?php echo __('Automation', 'wpfnl'); ?></span> | |
| 328 | + <?php echo __('Selected', 'wpfnl'); ?> | |
| 329 | + </p> | |
| 330 | + <button class="btn-default bulk-delete-toggler"> | |
| 331 | + <?php echo __('Bulk Actions', 'wpfnl'); ?> | |
| 332 | + <svg width="8" height="6" fill="none" viewBox="0 0 8 6" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" stroke="#fff" stroke-width=".2" d="M4 5.28a.559.559 0 01-.396-.164l-3.44-3.44A.56.56 0 11.956.884L4 3.928 7.044.884a.56.56 0 01.792.792l-3.44 3.44A.559.559 0 014 5.28z"/></svg> | |
| 333 | + <ul class="wpfnl-dropdown"> | |
| 334 | + <li> | |
| 335 | + <a href="#" class="delete wpfnl-automation-bulk-delete"> | |
| 336 | + <?php require WPFNL_DIR . '/admin/partials/icons/delete-icon.php'; ?> | |
| 337 | + <?php echo __('Delete', 'wpfnl'); ?> | |
| 338 | + </a> | |
| 339 | + </li> | |
| 340 | + </ul> | |
| 341 | + </button> | |
| 342 | + </div> | |
| 343 | + <div class="funnel-list__bulk-action"> | |
| 344 | + <div class="funnel-list__bulk-select select-all-funnels"> | |
| 327 | 345 | <span class="wpfnl-checkbox no-title"> |
| 328 | - <input type="checkbox" name="funnel-list__bulk-select" id="funnel-list__bulk-select"> | |
| 329 | - <label for="funnel-list__bulk-select"></label> | |
| 346 | + <input type="checkbox" name="automation-list__bulk-select" id="automation-list__bulk-select"> | |
| 347 | + <label for="automation-list__bulk-select"></label> | |
| 330 | 348 | </span> |
| 331 | 349 | </div> |
| 332 | - </div> --> | |
| 350 | + </div> | |
| 333 | 351 | <div class="list-cell wpfnl-name"><?php echo __('Automation Name', 'wpfnl'); ?></div> |
| 334 | 352 | <div class="list-cell wpfnl-customers"><?php echo __('Customers', 'wpfnl'); ?></div> |
| 335 | 353 | <div class="list-cell wpfnl-status"><?php echo __('Status', 'wpfnl'); ?></div> |
| 336 | 354 | <div class="list-cell list-action"><?php echo __('Action', 'wpfnl'); ?></div> |
| @@ -338,14 +356,14 @@ | ||
| 338 | 356 | <?php |
| 339 | 357 | foreach ($automations as $automation) : |
| 340 | 358 | ?> |
| 341 | 359 | <div class="funnel__single-list list-body"> |
| 342 | - <!-- <div class="funnel-list__bulk-action"> | |
| 360 | + <div class="funnel-list__bulk-action"> | |
| 343 | 361 | <span class="wpfnl-checkbox no-title"> |
| 344 | - <input type="checkbox" name="funnel-list-select" id="funnel-list<?php echo $automation['id']; ?>-select" data-id="<?php echo $automation['id']; ?>"> | |
| 345 | - <label for="funnel-list<?php echo $automation['id']; ?>-select"></label> | |
| 362 | + <input type="checkbox" name="automation-list-select" id="automation-list-<?php echo esc_attr( $automation['id'] ); ?>-select" data-id="<?php echo esc_attr( $automation['id'] ); ?>"> | |
| 363 | + <label for="automation-list-<?php echo esc_attr( $automation['id'] ); ?>-select"></label> | |
| 346 | 364 | </span> |
| 347 | - </div> --> | |
| 365 | + </div> | |
| 348 | 366 | <div class="list-cell wpfnl-name"> |
| 349 | 367 | <span class="builder-logo"> |
| 350 | 368 | <?php require WPFNL_DIR . '/admin/partials/icons/automation-list-icon.php'; ?> |
| 351 | 369 | </span> |
| @@ -642,13 +660,91 @@ | ||
| 642 | 660 | beforeSend: function(xhr) { |
| 643 | 661 | xhr.setRequestHeader('X-WP-Nonce', wpfnlAutomationVars.restNonce); |
| 644 | 662 | }, |
| 645 | 663 | success: function() { |
| 646 | - $(row).remove(); | |
| 664 | + location.reload(); | |
| 647 | 665 | }, |
| 648 | 666 | error: function() { |
| 649 | 667 | row.style.opacity = '1'; |
| 650 | 668 | alert('Failed to delete automation. Please try again.'); |
| 669 | + } | |
| 670 | + }); | |
| 671 | + }); | |
| 672 | + }); | |
| 673 | + | |
| 674 | + // Bulk action: counter + show/hide wrapper (mirrors funnel listing pattern) | |
| 675 | + function automationSelectedCounter() { | |
| 676 | + var total = $('input[name=automation-list-select]:checked').length; | |
| 677 | + if (total > 0) { | |
| 678 | + var label = total > 1 ? total + ' Automations' : total + ' Automation'; | |
| 679 | + $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(label); | |
| 680 | + $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'flex'); | |
| 681 | + } else { | |
| 682 | + $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none'); | |
| 683 | + } | |
| 684 | + } | |
| 685 | + | |
| 686 | + // Per-row checkbox change | |
| 687 | + $('.funnel__single-list.list-body input[name=automation-list-select]').on('change', function() { | |
| 688 | + $('#automation-list__bulk-select').prop('checked', false); | |
| 689 | + automationSelectedCounter(); | |
| 690 | + }); | |
| 691 | + | |
| 692 | + // Select-all checkbox change | |
| 693 | + $('#automation-list__bulk-select').on('change', function() { | |
| 694 | + if ($(this).is(':checked')) { | |
| 695 | + $('input[name=automation-list-select]').prop('checked', true); | |
| 696 | + automationSelectedCounter(); | |
| 697 | + } else { | |
| 698 | + $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none'); | |
| 699 | + $('input[name=automation-list-select]').prop('checked', false); | |
| 700 | + } | |
| 701 | + }); | |
| 702 | + | |
| 703 | + // Bulk delete (from dropdown) | |
| 704 | + $(document).on('click', '.wpfnl-automation-bulk-delete', function(e) { | |
| 705 | + e.preventDefault(); | |
| 706 | + e.stopPropagation(); | |
| 707 | + $('.bulk-delete-toggler').removeClass('show-dropdown'); | |
| 708 | + | |
| 709 | + var checked = $('input[name=automation-list-select]:checked'); | |
| 710 | + if (checked.length === 0) return; | |
| 711 | + | |
| 712 | + if ( ! confirm('Are you sure you want to delete ' + checked.length + ' automation(s)? This action cannot be undone.') ) { | |
| 713 | + return; | |
| 714 | + } | |
| 715 | + | |
| 716 | + var ids = []; | |
| 717 | + checked.each(function() { ids.push($(this).data('id')); }); | |
| 718 | + | |
| 719 | + var remaining = ids.length; | |
| 720 | + var failed = 0; | |
| 721 | + | |
| 722 | + $.each(ids, function(i, automationId) { | |
| 723 | + var row = $('input[name=automation-list-select][data-id="' + automationId + '"]').closest('.funnel__single-list'); | |
| 724 | + row.css('opacity', '0.5'); | |
| 725 | + | |
| 726 | + $.ajax({ | |
| 727 | + url: wpfnlAutomationVars.restUrl + 'wpfunnels/v1/automation-canvas/' + automationId, | |
| 728 | + type: 'DELETE', | |
| 729 | + beforeSend: function(xhr) { | |
| 730 | + xhr.setRequestHeader('X-WP-Nonce', wpfnlAutomationVars.restNonce); | |
| 731 | + }, | |
| 732 | + success: function() { | |
| 733 | + row.remove(); | |
| 734 | + }, | |
| 735 | + error: function() { | |
| 736 | + row.css('opacity', '1'); | |
| 737 | + failed++; | |
| 738 | + }, | |
| 739 | + complete: function() { | |
| 740 | + remaining--; | |
| 741 | + if (remaining === 0) { | |
| 742 | + if (failed > 0) { | |
| 743 | + alert(failed + ' automation(s) could not be deleted. Please try again.'); | |
| 744 | + } | |
| 745 | + location.reload(); | |
| 746 | + } | |
| 651 | 747 | } |
| 652 | 748 | }); |
| 653 | 749 | }); |
| 654 | 750 | }); |