| @@ -39,8 +39,9 @@ | ||
| 39 | 39 | 'pending' => 'pending', |
| 40 | 40 | 'pe_cancelled' => 'pending-cancel', |
| 41 | 41 | 'cancelled' => 'cancelled', |
| 42 | 42 | 'expired' => 'expired', |
| 43 | + 'completed' => 'completed', | |
| 43 | 44 | 'draft' => 'draft', |
| 44 | 45 | 'trash' => 'trash', |
| 45 | 46 | ); |
| 46 | 47 | $badge_mod = $badge_mod_map[ $subscrpt_status ] ?? 'expired'; |
| @@ -63,13 +64,15 @@ | ||
| 63 | 64 | |
| 64 | 65 | // Page header: product title + meta description (badge · #id · email · next payment). |
| 65 | 66 | $header_title = ( $product_name && '-' !== $product_name ) |
| 66 | 67 | ? $product_name |
| 67 | - /* translators: %s: subscription ID */ | |
| 68 | + /* translators: %s: Subscription ID */ | |
| 68 | 69 | : sprintf( __( 'Subscription #%s', 'subscription' ), $subscription_id ); |
| 69 | 70 | |
| 70 | 71 | $next_payment_date = $subscription_data['next_date'] ?? ''; |
| 71 | -$next_payment_date = ! empty( $next_payment_date ) ? wp_date( get_option( 'date_format' ), strtotime( $next_payment_date ) ) : ''; | |
| 72 | +$next_payment_date = ! empty( $next_payment_date ) && Helper::has_next_payment( $subscription_data['status'] ?? '' ) | |
| 73 | + ? wp_date( get_option( 'date_format' ), strtotime( $next_payment_date ) ) | |
| 74 | + : ''; | |
| 72 | 75 | |
| 73 | 76 | $header_badge = '<span class="wpsubs-badge wpsubs-badge--' . esc_attr( $badge_mod ) . '">' . esc_html( $verbose_status ); |
| 74 | 77 | if ( $is_grace_period && $grace_remaining > 0 ) { |
| 75 | 78 | /* translators: %d: days remaining */ |
| @@ -102,14 +105,26 @@ | ||
| 102 | 105 | $timing_per = (int) ( $subscription_data['schedule']['timing_per'] ?? 1 ); |
| 103 | 106 | $timing_option = $subscription_data['schedule']['timing_option'] ?? ''; |
| 104 | 107 | $period_label = ''; |
| 105 | 108 | if ( $timing_option ) { |
| 109 | + $timing_unit = ucfirst( Helper::get_typos( $timing_per, $timing_option ) ); | |
| 106 | 110 | $period_label = $timing_per > 1 |
| 107 | - ? $timing_per . ' ' . ucfirst( $timing_option ) . 's' | |
| 108 | - : ucfirst( $timing_option ); | |
| 111 | + ? $timing_per . ' ' . $timing_unit | |
| 112 | + : $timing_unit; | |
| 109 | 113 | } |
| 110 | 114 | |
| 111 | - $recurring_value = wc_price( (float) $subscription_data['price'], array( 'currency' => $order->get_currency() ) ); | |
| 115 | + // Net of any discount that carries into renewals, with the original struck through. | |
| 116 | + $recurring_totals = Helper::get_subscription_display_totals( $subscription_id, $order_item ); | |
| 117 | + $recurring_full = $recurring_totals['full_excl'] + $recurring_totals['tax'] + $recurring_totals['discount_tax']; | |
| 118 | + | |
| 119 | + $recurring_value = wc_price( (float) $recurring_totals['total'], array( 'currency' => $order->get_currency() ) ); | |
| 120 | + | |
| 121 | + if ( $recurring_totals['has_discount'] ) { | |
| 122 | + $recurring_value = '<del aria-hidden="true" class="subscrpt-summary__was">' | |
| 123 | + . wc_price( $recurring_full, array( 'currency' => $order->get_currency() ) ) | |
| 124 | + . '</del> ' . $recurring_value; | |
| 125 | + } | |
| 126 | + | |
| 112 | 127 | if ( $period_label ) { |
| 113 | 128 | $recurring_value .= '<span class="subscrpt-summary__unit"> / ' . esc_html( $period_label ) . '</span>'; |
| 114 | 129 | } |
| 115 | 130 | |
| @@ -123,14 +138,13 @@ | ||
| 123 | 138 | 'label' => __( 'Started', 'subscription' ), |
| 124 | 139 | 'value' => esc_html( wp_date( get_option( 'date_format' ), strtotime( $subscription_data['start_date'] ) ) ), |
| 125 | 140 | ); |
| 126 | 141 | } |
| 127 | -if ( ! empty( $subscription_data['next_date'] ) ) { | |
| 128 | - $summary_tiles[] = array( | |
| 129 | - 'label' => __( 'Next Payment', 'subscription' ), | |
| 130 | - 'value' => esc_html( wp_date( get_option( 'date_format' ), strtotime( $subscription_data['next_date'] ) ) ), | |
| 131 | - ); | |
| 132 | -} | |
| 142 | +// Always show the Next Payment tile; dash when there is no next date. | |
| 143 | +$summary_tiles[] = array( | |
| 144 | + 'label' => __( 'Next Payment', 'subscription' ), | |
| 145 | + 'value' => $next_payment_date ? esc_html( $next_payment_date ) : '-', | |
| 146 | +); | |
| 133 | 147 | // Total payments is not part of $subscription_data; pull it from the info rows. |
| 134 | 148 | if ( isset( $rows['total_payments'] ) ) { |
| 135 | 149 | $summary_tiles[] = array( |
| 136 | 150 | 'label' => __( 'Total Payments', 'subscription' ), |
| @@ -151,8 +165,9 @@ | ||
| 151 | 165 | |
| 152 | 166 | // Plan card: product + qty render side by side; trial/signup fee as extra rows. |
| 153 | 167 | $plan_product = isset( $rows['product'] ) ? $rows['product']['value'] : ''; |
| 154 | 168 | $plan_qty = isset( $rows['quantity'] ) ? $rows['quantity']['value'] : ''; |
| 169 | +$plan_label = function_exists( 'subscrpt_get_subscription_plan_label' ) ? subscrpt_get_subscription_plan_label( $subscription_id ) : ''; | |
| 155 | 170 | $plan_extra = array(); |
| 156 | 171 | foreach ( array( 'product', 'quantity', 'signup_fee', 'trial', 'trial_period' ) as $plan_key ) { |
| 157 | 172 | $used_keys[ $plan_key ] = true; |
| 158 | 173 | if ( in_array( $plan_key, array( 'signup_fee', 'trial', 'trial_period' ), true ) && isset( $rows[ $plan_key ] ) ) { |
| @@ -254,8 +269,18 @@ | ||
| 254 | 269 | 'label' => ucfirst( str_replace( '-', ' ', (string) $history->type ) ), |
| 255 | 270 | ); |
| 256 | 271 | } |
| 257 | 272 | |
| 273 | +/* | |
| 274 | + * Sequence number within this subscription: 1 = first (parent) order, then each | |
| 275 | + * renewal in order. Helper::get_related_orders() returns newest-first, so the | |
| 276 | + * sequence counts down across the rendered rows. | |
| 277 | + */ | |
| 278 | +$related_count = count( $related_rows ); | |
| 279 | +foreach ( array_keys( $related_rows ) as $related_index ) { | |
| 280 | + $related_rows[ $related_index ]['seq'] = $related_count - $related_index; | |
| 281 | +} | |
| 282 | + | |
| 258 | 283 | // Reusable per-page + date toolbar for the paginated tables. Uses the admin |
| 259 | 284 | // advanced-select component; the date options are injected client-side from the |
| 260 | 285 | // table's date column. |
| 261 | 286 | $subscrpt_render_table_tools = function () { |
| @@ -276,32 +301,13 @@ | ||
| 276 | 301 | ), |
| 277 | 302 | ), |
| 278 | 303 | ) |
| 279 | 304 | ); |
| 280 | - wpsubs_render_adv_select( | |
| 305 | + wpsubs_render_per_page_select( | |
| 281 | 306 | array( |
| 282 | - 'name' => 'subscrpt_per_page', | |
| 283 | - 'value' => '10', | |
| 284 | - 'align' => 'right', | |
| 285 | - 'class' => 'subscrpt-filter-perpage', | |
| 286 | - 'options' => array( | |
| 287 | - array( | |
| 288 | - 'value' => '10', | |
| 289 | - 'label' => __( '10 / page', 'subscription' ), | |
| 290 | - ), | |
| 291 | - array( | |
| 292 | - 'value' => '20', | |
| 293 | - 'label' => __( '20 / page', 'subscription' ), | |
| 294 | - ), | |
| 295 | - array( | |
| 296 | - 'value' => '50', | |
| 297 | - 'label' => __( '50 / page', 'subscription' ), | |
| 298 | - ), | |
| 299 | - array( | |
| 300 | - 'value' => '100', | |
| 301 | - 'label' => __( '100 / page', 'subscription' ), | |
| 302 | - ), | |
| 303 | - ), | |
| 307 | + 'name' => 'subscrpt_per_page', | |
| 308 | + 'align' => 'right', | |
| 309 | + 'class' => 'subscrpt-filter-perpage', | |
| 304 | 310 | ) |
| 305 | 311 | ); |
| 306 | 312 | ?> |
| 307 | 313 | </div> |
| @@ -408,8 +414,16 @@ | ||
| 408 | 414 | <?php endif; ?> |
| 409 | 415 | </div> |
| 410 | 416 | <div class="subscrpt-plan-meta"> |
| 411 | 417 | <span class="subscrpt-plan-name"><?php echo $plan_product ? wp_kses_post( $plan_product ) : '—'; ?></span> |
| 418 | + <?php if ( $plan_label ) : ?> | |
| 419 | + <span class="subscrpt-plan-term"> | |
| 420 | + <?php | |
| 421 | + /* translators: %s: plan name */ | |
| 422 | + printf( esc_html__( 'Plan: %s', 'subscription' ), esc_html( $plan_label ) ); | |
| 423 | + ?> | |
| 424 | + </span> | |
| 425 | + <?php endif; ?> | |
| 412 | 426 | <span class="subscrpt-plan-qty"> |
| 413 | 427 | <?php |
| 414 | 428 | /* translators: %s: quantity */ |
| 415 | 429 | printf( esc_html__( 'Quantity: %s', 'subscription' ), $plan_qty ? wp_kses_post( $plan_qty ) : '1' ); |
| @@ -491,9 +505,9 @@ | ||
| 491 | 505 | </div> |
| 492 | 506 | <?php endif; ?> |
| 493 | 507 | |
| 494 | 508 | <!-- Related orders card --> |
| 495 | - <div class="subscrpt-card" data-subscrpt-paginate data-per-page="10" data-date-col="2"> | |
| 509 | + <div class="subscrpt-card" data-subscrpt-paginate data-per-page="10" data-date-col="3"> | |
| 496 | 510 | <div class="subscrpt-card__head subscrpt-card__head--toolbar"> |
| 497 | 511 | <span class="subscrpt-card__title"><?php esc_html_e( 'Related Orders', 'subscription' ); ?></span> |
| 498 | 512 | <?php if ( ! empty( $related_rows ) ) : ?> |
| 499 | 513 | <?php $subscrpt_render_table_tools(); ?> |
| @@ -502,13 +516,13 @@ | ||
| 502 | 516 | <?php if ( ! empty( $related_rows ) ) : ?> |
| 503 | 517 | <table class="wpsubs-table subscrpt-table--compact"> |
| 504 | 518 | <thead> |
| 505 | 519 | <tr> |
| 520 | + <th><?php esc_html_e( '#', 'subscription' ); ?></th> | |
| 506 | 521 | <th><?php esc_html_e( 'Order', 'subscription' ); ?></th> |
| 507 | 522 | <th><?php esc_html_e( 'Type', 'subscription' ); ?></th> |
| 508 | 523 | <th><?php esc_html_e( 'Date', 'subscription' ); ?></th> |
| 509 | 524 | <th><?php esc_html_e( 'Status', 'subscription' ); ?></th> |
| 510 | - <th><?php esc_html_e( 'Items', 'subscription' ); ?></th> | |
| 511 | 525 | <th><?php esc_html_e( 'Payment', 'subscription' ); ?></th> |
| 512 | 526 | <th><?php esc_html_e( 'Total', 'subscription' ); ?></th> |
| 513 | 527 | </tr> |
| 514 | 528 | </thead> |
| @@ -531,17 +545,19 @@ | ||
| 531 | 545 | $related_status = $related_order->get_status(); |
| 532 | 546 | $badge_class = $order_badge_map[ $related_status ] ?? 'draft'; |
| 533 | 547 | ?> |
| 534 | 548 | <tr> |
| 549 | + <td><span class="wpsubs-cell-title"><?php echo esc_html( number_format_i18n( $related['seq'] ) ); ?></span></td> | |
| 535 | 550 | <td> |
| 536 | - <a href="<?php echo esc_url( $related_order->get_edit_order_url() ); ?>" target="_blank" class="wpsubs-cell-title"> | |
| 537 | - #<?php echo esc_html( $related_order->get_order_number() ); ?> | |
| 538 | - </a> | |
| 551 | + <?php | |
| 552 | + // translators: %s: WooCommerce order number. | |
| 553 | + $order_id_label = sprintf( __( 'Order ID: #%s', 'subscription' ), $related_order->get_order_number() ); | |
| 554 | + ?> | |
| 555 | + <a href="<?php echo esc_url( $related_order->get_edit_order_url() ); ?>" target="_blank" class="wpsubs-cell-title" title="<?php echo esc_attr( $order_id_label ); ?>">#<?php echo esc_html( $related_order->get_order_number() ); ?></a> | |
| 539 | 556 | </td> |
| 540 | 557 | <td><?php echo esc_html( $related['label'] ); ?></td> |
| 541 | 558 | <td><?php echo esc_html( $related_order->get_date_created()->date( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ) ) ); ?></td> |
| 542 | 559 | <td><span class="wpsubs-badge wpsubs-badge--<?php echo esc_attr( $badge_class ); ?>"><?php echo esc_html( wc_get_order_status_name( $related_status ) ); ?></span></td> |
| 543 | - <td><?php echo esc_html( number_format_i18n( $related_order->get_item_count() ) ); ?></td> | |
| 544 | 560 | <td><?php echo $related_order->get_payment_method_title() ? esc_html( $related_order->get_payment_method_title() ) : '—'; ?></td> |
| 545 | 561 | <td><?php echo wp_kses_post( $related_order->get_formatted_order_total() ); ?></td> |
| 546 | 562 | </tr> |
| 547 | 563 | <?php endforeach; ?> |
| @@ -546,9 +562,26 @@ | ||
| 546 | 562 | </tr> |
| 547 | 563 | <?php endforeach; ?> |
| 548 | 564 | </tbody> |
| 549 | 565 | </table> |
| 550 | - <div class="subscrpt-pager wpsubs-pagination" hidden></div> | |
| 566 | + <?php | |
| 567 | + // Initial pager; WPSubsPager hydrates and re-derives totals on init. | |
| 568 | + $related_total = count( $related_rows ); | |
| 569 | + wpsubs_render_pager( | |
| 570 | + array( | |
| 571 | + 'current' => 1, | |
| 572 | + 'total' => max( 1, (int) ceil( $related_total / 10 ) ), | |
| 573 | + 'info' => true, | |
| 574 | + 'per_page' => 10, | |
| 575 | + 'item_count' => $related_total, | |
| 576 | + 'link_mode' => 'cb', | |
| 577 | + 'class' => 'subscrpt-pager', | |
| 578 | + // translators: %1$s: first item number, %2$s: last item number, %3$s: total items | |
| 579 | + 'info_format' => __( 'Showing %1$s–%2$s of %3$s related orders', 'subscription' ), | |
| 580 | + 'context' => 'subscription-details-related-orders', | |
| 581 | + ) | |
| 582 | + ); | |
| 583 | + ?> | |
| 551 | 584 | <?php else : ?> |
| 552 | 585 | <div class="subscrpt-card__body"><p class="subscrpt-muted"><?php esc_html_e( 'No related orders found.', 'subscription' ); ?></p></div> |
| 553 | 586 | <?php endif; ?> |
| 554 | 587 | </div> |
| @@ -574,9 +607,26 @@ | ||
| 574 | 607 | */ |
| 575 | 608 | do_action( 'subscrpt_order_activities', $subscription_id ); |
| 576 | 609 | ?> |
| 577 | 610 | </div> |
| 578 | - <div class="subscrpt-pager wpsubs-pagination" hidden></div> | |
| 611 | + <?php | |
| 612 | + // Activities pager. Total pages are unknown at render time (Pro | |
| 613 | + // injects the rows); WPSubsPager recomputes on init via render(). | |
| 614 | + wpsubs_render_pager( | |
| 615 | + array( | |
| 616 | + 'current' => 1, | |
| 617 | + 'total' => 1, | |
| 618 | + 'info' => true, | |
| 619 | + 'per_page' => 10, | |
| 620 | + 'item_count' => 0, | |
| 621 | + 'link_mode' => 'cb', | |
| 622 | + 'class' => 'subscrpt-pager', | |
| 623 | + // translators: %1$s: first item number, %2$s: last item number, %3$s: total items | |
| 624 | + 'info_format' => __( 'Showing %1$s–%2$s of %3$s activities', 'subscription' ), | |
| 625 | + 'context' => 'subscription-details-activities', | |
| 626 | + ) | |
| 627 | + ); | |
| 628 | + ?> | |
| 579 | 629 | <?php else : ?> |
| 580 | 630 | <div class="subscrpt-card__body"> |
| 581 | 631 | <div class="subscrpt-upgrade-banner"> |
| 582 | 632 | <div> |
| @@ -582,9 +632,9 @@ | ||
| 582 | 632 | <div> |
| 583 | 633 | <strong><?php esc_html_e( 'Upgrade to WPSubscription Pro', 'subscription' ); ?></strong> |
| 584 | 634 | <p><?php esc_html_e( 'Track subscription activity history, automation, and more.', 'subscription' ); ?></p> |
| 585 | 635 | </div> |
| 586 | - <a href="https://wpsubscription.co/" target="_blank" class="wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm" rel="noreferrer noopener"> | |
| 636 | + <a href="https://wpsubscription.co/?utm_source=plugin&utm_medium=admin&utm_campaign=upgrade_pro" target="_blank" class="wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm" rel="noreferrer noopener"> | |
| 587 | 637 | <?php esc_html_e( 'Upgrade to Pro', 'subscription' ); ?> |
| 588 | 638 | </a> |
| 589 | 639 | </div> |
| 590 | 640 | </div> |
| @@ -716,12 +766,13 @@ | ||
| 716 | 766 | |
| 717 | 767 | </div> |
| 718 | 768 | |
| 719 | 769 | <style> |
| 720 | -/* Page sits on WP admin gray; the cards are the white surfaces (matches list/health pages). */ | |
| 770 | +/* Page sits on WP admin gray; the cards are the white surfaces (matches list/health pages). | |
| 771 | + No `padding: 0` here — that overrode `.list-page`'s own `0 24px` and ran the | |
| 772 | + whole page flush into the admin menu and the right edge of the window. */ | |
| 721 | 773 | .wp-subscription-admin-content.list-page.subscrpt-subs-details { |
| 722 | 774 | background: transparent; |
| 723 | - padding: 0; | |
| 724 | 775 | border-radius: 0; |
| 725 | 776 | margin-top: 24px; |
| 726 | 777 | margin-bottom: 32px; |
| 727 | 778 | } |
| @@ -779,8 +830,14 @@ | ||
| 779 | 830 | font-size: 13px; |
| 780 | 831 | font-weight: 500; |
| 781 | 832 | color: var(--wpsubs-text-muted); |
| 782 | 833 | } |
| 834 | +.subscrpt-summary__value .subscrpt-summary__was { | |
| 835 | + font-size: 14px; | |
| 836 | + font-weight: 500; | |
| 837 | + color: var(--wpsubs-text-muted); | |
| 838 | + margin-right: 4px; | |
| 839 | +} | |
| 783 | 840 | |
| 784 | 841 | .subscrpt-detail-grid { |
| 785 | 842 | display: grid; |
| 786 | 843 | grid-template-columns: minmax(0, 1fr) 340px; |
| @@ -850,11 +907,10 @@ | ||
| 850 | 907 | padding-top: 0; |
| 851 | 908 | padding-bottom: 0; |
| 852 | 909 | } |
| 853 | 910 | |
| 854 | -/* Pager footer (uses .wpsubs-pagination layout). */ | |
| 855 | -.subscrpt-pager .wpsubs-pagination__info { font-size: 12px; color: var(--wpsubs-text-muted); } | |
| 856 | -.subscrpt-pager .wpsubs-pagination__nav { display: flex; align-items: center; gap: 4px; } | |
| 911 | +/* Pager (uses .wpsubs-pagination layout; styles in admin-components.css). */ | |
| 912 | +.subscrpt-pager { margin: 0; } | |
| 857 | 913 | .subscrpt-empty-row td { color: var(--wpsubs-text-muted); font-size: 13px; } |
| 858 | 914 | |
| 859 | 915 | /* Tables render flush to the card edges (the table thead is the column strip). */ |
| 860 | 916 | .subscrpt-card .wpsubs-table { border: 0; } |
| @@ -948,8 +1004,9 @@ | ||
| 948 | 1004 | .subscrpt-plan-name { font-size: 14px; font-weight: 600; color: var(--wpsubs-text); line-height: 1.3; } |
| 949 | 1005 | .subscrpt-plan-name a { color: var(--wpsubs-text); text-decoration: none; } |
| 950 | 1006 | .subscrpt-plan-name a:hover { color: var(--wpsubs-brand); } |
| 951 | 1007 | .subscrpt-plan-qty { font-size: 13px; color: var(--wpsubs-text-muted); } |
| 1008 | +.subscrpt-plan-term { font-size: 13px; color: var(--wpsubs-text-muted); } | |
| 952 | 1009 | .subscrpt-plan-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; } |
| 953 | 1010 | .subscrpt-plan-label { |
| 954 | 1011 | font-size: 11px; |
| 955 | 1012 | font-weight: 600; |
| @@ -1010,170 +1067,4 @@ | ||
| 1010 | 1067 | } |
| 1011 | 1068 | .subscrpt-upgrade-banner strong { color: var(--wpsubs-text); font-size: 14px; } |
| 1012 | 1069 | .subscrpt-upgrade-banner p { margin: 4px 0 0; font-size: 13px; color: var(--wpsubs-text-muted); } |
| 1013 | 1070 | </style> |
| 1014 | - | |
| 1015 | -<script> | |
| 1016 | -( function () { | |
| 1017 | - 'use strict'; | |
| 1018 | - | |
| 1019 | - var MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; | |
| 1020 | - | |
| 1021 | - // Derive a "YYYY-MM" key from a row's date column. | |
| 1022 | - function monthKey( tr, dateCol ) { | |
| 1023 | - var cell = tr.children[ dateCol ]; | |
| 1024 | - if ( ! cell ) { | |
| 1025 | - return ''; | |
| 1026 | - } | |
| 1027 | - var d = new Date( cell.textContent.replace( ' - ', ' ' ).trim() ); | |
| 1028 | - if ( isNaN( d.getTime() ) ) { | |
| 1029 | - return ''; | |
| 1030 | - } | |
| 1031 | - return d.getFullYear() + '-' + ( '0' + ( d.getMonth() + 1 ) ).slice( -2 ); | |
| 1032 | - } | |
| 1033 | - | |
| 1034 | - function initBox( box ) { | |
| 1035 | - var tools = box.querySelector( '.subscrpt-card__tools' ); | |
| 1036 | - var table = box.querySelector( 'table' ); | |
| 1037 | - var tbody = table ? table.querySelector( 'tbody' ) : null; | |
| 1038 | - var rows = tbody ? Array.prototype.slice.call( tbody.querySelectorAll( 'tr' ) ) : []; | |
| 1039 | - | |
| 1040 | - if ( ! rows.length ) { | |
| 1041 | - if ( tools ) { | |
| 1042 | - tools.style.display = 'none'; | |
| 1043 | - } | |
| 1044 | - return; | |
| 1045 | - } | |
| 1046 | - | |
| 1047 | - var dateCol = box.hasAttribute( 'data-date-col' ) ? parseInt( box.getAttribute( 'data-date-col' ), 10 ) : -1; | |
| 1048 | - var dateAdv = box.querySelector( '.subscrpt-filter-date' ); | |
| 1049 | - var ppAdv = box.querySelector( '.subscrpt-filter-perpage' ); | |
| 1050 | - var pager = box.querySelector( '.subscrpt-pager' ); | |
| 1051 | - var colSpan = ( table.querySelectorAll( 'thead th' ).length ) || 1; | |
| 1052 | - var page = 1; | |
| 1053 | - var emptyRow = null; | |
| 1054 | - | |
| 1055 | - function advValue( adv ) { | |
| 1056 | - var input = adv ? adv.querySelector( 'input[type="hidden"]' ) : null; | |
| 1057 | - return input ? input.value : ''; | |
| 1058 | - } | |
| 1059 | - | |
| 1060 | - var perPage = parseInt( advValue( ppAdv ), 10 ) || parseInt( box.getAttribute( 'data-per-page' ), 10 ) || 10; | |
| 1061 | - | |
| 1062 | - // Inject month options into the date advanced-select (built from the data). | |
| 1063 | - if ( dateAdv && dateCol >= 0 ) { | |
| 1064 | - var menu = dateAdv.querySelector( '.wpsubs-adv-select__menu' ); | |
| 1065 | - var seen = {}; | |
| 1066 | - var months = []; | |
| 1067 | - rows.forEach( function ( tr ) { | |
| 1068 | - var key = monthKey( tr, dateCol ); | |
| 1069 | - if ( key && ! seen[ key ] ) { | |
| 1070 | - seen[ key ] = true; | |
| 1071 | - months.push( key ); | |
| 1072 | - } | |
| 1073 | - } ); | |
| 1074 | - months.sort().reverse().forEach( function ( key ) { | |
| 1075 | - var parts = key.split( '-' ); | |
| 1076 | - var btn = document.createElement( 'button' ); | |
| 1077 | - btn.type = 'button'; | |
| 1078 | - btn.className = 'wpsubs-adv-select__item'; | |
| 1079 | - btn.setAttribute( 'data-value', key ); | |
| 1080 | - btn.setAttribute( 'role', 'option' ); | |
| 1081 | - var span = document.createElement( 'span' ); | |
| 1082 | - span.className = 'wpsubs-adv-select__item-label'; | |
| 1083 | - span.textContent = MONTHS[ parseInt( parts[1], 10 ) - 1 ] + ' ' + parts[0]; | |
| 1084 | - btn.appendChild( span ); | |
| 1085 | - if ( menu ) { | |
| 1086 | - menu.appendChild( btn ); | |
| 1087 | - } | |
| 1088 | - } ); | |
| 1089 | - } | |
| 1090 | - | |
| 1091 | - function filtered() { | |
| 1092 | - var dm = advValue( dateAdv ); | |
| 1093 | - if ( ! dm || dateCol < 0 ) { | |
| 1094 | - return rows; | |
| 1095 | - } | |
| 1096 | - return rows.filter( function ( tr ) { return monthKey( tr, dateCol ) === dm; } ); | |
| 1097 | - } | |
| 1098 | - | |
| 1099 | - function makeBtn( label, target, inert, active, disabled ) { | |
| 1100 | - var el = document.createElement( inert ? 'span' : 'button' ); | |
| 1101 | - el.className = 'wpsubs-pagination__btn' | |
| 1102 | - + ( active ? ' wpsubs-pagination__btn--active' : '' ) | |
| 1103 | - + ( disabled ? ' wpsubs-pagination__btn--disabled' : '' ); | |
| 1104 | - el.innerHTML = label; | |
| 1105 | - if ( ! inert ) { | |
| 1106 | - el.type = 'button'; | |
| 1107 | - el.addEventListener( 'click', function () { page = target; render(); } ); | |
| 1108 | - } | |
| 1109 | - return el; | |
| 1110 | - } | |
| 1111 | - | |
| 1112 | - // Pagination is always shown — a single page renders just "1". | |
| 1113 | - function renderPager( total, pages, start, end ) { | |
| 1114 | - if ( ! pager ) { | |
| 1115 | - return; | |
| 1116 | - } | |
| 1117 | - pager.hidden = false; | |
| 1118 | - pager.innerHTML = ''; | |
| 1119 | - | |
| 1120 | - var info = document.createElement( 'span' ); | |
| 1121 | - info.className = 'wpsubs-pagination__info'; | |
| 1122 | - info.textContent = 'Showing ' + ( total ? start + 1 : 0 ) + '–' + Math.min( end, total ) + ' of ' + total; | |
| 1123 | - pager.appendChild( info ); | |
| 1124 | - | |
| 1125 | - var nav = document.createElement( 'div' ); | |
| 1126 | - nav.className = 'wpsubs-pagination__nav'; | |
| 1127 | - nav.appendChild( makeBtn( '‹', page - 1, page <= 1, false, page <= 1 ) ); | |
| 1128 | - for ( var p = 1; p <= pages; p++ ) { | |
| 1129 | - nav.appendChild( makeBtn( String( p ), p, p === page, p === page, false ) ); | |
| 1130 | - } | |
| 1131 | - nav.appendChild( makeBtn( '›', page + 1, page >= pages, false, page >= pages ) ); | |
| 1132 | - pager.appendChild( nav ); | |
| 1133 | - } | |
| 1134 | - | |
| 1135 | - function render() { | |
| 1136 | - var list = filtered(); | |
| 1137 | - var pages = Math.max( 1, Math.ceil( list.length / perPage ) ); | |
| 1138 | - if ( page > pages ) { | |
| 1139 | - page = pages; | |
| 1140 | - } | |
| 1141 | - var start = ( page - 1 ) * perPage; | |
| 1142 | - var end = start + perPage; | |
| 1143 | - | |
| 1144 | - rows.forEach( function ( tr ) { tr.style.display = 'none'; } ); | |
| 1145 | - list.slice( start, end ).forEach( function ( tr ) { tr.style.display = ''; } ); | |
| 1146 | - | |
| 1147 | - if ( ! list.length ) { | |
| 1148 | - if ( ! emptyRow ) { | |
| 1149 | - emptyRow = document.createElement( 'tr' ); | |
| 1150 | - emptyRow.className = 'subscrpt-empty-row'; | |
| 1151 | - var td = document.createElement( 'td' ); | |
| 1152 | - td.colSpan = colSpan; | |
| 1153 | - td.style.textAlign = 'center'; | |
| 1154 | - td.style.padding = '18px'; | |
| 1155 | - td.textContent = 'No matching records.'; | |
| 1156 | - emptyRow.appendChild( td ); | |
| 1157 | - tbody.appendChild( emptyRow ); | |
| 1158 | - } | |
| 1159 | - emptyRow.style.display = ''; | |
| 1160 | - } else if ( emptyRow ) { | |
| 1161 | - emptyRow.style.display = 'none'; | |
| 1162 | - } | |
| 1163 | - | |
| 1164 | - renderPager( list.length, pages, start, end ); | |
| 1165 | - } | |
| 1166 | - | |
| 1167 | - if ( dateAdv ) { | |
| 1168 | - dateAdv.addEventListener( 'wpsubs:select', function () { page = 1; render(); } ); | |
| 1169 | - } | |
| 1170 | - if ( ppAdv ) { | |
| 1171 | - ppAdv.addEventListener( 'wpsubs:select', function () { perPage = parseInt( advValue( ppAdv ), 10 ) || 10; page = 1; render(); } ); | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | - render(); | |
| 1175 | - } | |
| 1176 | - | |
| 1177 | - document.querySelectorAll( '[data-subscrpt-paginate]' ).forEach( initBox ); | |
| 1178 | -}() ); | |
| 1179 | -</script> | |