From c843169cd2a563bb91944df92657b2e81d0010b3 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 31 Mar 2017 23:45:42 +0100 Subject: [PATCH] Show message instead of checkbox when renew required. Hide checkbox when renew not allowed. On confirmation page change message depending if user selected auto-renew or it was mandatory --- CRM/Contribute/Form/ContributionBase.php | 20 +++++++--- .../Contribute/Form/Contribution/Confirm.tpl | 8 +++- .../Form/Contribution/MembershipBlock.tpl | 40 +++++++++++-------- templates/CRM/Price/Form/PriceSet.tpl | 3 +- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 946525300730..80644b80636f 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1194,6 +1194,15 @@ protected function buildMembershipBlock( $takeUserSubmittedAutoRenew = (!empty($_POST) || $this->isSubmitted()) ? TRUE : FALSE; $this->assign('takeUserSubmittedAutoRenew', $takeUserSubmittedAutoRenew); + // Assign autorenew option (0:hide,1:optional,2:required) so we can use it in confirmation etc. + $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId); + if (isset($membershipTypeValues[$selectedMembershipTypeID]['auto_renew'])) { + $this->assign('autoRenewOption', $membershipTypeValues[$selectedMembershipTypeID]['auto_renew']); + } + else { + $this->assign('autoRenewOption', $autoRenewOption); + } + if ($isContributionMainPage) { if (!$membershipPriceset) { if (!$this->_membershipBlock['is_required']) { @@ -1213,13 +1222,14 @@ protected function buildMembershipBlock( $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); } - else { - $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId); - $this->assign('autoRenewOption', $autoRenewOption); - } if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { - $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); + if ($autoRenewOption == 2) { + $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); + } + else { + $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); + } } } diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 2067f6a0d70d..efb3dc316c81 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -90,7 +90,13 @@ {if !empty($auto_renew)} {* Auto-renew membership confirmation *} {crmRegion name="contribution-confirm-recur-membership"}
- {ts 1=$frequency_interval 2=$frequency_unit}I want this membership to be renewed automatically every %1 %2(s).{/ts}

+ + {if $autoRenewOption == 1} + {ts 1=$frequency_interval 2=$frequency_unit}I want this membership to be renewed automatically every %1 %2(s).{/ts} + {elseif $autoRenewOption == 2} + {ts 1=$frequency_interval 2=$frequency_unit}This membership will be renewed automatically every %1 %2(s).{/ts} + {/if} +

({ts}Your initial membership fee will be processed once you complete the confirmation step. You will be able to cancel the auto-renewal option by visiting the web page link that will be included in your receipt.{/ts})
{/crmRegion} {else} diff --git a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl index e6b5fdd3e13d..eee638da885e 100644 --- a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl @@ -84,14 +84,17 @@ CRM.$(function($) { //if price set is set we use below below code to show for showing auto renew var autoRenewOption = {/literal}'{$autoRenewOption}'{literal}; - $('#allow_auto_renew').hide(); + var autoRenew = $("#auto_renew"); + var forceRenew = $("#force_renew"); + autoRenew.hide(); + forceRenew.hide(); if ( autoRenewOption == 1 ) { - $('#allow_auto_renew').show(); + autoRenew.show(); } else if ( autoRenewOption == 2 ) { - var autoRenew = $("#auto_renew"); autoRenew.prop('checked', true ); autoRenew.attr( 'readonly', true ); - $('#allow_auto_renew').show(); + autoRenew.hide(); + forceRenew.show(); } }); @@ -245,39 +248,42 @@ function showHideAutoRenew( memTypeId ) if ( !memTypeId && singleMembership ) memTypeId = cj("input:radio[name="+priceSetName+"]").attr('membership-type'); var renewOptions = {/literal}{$autoRenewMembershipTypeOptions}{literal}; var currentOption = eval( "renewOptions." + 'autoRenewMembershipType_' + memTypeId ); + var autoRenew = cj('#auto_renew'); + var autoRenewC = cj('input[name="auto_renew"]'); + var forceRenew = cj("#force_renew"); - funName = 'hide();'; var readOnly = false; var isChecked = false; + if ( currentOption == 0 ) { + isChecked = false; + forceRenew.hide(); + autoRenew.hide(); + } if ( currentOption == 1 ) { - funName = 'show();'; + forceRenew.hide(); + autoRenew.show(); //uncomment me, if we'd like //to load auto_renew checked. //isChecked = true; - } else if ( currentOption == 2 || currentOption == 4) { - funName = 'show();'; + autoRenew.hide(); + forceRenew.show(); isChecked = readOnly = true; } - var autoRenew = cj("#auto_renew"); if ( considerUserInput ) isChecked = autoRenew.prop('checked' ); //its a normal recur contribution. if ( cj( "is_recur" ) && ( cj( 'input:radio[name="is_recur"]:checked').val() == 1 ) ) { isChecked = false; - funName = 'hide();'; + autoRenew.hide(); + forceRenew.hide(); } - //when we do show auto_renew read only - //which implies it should be checked. - if ( readOnly && funName == 'show();' ) isChecked = true; - - autoRenew.attr( 'readonly', readOnly ); - autoRenew.prop('checked', isChecked ); - eval( "cj('#allow_auto_renew')." + funName ); + autoRenewC.attr( 'readonly', readOnly ); + autoRenewC.prop('checked', isChecked ); } {/literal}{if $allowAutoRenewMembership}{literal} diff --git a/templates/CRM/Price/Form/PriceSet.tpl b/templates/CRM/Price/Form/PriceSet.tpl index 11b431b0b1b3..ad741fe9dbc0 100644 --- a/templates/CRM/Price/Form/PriceSet.tpl +++ b/templates/CRM/Price/Form/PriceSet.tpl @@ -107,11 +107,12 @@
-
+
{if isset($form.auto_renew) } {$form.auto_renew.html} {$form.auto_renew.label} {/if}
+
{/if}