Adding more functionality

This commit is contained in:
2025-08-29 18:54:14 -07:00
parent 264e65006a
commit ce48f1615f
14 changed files with 4098 additions and 84 deletions

124
assets/js/admin-payouts.js Normal file
View File

@@ -0,0 +1,124 @@
jQuery(document).ready(function($) {
// Handle individual payout processing
$('.wpdd-process-payout').on('click', function(e) {
e.preventDefault();
var $button = $(this);
var payoutId = $button.data('payout-id');
var originalText = $button.text();
// Disable button and show loading
$button.prop('disabled', true).text('Processing...');
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'wpdd_process_payout',
payout_id: payoutId,
nonce: wpdd_admin_nonce
},
success: function(response) {
if (response.success) {
$button.closest('tr').find('.payout-status').text('Processing');
$button.text('Processed').removeClass('wpdd-process-payout').addClass('button-disabled');
} else {
alert('Error: ' + (response.data || 'Unknown error occurred'));
$button.prop('disabled', false).text(originalText);
}
},
error: function() {
alert('Ajax request failed');
$button.prop('disabled', false).text(originalText);
}
});
});
// Handle payout request approval
$('.wpdd-approve-request').on('click', function(e) {
e.preventDefault();
var $button = $(this);
var requestId = $button.data('request-id');
var originalText = $button.text();
// Disable button and show loading
$button.prop('disabled', true).text('Processing...');
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'wpdd_approve_payout_request',
request_id: requestId,
nonce: wpdd_admin_nonce
},
success: function(response) {
if (response.success) {
location.reload(); // Reload to show updated status
} else {
alert('Error: ' + (response.data || 'Unknown error occurred'));
$button.prop('disabled', false).text(originalText);
}
},
error: function() {
alert('Ajax request failed');
$button.prop('disabled', false).text(originalText);
}
});
});
// Handle bulk payout processing
$('#wpdd-process-bulk-payouts').on('click', function(e) {
e.preventDefault();
var checkedPayouts = $('.wpdd-payout-checkbox:checked');
if (checkedPayouts.length === 0) {
alert('Please select at least one payout to process.');
return;
}
if (!confirm('Are you sure you want to process ' + checkedPayouts.length + ' payout(s)?')) {
return;
}
var $button = $(this);
var originalText = $button.text();
var payoutIds = [];
checkedPayouts.each(function() {
payoutIds.push($(this).val());
});
// Disable button and show loading
$button.prop('disabled', true).text('Processing...');
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'wpdd_process_bulk_payouts',
payout_ids: payoutIds,
nonce: wpdd_admin_nonce
},
success: function(response) {
if (response.success) {
location.reload(); // Reload to show updated status
} else {
alert('Error: ' + (response.data || 'Unknown error occurred'));
$button.prop('disabled', false).text(originalText);
}
},
error: function() {
alert('Ajax request failed');
$button.prop('disabled', false).text(originalText);
}
});
});
// Handle select all checkboxes
$('#wpdd-select-all-payouts').on('change', function() {
$('.wpdd-payout-checkbox').prop('checked', $(this).prop('checked'));
});
});