Skip to content

Commit

Permalink
Merge pull request #10095 from mattwire/membership_force_auto_renew
Browse files Browse the repository at this point in the history
CRM-20375: Show message instead of checkbox when renew required. Hide checkbox w…
  • Loading branch information
eileenmcnaughton authored Apr 5, 2017
2 parents 841720d + c843169 commit d37f296
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
20 changes: 15 additions & 5 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand All @@ -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.'));
}
}

}
Expand Down
8 changes: 7 additions & 1 deletion templates/CRM/Contribute/Form/Contribution/Confirm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@
{if !empty($auto_renew)} {* Auto-renew membership confirmation *}
{crmRegion name="contribution-confirm-recur-membership"}
<br />
<strong>{ts 1=$frequency_interval 2=$frequency_unit}I want this membership to be renewed automatically every %1 %2(s).{/ts}</strong></p>
<strong>
{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}
</strong></p>
<div class="description crm-auto-renew-cancel-info">({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})</div>
{/crmRegion}
{else}
Expand Down
40 changes: 23 additions & 17 deletions templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
</script>
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion templates/CRM/Price/Form/PriceSet.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@
<div id="allow_auto_renew">
<div class='crm-section auto-renew'>
<div class='label'></div>
<div class ='content'>
<div class='content' id="auto_renew">
{if isset($form.auto_renew) }
{$form.auto_renew.html}&nbsp;{$form.auto_renew.label}
{/if}
</div>
<div class='content' id="force_renew" style='display: none'>{ts}Membership will renew automatically.{/ts}</div>
</div>
</div>
{/if}
Expand Down

0 comments on commit d37f296

Please sign in to comment.