| 1 |
/** |
| 2 |
* Handles UI elements for the Plugin Log screen. |
| 3 |
* |
| 4 |
* @since 3.9.6 |
| 5 |
* |
| 6 |
* @package |
| 7 |
* @author WP Zinc |
| 8 |
*/ |
| 9 |
|
| 10 |
jQuery( document ).ready( |
| 11 |
function ($) { |
| 12 |
/** |
| 13 |
* Refresh Log |
| 14 |
* |
| 15 |
* @since 4.4.0 |
| 16 |
*/ |
| 17 |
$( 'a.' + wp_to_social_pro.plugin_name + '-refresh-log' ).on( |
| 18 |
'click', |
| 19 |
function (e) { |
| 20 |
// Prevent default action. |
| 21 |
e.preventDefault(); |
| 22 |
|
| 23 |
// Define button. |
| 24 |
const button = $( this ); |
| 25 |
|
| 26 |
// Send AJAX request to clear log. |
| 27 |
$.post( |
| 28 |
wp_to_social_pro.ajax, |
| 29 |
{ |
| 30 |
action: $( button ).data( 'action' ), |
| 31 |
post: wp_to_social_pro.post_id, |
| 32 |
nonce: wp_to_social_pro.get_log_nonce, |
| 33 |
}, |
| 34 |
function (response) { |
| 35 |
// Replace the table data with the response data. |
| 36 |
$( 'table.widefat tbody', $( $( button ).data( 'target' ) ) ).html( |
| 37 |
response.data |
| 38 |
); |
| 39 |
} |
| 40 |
); |
| 41 |
} |
| 42 |
); |
| 43 |
|
| 44 |
/** |
| 45 |
* Clear Log |
| 46 |
* |
| 47 |
* @since 3.0.0 |
| 48 |
*/ |
| 49 |
$( 'a.' + wp_to_social_pro.plugin_name + '-clear-log' ).on( |
| 50 |
'click', |
| 51 |
function (e) { |
| 52 |
// Define button. |
| 53 |
const button = $( this ); |
| 54 |
|
| 55 |
// Bail if the user doesn't want to clear the log. |
| 56 |
const result = confirm( $( button ).data( 'message' ) ); |
| 57 |
if ( ! result) { |
| 58 |
// Prevent default action. |
| 59 |
e.preventDefault(); |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
// If the button doesn't have an action and a target, it's not an AJAX request. |
| 64 |
// Let the request through. |
| 65 |
if ( |
| 66 |
typeof $( button ).data( 'action' ) === 'undefined' || |
| 67 |
typeof $( button ).data( 'target' ) === 'undefined' |
| 68 |
) { |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
// Prevent default action. |
| 73 |
e.preventDefault(); |
| 74 |
|
| 75 |
// Send AJAX request to clear log. |
| 76 |
$.post( |
| 77 |
wp_to_social_pro.ajax, |
| 78 |
{ |
| 79 |
action: $( button ).data( 'action' ), |
| 80 |
post: $( 'input[name=post_ID]' ).val(), |
| 81 |
nonce: wp_to_social_pro.clear_log_nonce, |
| 82 |
}, |
| 83 |
function () { |
| 84 |
// Clear Log. |
| 85 |
$( 'table.widefat tbody', $( $( button ).data( 'target' ) ) ).html( |
| 86 |
'<tr><td colspan="8">' + |
| 87 |
wp_to_social_pro.clear_log_completed + |
| 88 |
'</td></tr>' |
| 89 |
); |
| 90 |
} |
| 91 |
); |
| 92 |
} |
| 93 |
); |
| 94 |
} |
| 95 |
); |
| 96 |
|