From 2f2e082a47d0b1cc0d0383580f7eb92fc9fb5e1c Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Tue, 26 Dec 2023 18:08:50 -0600 Subject: [PATCH] Update add fields to support multiple uses --- src/js/pricing-table.js | 34 ++++++++++++++++++---------------- src/mt-processing.php | 28 ++++++++++++++-------------- src/mt-ticketing-settings.php | 18 +++++++++--------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/js/pricing-table.js b/src/js/pricing-table.js index 4387292e..e23ab66f 100644 --- a/src/js/pricing-table.js +++ b/src/js/pricing-table.js @@ -1,31 +1,33 @@ jQuery(document).ready(function ($) { - - $('#add_price').on('click', function () { - var num = $('.clonedPrice').length; // how many "duplicatable" input fields we currently have + $('.add-price').on('click', function () { + var context = $( this ).attr( 'data-context' ); + var num = $('.clonedPrice.' + context).length; // how many "duplicatable" input fields we currently have var newNum = new Number(num + 1); // the numeric ID of the new input field being added // create the new element via clone(), and manipulate it's ID using newNum value - var newElem = $('#price' + num).clone().attr('id', 'price' + newNum); + var newElem = $('#price' + context + num).clone().attr('id', 'price' + context + newNum); // manipulate the name/id values of the input inside the new element // insert the new element after the last "duplicatable" input field - $('#price' + num).after(newElem); + $('#price' + context + num).after(newElem); // enable the "remove" button - $('#del_price').removeAttr('disabled'); + $('.del-price.' + context).removeAttr('disabled'); // business rule: you can only add 20 variations - if (newNum == 20) - $('#add_price').attr('disabled', 'disabled'); + if (newNum == 20) { + $( this ).attr('disabled', 'disabled'); + } }); - $('#del_price').on('click', function () { - var num = $('.clonedPrice').length; // how many "duplicatable" input fields we currently have - $('#price' + num).remove(); // remove the last element + $('.del-price').on('click', function () { + var context = $( this ).attr( 'data-context' ); + var num = $('.clonedPrice.' + context).length; // how many "duplicatable" input fields we currently have + $('#price' + context + num).remove(); // remove the last element // enable the "add" button - $('#add_price').removeAttr('disabled'); + $( this ).removeAttr('disabled'); // if only one element remains, disable the "remove" button - if (num - 1 == 1) - $('#del_price').attr('disabled', 'disabled'); - $('#event_span').attr('disabled', 'disabled'); + if (num - 1 == 1) { + $( this ).attr('disabled', 'disabled'); + } }); - $('#del_price').attr('disabled', 'disabled'); + $('.del-price').attr('disabled', 'disabled'); $("button.up,button.down").on( 'click', function(e){ e.preventDefault(); diff --git a/src/mt-processing.php b/src/mt-processing.php index 464d8f0c..55173939 100644 --- a/src/mt-processing.php +++ b/src/mt-processing.php @@ -407,19 +407,19 @@ function mt_prices_table( $registration = array() ) { $total = ''; } else { $disabled = ( 'general' === $counting ) ? ' disabled="disabled"' : ''; - $notice = ( 'general' === $counting ) ? ' ' . __( 'Ticket counting is disabled for general admission events.', 'my-tickets' ) . '' : ''; + $notice = ( 'general' === $counting ) ? ' ' . __( 'Ticket counting is disabled for general admission events.', 'my-tickets' ) . '' : ''; $value = ( isset( $registration['total'] ) && 'inherit' !== $registration['total'] ) ? $registration['total'] : $tickets; - $available_empty = ""; - $total = "

' . $notice . '

'; + $available_empty = ""; + $total = "

' . $notice . '

'; } $labels_index = array(); $pricing = ( isset( $registration['prices'] ) ) ? $registration['prices'] : $registration['pricing']; // array of prices; label => cost/available/sold. if ( is_array( $pricing ) ) { foreach ( $pricing as $label => $options ) { if ( 'discrete' === $counting || 'event' === $counting ) { - $available = ""; + $available = ""; } else { - $available = ""; + $available = ""; } if ( $label ) { $date = ( '' !== $options['label'] ) ? $options['label'] : gmdate( 'Y-m-d' ); @@ -441,8 +441,8 @@ function mt_prices_table( $registration = array() ) { - $label_field$comps - + $label_field$comps + $available " . $sold . ' @@ -465,8 +465,8 @@ function mt_prices_table( $registration = array() ) { -
" . __( 'Note: complimentary tickets can only be added by logged-in administrators.', 'my-tickets' ) . " - +
" . __( 'Note: complimentary tickets can only be added by logged-in administrators.', 'my-tickets' ) . " + $available @@ -474,10 +474,10 @@ function mt_prices_table( $registration = array() ) { } } $return .= " - + - $label_field - + $label_field + $available_empty @@ -487,8 +487,8 @@ function mt_prices_table( $registration = array() ) { $del_field = __( 'Remove last price group', 'my-tickets' ); $return .= '

- - + +

'; return $total . $return; diff --git a/src/mt-ticketing-settings.php b/src/mt-ticketing-settings.php index 250e0ad3..1d1a8819 100644 --- a/src/mt-ticketing-settings.php +++ b/src/mt-ticketing-settings.php @@ -263,25 +263,25 @@ function mt_ticketing_settings() {

- - '/> + + '/>

- - /> + + />

- /> -
- /> - + /> +
+ /> +

- +