CRM-16555 - Cleanup billing block js
authorColeman Watts <coleman@civicrm.org>
Thu, 4 Jun 2015 02:56:57 +0000 (22:56 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 4 Jun 2015 02:56:57 +0000 (22:56 -0400)
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Financial/Form/Payment.php
templates/CRM/Core/BillingBlock.js
templates/CRM/common/paymentBlock.tpl

index e6fea0842e528d8671c231947ea55eec6e04dd99..18e11131a85d1aa8cdf022d36896ac0e8673231f 100644 (file)
@@ -312,6 +312,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
 
     // Set title
     if ($this->_mode) {
+      CRM_Financial_Form_Payment::addCreditCardJs();
       $this->setPageTitle($this->_ppID ? ts('Credit Card Pledge Payment') : ts('Credit Card Contribution'));
     }
     else {
index 52dc3f6adc6b86a5f1d57831b5ea4f6855f2306b..2350155c52504a9a03b9439a73050a43e98d2066 100644 (file)
@@ -1419,15 +1419,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
           break;
         }
       }
-      if (!$form->_snippet) {
-        // Add JS to show icons for the accepted credit cards
-        $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames();
-        CRM_Core_Resources::singleton()
-          ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)
-          // workaround for CRM-13634
-          // ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
-          ->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
-      }
+      CRM_Financial_Form_Payment::addCreditCardJs();
     }
     $form->assign('paymentProcessorID', $form->_paymentProcessorID);
   }
index 9d8ad34e6a34b3a7c23534c9745b2c53c497f753..56ad9e158a887679d731f479ea1df1830536ae93 100644 (file)
@@ -54,20 +54,25 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form {
     //$payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0;
     // $this->assign('payPalExpressId', $payPalExpressId);
 
-    // Add JS to show icons for the accepted credit cards
+    self::addCreditCardJs();
 
+    $this->assign('paymentProcessorID', $this->_paymentProcessorID);
+  }
+
+  public function buildQuickForm() {
+    CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
+  }
+
+  /**
+   * Add JS to show icons for the accepted credit cards
+   */
+  public static function addCreditCardJs() {
     $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames();
     CRM_Core_Resources::singleton()
       ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)
       // workaround for CRM-13634
       // ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
       ->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
-
-    $this->assign('paymentProcessorID', $this->_paymentProcessorID);
-  }
-
-  public function buildQuickForm() {
-    CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
   }
 
 }
index dec4b6581fc3a1ebbfd3b889ca95d7ef004b5ffe..bc06b0a4575d179e4e1321b21d84450e28bc9349 100644 (file)
@@ -76,7 +76,4 @@
 
   civicrm_billingblock_creditcard_helper();
 
-  $(function() {
-    $('#billing-payment-block').on('crmFormLoad', civicrm_billingblock_creditcard_helper);
-  });
 })(CRM.$);
index 54016083e4ae7851d4fc2ae92ddf24722f04d4d7..7ee0301ed332ed5e96b8a46781a4c420a06f1f8e 100644 (file)
 {literal}
 <script type="text/javascript">
 
-function buildPaymentBlock(type) {
-  {/literal}{if !$isBillingAddressRequiredForPayLater}{literal}
-  if (type == 0) {
-    if (cj("#billing-payment-block").length) {
-      cj("#billing-payment-block").html('');
+  CRM.$(function($) {
+    function buildPaymentBlock(type) {
+      {/literal}{if !$isBillingAddressRequiredForPayLater}{literal}
+      if (type == 0) {
+        $("#billing-payment-block").html('');
+        return;
+      }
+      {/literal}{/if}
+
+      {if $contributionPageID}
+        {capture assign='contributionPageID'}id={$contributionPageID}&{/capture}
+      {else}
+        {capture assign='contributionPageID'}{/capture}
+      {/if}
+      {if $urlPathVar}
+        {capture assign='urlPathVar'}{$urlPathVar}&{/capture}
+      {else}
+        {capture assign='urlPathVar'}{/capture}
+      {/if}
+
+      var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="`$urlPathVar``$contributionPageID`processor_id="}" + type;
+
+      {literal}
+      CRM.loadPage(dataUrl, {target: '#billing-payment-block'});
     }
-    return;
-  }
-  {/literal}{/if}{literal}
-
-  var dataUrl = {/literal}"{crmURL p='civicrm/payment/form' h=0 q='snippet=4&processor_id='}"{literal} + type;
-
-  {/literal}
-    {if $urlPathVar}
-      dataUrl = dataUrl + '&' + '{$urlPathVar}'
-    {/if}
-
-    {if $contributionPageID}
-            dataUrl = dataUrl + '&id=' + '{$contributionPageID}'
-        {/if}
-
-  {literal}
-
-  var response = cj.ajax({
-                        url: dataUrl,
-                        async: false
-                        }).responseText;
-
-  cj('#billing-payment-block').html(response).trigger('crmLoad').trigger('crmFormLoad');
-}
-
-CRM.$(function($) {
+  
     $('.crm-group.payment_options-group').show();
-    // FIXME: This code is getting re-loaded and re-run every time, using .off() as a temporary fix
-    $('[name=payment_processor_id]').off('.paymentBlock').on('change.paymentBlock', function() {
-        buildPaymentBlock( $(this).val() );
+    $('[name=payment_processor_id]').on('change.paymentBlock', function() {
+        buildPaymentBlock($(this).val());
     });
-});
+  });
 
 </script>
 {/literal}