Skip to content

Commit 4821627

Browse files
committed
GH-1397 Disables new voucher generation if invalid code is entered
1 parent 789abbd commit 4821627

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

laterpay/asset_sources/js/laterpay-backend-pricing.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,12 @@
432432

433433
// generate voucher code
434434
$o.timepass.editor
435-
.on('mousedown', $o.generateVoucherCode, function() {
436-
generateVoucherCode($(this).parents($o.timepass.wrapper));
435+
.on('mousedown', $o.generateVoucherCode, function(e) {
436+
if ( $(this).is('[disabled=disabled]') ) {
437+
e.preventDefault();
438+
return false;
439+
}
440+
generateVoucherCode($(this).parents($o.timepass.wrapper));
437441
})
438442
.on('click', $o.generateVoucherCode, function(e) {
439443
e.preventDefault();
@@ -551,8 +555,12 @@
551555

552556
// Generate voucher code.
553557
$o.subscription.editor
554-
.on('mousedown', $o.generateVoucherCode, function() {
555-
generateVoucherCode($(this).parents($o.subscription.wrapper));
558+
.on('mousedown', $o.generateVoucherCode, function(e) {
559+
if ( $(this).is('[disabled=disabled]') ) {
560+
e.preventDefault();
561+
return false;
562+
}
563+
generateVoucherCode($(this).parents($o.subscription.wrapper));
556564
})
557565
.on('click', $o.generateVoucherCode, function(e) {
558566
e.preventDefault();
@@ -750,7 +758,8 @@
750758
return;
751759
}
752760
$($o.subscription.actions.save).removeAttr('disabled');
753-
$($o.subscription.actions.save).attr('href', '#');
761+
$wrapper.find($o.generateVoucherCode).removeAttr('disabled');
762+
$($o.subscription.actions.save).attr('href', 'javascript:void(0);');
754763
} else if ( isGlobal ) {
755764
if (true === voucherExists) {
756765
$wrapper.find('.lp_js_voucher_msg').text(lpVars.i18n.voucherExists);
@@ -760,7 +769,8 @@
760769
return;
761770
}
762771
$o.saveGlobalDefaultPrice.removeAttr('disabled');
763-
$o.saveGlobalDefaultPrice.attr('href', '#');
772+
$wrapper.find($o.generateVoucherCode).removeAttr('disabled');
773+
$o.saveGlobalDefaultPrice.attr('href', 'javascript:void(0);');
764774
} else {
765775
if (true === voucherExists) {
766776
$wrapper.find('.lp_js_voucher_msg').text(lpVars.i18n.voucherExists);
@@ -770,7 +780,8 @@
770780
return;
771781
}
772782
$($o.timepass.actions.save).removeAttr('disabled');
773-
$($o.timepass.actions.save).attr('href', '#');
783+
$wrapper.find($o.generateVoucherCode).removeAttr('disabled');
784+
$($o.timepass.actions.save).attr('href', 'javascript:void(0);');
774785
}
775786

776787
voucherInput.parent().attr('data-code', voucherCode);
@@ -780,6 +791,7 @@
780791
$wrapper.find('.lp_js_voucher_msg').css('display', 'block');
781792
// Disabled save button if there are less than 6 characters. #1397
782793
$wrapper.find('.button-primary').attr('disabled', 'disabled');
794+
$wrapper.find($o.generateVoucherCode).attr('disabled', 'disabled');
783795
return;
784796
}
785797

laterpay/views/backend/pricing.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class="lp_js_priceInput lp_input lp_number-input"
342342
<span class="lp_js_voucher_msg" data-icon="n"><?php esc_html_e( 'This voucher code is already in use, please choose a different name.', 'laterpay' ); ?></span>
343343

344344
<div class="lp_js_voucherPlaceholder"></div>
345-
<a href="#" class="lp_js_generateVoucherCode lp_edit-link lp_add-link lp_single_voucher_button" data-icon="c">
345+
<a href="javascript:void(0);" class="lp_js_generateVoucherCode lp_edit-link lp_add-link lp_single_voucher_button" data-icon="c">
346346
<?php esc_html_e( 'Generate voucher code', 'laterpay' ); ?>
347347
</a>
348348
<span data-icon="n" class="lp_single_voucher_disclaimer"><?php esc_html_e( 'This voucher will provide discounted access to all Articles, even those with a Category Default or Single Article Price.', 'laterpay' ); ?></span>
@@ -624,8 +624,8 @@ class="lp_js_priceInput lp_js_categoryDefaultPriceInput lp_input lp_number-input
624624

625625
<div class="lp_js_timePassEditorContainer lp_time-pass-editor"></div>
626626

627-
<a href="#" class="lp_js_saveTimePass button button-primary lp_mt- lp_mb- lp_hidden"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
628-
<a href="#" class="lp_js_cancelEditingTimePass lp_inline-block lp_pd- lp_hidden"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
627+
<a href="javascript:void(0);" class="lp_js_saveTimePass button button-primary lp_mt- lp_mb- lp_hidden"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
628+
<a href="javascript:void(0);" class="lp_js_cancelEditingTimePass lp_inline-block lp_pd- lp_hidden"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
629629
<a href="#" class="lp_js_editTimePass lp_edit-link--bold lp_rounded--topright lp_inline-block" data-icon="d"></a>
630630
<a href="#" class="lp_js_deleteTimePass lp_edit-link--bold lp_inline-block" data-icon="g"></a>
631631

@@ -778,7 +778,7 @@ class="lp_js_timePassDescriptionTextarea lp_timePass_description-input lp_input
778778
<span class="lp_js_voucher_msg" data-icon="n"><?php printf( '%1$s<br/>%2$s', esc_html__( 'The voucher price must be less than or equal to the ', 'laterpay'), esc_html__( 'time pass price.', 'laterpay' ) ); ?></span>
779779

780780
<div class="lp_js_voucherPlaceholder"></div>
781-
<a href="#" class="lp_js_generateVoucherCode lp_edit-link lp_add-link" data-icon="c">
781+
<a href="javascript:void(0);" class="lp_js_generateVoucherCode lp_edit-link lp_add-link" data-icon="c">
782782
<?php esc_html_e( 'Generate voucher code', 'laterpay' ); ?>
783783
</a>
784784
</div>
@@ -839,8 +839,8 @@ class="lp_js_timePassDescriptionTextarea lp_timePass_description-input lp_input
839839

840840
<div class="lp_js_subscriptionEditorContainer lp_subscription-editor"></div>
841841

842-
<a href="#" class="lp_js_saveSubscription button button-primary lp_mt- lp_mb- lp_hidden"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
843-
<a href="#" class="lp_js_cancelEditingSubscription lp_inline-block lp_pd- lp_hidden"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
842+
<a href="javascript:void(0);" class="lp_js_saveSubscription button button-primary lp_mt- lp_mb- lp_hidden"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
843+
<a href="javascript:void(0);" class="lp_js_cancelEditingSubscription lp_inline-block lp_pd- lp_hidden"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
844844
<a href="#" class="lp_js_editSubscription lp_edit-link--bold lp_rounded--topright lp_inline-block" data-icon="d"></a>
845845
<a href="#" class="lp_js_deleteSubscription lp_edit-link--bold lp_inline-block" data-icon="g"></a>
846846

@@ -977,7 +977,7 @@ class="lp_js_subscriptionDescriptionTextarea lp_subscription_description-input l
977977
<span class="lp_js_voucher_msg" data-icon="n"><?php printf( '%1$s<br/>%2$s', esc_html__( 'The voucher price must be less than or equal to the ', 'laterpay'), esc_html__( 'subscription price.', 'laterpay' ) ); ?></span>
978978

979979
<div class="lp_js_voucherPlaceholder"></div>
980-
<a href="#" class="lp_js_generateVoucherCode lp_edit-link lp_add-link lp_sub_voucher_button" data-icon="c">
980+
<a href="javascript:void(0);" class="lp_js_generateVoucherCode lp_edit-link lp_add-link lp_sub_voucher_button" data-icon="c">
981981
<?php esc_html_e( 'Generate voucher code', 'laterpay' ); ?>
982982
</a>
983983
<span data-icon="n" class="lp_sub_voucher_disclaimer"><?php esc_html_e( 'This will reduce the price for the entirety of the subscription.', 'laterpay' ); ?></span>
@@ -986,8 +986,8 @@ class="lp_js_subscriptionDescriptionTextarea lp_subscription_description-input l
986986
</form>
987987
</div>
988988

989-
<a href="#" class="lp_js_saveSubscription button button-primary lp_mt- lp_mb-"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
990-
<a href="#" class="lp_js_cancelEditingSubscription lp_inline-block lp_pd-"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
989+
<a href="javascript:void(0);" class="lp_js_saveSubscription button button-primary lp_mt- lp_mb-"><?php esc_html_e( 'Save', 'laterpay' ); ?></a>
990+
<a href="javascript:void(0);" class="lp_js_cancelEditingSubscription lp_inline-block lp_pd-"><?php esc_html_e( 'Cancel', 'laterpay' ); ?></a>
991991

992992
<a href="#" class="lp_js_editSubscription lp_edit-link--bold lp_rounded--topright lp_inline-block lp_hidden" data-icon="d"></a><br>
993993
<a href="#" class="lp_js_deleteSubscription lp_edit-link--bold lp_inline-block lp_hidden" data-icon="g"></a>

0 commit comments

Comments
 (0)