| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
| defined('ABSPATH') || exit;
|
|
|
| add_action('admin_enqueue_scripts', function($hook_suffix) {
|
| wp_enqueue_script('jquery');
|
|
|
| $inline_js = <<<'JAVASCRIPT'
|
| jQuery(document).ready(function($) {
|
|
|
| function addSelectButtons() {
|
| var $formSection = $('label:contains("Form Selection"), h3:contains("Form Selection"), .gform-settings-field__label:contains("Form Selection")').first();
|
|
|
| if ($formSection.length === 0) {
|
| $formSection = $('label:contains("(Required)"), .gform-settings-field__label:contains("(Required)")').filter(':contains("Form")').first();
|
| }
|
|
|
| var $select2Container = $formSection.closest('.gform-settings-panel__content, .form-table, div').find('.select2-container').first();
|
|
|
| if ($select2Container.length === 0) {
|
| var $hiddenSelect = $('select[multiple], select[name*="forms"], select.ea-forms-select, select#forms');
|
| if ($hiddenSelect.length > 0) {
|
| $select2Container = $hiddenSelect.siblings('.select2-container').first();
|
| if ($select2Container.length === 0) {
|
| $select2Container = $hiddenSelect.next('.select2-container');
|
| }
|
| }
|
| }
|
|
|
| if ($('.ea-select-buttons').length > 0) return;
|
|
|
| if ($select2Container.length > 0) {
|
| var $actualSelect = $select2Container.prev('select');
|
| if ($actualSelect.length === 0) {
|
| $actualSelect = $select2Container.siblings('select').first();
|
| }
|
| if ($actualSelect.length === 0) {
|
| $actualSelect = $('#' + $select2Container.attr('id').replace('s2id_', ''));
|
| }
|
|
|
| var $buttonContainer = $('<div class="ea-select-buttons" style="margin-top: 10px; margin-bottom: 10px;"></div>');
|
|
|
| // Select All button with column loading fix
|
| var $selectAllBtn = $('<button type="button" class="button button-primary" style="margin-right: 8px;">Select All Forms</button>');
|
|
|
| var $selectNoneBtn = $('<button type="button" class="button button-secondary">Clear Selection</button>');
|
|
|
| var getAllOptions = function() {
|
| if ($actualSelect.length > 0) {
|
| return $actualSelect.find('option').map(function() {
|
| return $(this).val();
|
| }).get();
|
| }
|
| return $select2Container.select2('data');
|
| };
|
|
|
| // Modified Select All handler that triggers column loading
|
| $selectAllBtn.on('click', function(e) {
|
| e.preventDefault();
|
| e.stopPropagation();
|
|
|
| if ($actualSelect.length > 0) {
|
| var allValues = getAllOptions();
|
|
|
| // First set all values
|
| $actualSelect.val(allValues);
|
|
|
| // Trigger change events to load columns
|
| $actualSelect.trigger('change');
|
| $actualSelect.trigger('change.select2');
|
|
|
| // Force a second change event after a delay to ensure columns load
|
| setTimeout(function() {
|
| $actualSelect.trigger('change');
|
|
|
| // Some interfaces need the input event too
|
| $actualSelect.trigger('input');
|
|
|
| // If there's a specific update button, click it
|
| var $updateBtn = $('button:contains("Update"), input[value="Update"]').first();
|
| if ($updateBtn.length > 0) {
|
| $updateBtn.click();
|
| }
|
| }, 500);
|
|
|
| showNotification('Selected all ' + allValues.length + ' forms! Columns should load shortly...');
|
| }
|
| });
|
|
|
| $selectNoneBtn.on('click', function(e) {
|
| e.preventDefault();
|
| e.stopPropagation();
|
|
|
| if ($actualSelect.length > 0) {
|
| $actualSelect.val([]).trigger('change.select2').trigger('change');
|
| showNotification('Cleared all selections');
|
| }
|
| });
|
|
|
| $buttonContainer.append($selectAllBtn).append($selectNoneBtn);
|
| $select2Container.after($buttonContainer);
|
|
|
| var optionCount = $actualSelect.find('option').length;
|
| if (optionCount > 0) {
|
| $buttonContainer.append('<span style="margin-left: 10px; color: #666; font-size: 12px;">(' + optionCount + ' forms available)</span>');
|
| }
|
|
|
| console.log('Entry Automation Select All: Buttons added successfully');
|
| } else {
|
| console.log('Entry Automation Select All: Select2 container not found, retrying...');
|
| setTimeout(addSelectButtons, 1000);
|
| }
|
| }
|
|
|
| function showNotification(message) {
|
| var $notice = $('<div class="notice notice-success is-dismissible" style="position: fixed; top: 50px; right: 20px; z-index: 9999; padding: 12px 20px; background: #00a32a; color: white; border-radius: 4px;">' + message + '</div>');
|
| $('body').append($notice);
|
| setTimeout(function() {
|
| $notice.fadeOut(300, function() {
|
| $notice.remove();
|
| });
|
| }, 2000);
|
| }
|
|
|
| if (window.location.href.indexOf('page=gf_export') > -1 ||
|
| window.location.href.indexOf('page=gf_entry_automation') > -1 ||
|
| window.location.href.indexOf('page=ea_') > -1 ||
|
| $('h1:contains("Multiple Forms"), h2:contains("Multiple Forms")').length > 0) {
|
|
|
| addSelectButtons();
|
|
|
| $(document).on('change', 'select[multiple]', function() {
|
| if ($('.ea-select-buttons').length === 0) {
|
| addSelectButtons();
|
| }
|
| });
|
|
|
| $(document).on('select2:open', function(e) {
|
| if ($('.ea-select-buttons').length === 0) {
|
| setTimeout(addSelectButtons, 100);
|
| }
|
| });
|
| }
|
| });
|
| JAVASCRIPT;
|
|
|
| wp_add_inline_script('jquery', $inline_js, 'after');
|
| });
|
| |
| |
Comments