From 8c80f3f9e9d6726f4ff060cf4c16d76d8a975450 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 30 Nov 2015 14:42:03 +1300 Subject: [PATCH] CRM-17635 show option to email for autorenew memberships --- CRM/Member/Form.php | 6 +- CRM/Member/Form/Membership.php | 8 +-- templates/CRM/Member/Form/Membership.tpl | 89 +++++++++--------------- 3 files changed, 39 insertions(+), 64 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index ca06acb5c5..14a47c9830 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -160,7 +160,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE, - array('onChange' => "buildAutoRenew( null, this.value );") + array('onChange' => "buildAutoRenew( null, this.value, '{$this->_mode}');") ); CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE); } @@ -181,9 +181,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { $this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors)); $this->addElement('checkbox', 'auto_renew', - ts('Membership renewed automatically'), - NULL, - array('onclick' => "buildReceiptANDNotice( );") + ts('Membership renewed automatically') ); $this->assignPaymentRelatedVariables(); diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 825bced3e8..dc43808739 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -563,7 +563,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { ); if (!empty($this->_recurPaymentProcessors)) { - $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . 'buildAutoRenew(this.value, null);'; + $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . "buildAutoRenew(this.value, null, '{$this->_mode}');"; } $this->add('text', 'max_related', ts('Max related'), @@ -681,7 +681,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, - array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio', false);") + array('onclick' => "showEmailOptions()") ); $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); @@ -718,8 +718,8 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->assign('isRecur', $isRecur); $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this); - - $this->assign('outBound_option', Civi::settings()->get('mailing_backend')); + $mailingInfo = Civi::settings()->get('mailing_backend'); + $this->assign('isEmailEnabledForSite', ($mailingInfo['outBound_option'] != 2)); parent::buildQuickForm(); } diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index f577373959..178993f02c 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -174,12 +174,12 @@ {/if} {include file="CRM/Member/Form/MembershipCommon.tpl"} - {if $emailExists and $outBound_option != 2} + {if $emailExists and $isEmailEnabledForSite} {$form.send_receipt.label}{$form.send_receipt.html}
{ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1 ?{/ts} {ts}OR if the payment is from a different contact, this email will only go to them.{/ts} - {elseif $context eq 'standalone' and $outBound_option != 2} + {elseif $context eq 'standalone' and $isEmailEnabledForSite} {$form.send_receipt.label}{$form.send_receipt.html}
{ts}Automatically email a membership confirmation and receipt to {/ts}? {ts}OR if the payment is from a different contact, this email will only go to them.{/ts} @@ -377,35 +377,36 @@ } } - - {/literal} + function showEmailOptions() { + {/literal} + // @todo emailExists refers to the primary contact for the page. + // elsewhere some script determines if there is a paying contact the + // email should go to instead (e.g gift membership). This should be checked for here + // and that merged into that code as currently behaviour is inconsistent. + var emailExists = '{$emailExists}'; + var isStandalone = ('{$context}' == 'standalone'); + var isEmailEnabledForSite = {$isEmailEnabledForSite}; - {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' } - {include file="CRM/common/showHideByFieldValue.tpl" - trigger_field_id ="send_receipt" - trigger_value ="" - target_element_id ="notice" - target_element_type ="table-row" - field_type ="radio" - invert = 0 - } - {include file="CRM/common/showHideByFieldValue.tpl" - trigger_field_id ="send_receipt" - trigger_value ="" - target_element_id ="fromEmail" - target_element_type ="table-row" - field_type ="radio" - invert = 0 - } - {/if} - {literal} + {literal} + var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone)); + if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) { + // Hide extra message and from email for recurring as they cannot be stored until use. + cj('#notice').show(); + cj('#fromEmail').show(); + } + else { + cj('#notice').hide(); + cj('#fromEmail').hide(); + } + } +