Show message instead of checkbox when renew required. Hide checkbox when renew not...
authorMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 31 Mar 2017 22:45:42 +0000 (23:45 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 31 Mar 2017 22:45:42 +0000 (23:45 +0100)
CRM/Contribute/Form/ContributionBase.php
templates/CRM/Contribute/Form/Contribution/Confirm.tpl
templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl
templates/CRM/Price/Form/PriceSet.tpl

index 9465253007306f95158d13b46f07d9e5e06fcb9e..80644b80636f62823bc7839d942e0da1fcdbf560 100644 (file)
@@ -1194,6 +1194,15 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       $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 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
           $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.'));
+          }
         }
 
       }
index 2067f6a0d70d87bb39fce6dc6796562984ee5193..efb3dc316c8144de3918c8b32d49e983948076f2 100644 (file)
                 {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}
index e6b5fdd3e13d85244831f0f651ca5ece1e272d6c..eee638da885e75627897a791dcb6f0f8a66700ef 100644 (file)
 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>
@@ -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}
index 11b431b0b1b398f41f228ca16a632af5c3cfc4f8..ad741fe9dbc04d2ec218058d6881d7541ac453e1 100644 (file)
                   <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}