Skip to content

Commit

Permalink
Improve hidden column handling; add print trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Dec 26, 2023
1 parent f7548ae commit 703c819
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/css/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ button.mt-show-button {
display: block;
}

#wpcontent a.print-button {
display: none;
}

#wpcontent .postbox {
margin: 0;
border: none;
Expand Down Expand Up @@ -92,8 +88,8 @@ td.mt-post {
width: 6em;
}

.hidden {
display: none;
td.mt-hidden {
opacity: .25;
}

.tabs {
Expand All @@ -114,6 +110,9 @@ table a:hover, table a:focus {
tr:nth-of-type(odd) {
background: #fefefe;
}
.mt-hidden {
display: none;
}
button {
display: none;
}
Expand Down
19 changes: 14 additions & 5 deletions src/js/report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery(document).ready(function ($) {
var cols = $( 'th[scope=col]' );
$( '.show-button' ).hide();
$( '.show-button' ).attr( 'disabled', 'disabled' );

cols.each( function() {
var context = $( this ).attr( 'class' );
Expand All @@ -10,13 +10,22 @@ jQuery(document).ready(function ($) {

$( 'button' ).on( 'click', function(e) {
var effects = $(this).attr( 'data-context' );
$( '.' + effects ).addClass( 'hidden' );
$( '.show-button' ).show();
var pressed = $(this).attr( 'aria-pressed' );
if ( 'true' === pressed ) {
$( '.' + effects ).removeClass( 'mt-hidden' );
$( this ).find( 'span' ).removeClass( 'dashicons-hidden' ).addClass( 'dashicons-visibility' );
$( this ).removeAttr( 'aria-pressed' );
} else {
$( '.' + effects ).addClass( 'mt-hidden' );
$( '.show-button' ).removeAttr( 'disabled' );
$( this ).find( 'span' ).removeClass( 'dashicons-visibility' ).addClass( 'dashicons-hidden' );
$( this ).attr( 'aria-pressed', 'true' );
}
});

$( '.show-button' ).on( 'click', function(e) {
$( 'th.hidden, td.hidden' ).removeClass( 'hidden' );
$( this ).hide();
$( 'th.hidden, td.hidden' ).removeClass( 'mt-hidden' );
$( this ).attr( 'disabled', 'disabled' );
});

});
10 changes: 7 additions & 3 deletions src/mt-reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function mt_reports_page() {

<div class="inside">
<?php
echo wp_kses( '<p><button class="show-button">' . __( 'Show Hidden Columns', 'my-tickets' ) . '</button></p>', mt_kses_elements() );
if ( isset( $_POST['event_id'] ) && is_numeric( $_POST['event_id'] ) ) {
if ( ! ( '' === strip_tags( $_POST['mt_subject'] ) || '' === strip_tags( $_POST['mt_body'] ) ) ) {
$verify = wp_verify_nonce( $_POST['mt-email-nonce'], 'mt-email-purchasers' );
Expand All @@ -51,10 +50,15 @@ function mt_reports_page() {
}
$event_id = (int) $_GET['event_id'];
$report_type = ( isset( $_GET['mt-event-report'] ) && 'tickets' === $_GET['mt-event-report'] ) ? 'tickets' : 'purchases';
$print_report_url = admin_url( 'admin.php?page=mt-reports&event_id=' . $event_id . '&mt-event-report=' . $report_type . '&format=view&mt_print=true' );
if ( isset( $_GET['mt_print'] ) ) {
$print_report_url = 'javascript:window.print()';
} else {
$print_report_url = esc_url( admin_url( 'admin.php?page=mt-reports&event_id=' . $event_id . '&mt-event-report=' . $report_type . '&format=view&mt_print=true' ) );
}
$back_url = admin_url( apply_filters( 'mt_printable_report_back', 'admin.php?page=mt-reports&mt-event-report=' . $report_type . '&event_id=' . $event_id ) );
$return = ( isset( $_GET['mt_print'] ) ) ? '<a class="mt-back button" href="' . esc_url( $back_url ) . '">' . __( 'Return to My Tickets Reports', 'my-tickets' ) . '</a>' : '';
echo wp_kses_post( '<p><a class="button print-button" href="' . esc_url( $print_report_url ) . '">' . __( 'Print this report', 'my-tickets' ) . '</a> ' . $return . '</p>' );
$show = '<button class="button show-button">' . esc_html( __( 'Show Hidden Columns', 'my-tickets' ) ) . '</button>';
echo '<p><a class="button print-button" href="' . $print_report_url . '">' . __( 'Print this report', 'my-tickets' ) . '</a> ' . $return . ' ' . $show . '</p>';
}
?>
<div class="mt-report-selector">
Expand Down

0 comments on commit 703c819

Please sign in to comment.