CRM-14059 - Contribution form - Fix onbehalf profile ajax load
authorColeman Watts <coleman@civicrm.org>
Mon, 13 Jan 2014 23:31:55 +0000 (15:31 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 13 Jan 2014 23:31:55 +0000 (15:31 -0800)
CRM/Contribute/Form/Contribution/Main.php
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

index 68918da67f3ac9f4b627c5f1845fee03545f5c33..7eb123c9cced41f97b911786866b997879706a71 100644 (file)
@@ -69,9 +69,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     parent::preProcess();
 
     self::preProcessPaymentOptions($this);
-    if ($this->_snippet) {
-      return;
-    }
 
     // Make the contributionPageID avilable to the template
     $this->assign('contributionPageID', $this->_id);
@@ -114,6 +111,11 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
     $this->assign('onBehalfRequired', $this->_onBehalfRequired);
 
+    if ($this->_snippet) {
+      $this->assign('isOnBehalfCallback', CRM_Utils_Array::value('onbehalf', $_GET, FALSE));
+      return;
+    }
+
     if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) {
       $this->assign('intro_text', $this->_pcpInfo['intro_text']);
     }
@@ -346,7 +348,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     // Build payment processor form
-    if ($this->_ppType) {
+    if ($this->_ppType && empty($_GET['onbehalf'])) {
       CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
       // Return if we are in an ajax callback
       if ($this->_snippet) {
@@ -358,6 +360,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
 
     if ($this->_onbehalf) {
       CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
+      // Return if we are in an ajax callback
+      if ($this->_snippet) {
+        return;
+      }
     }
 
     $this->applyFilter('__ALL__', 'trim');
index 84a01fea6d72731da926875198a886a100989843..92cfe826bd982681b6d68e2ff8bd61c1c0946253 100644 (file)
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
 *}
+{* Callback snippet: On-behalf profile *}
+{if $snippet and !empty($isOnBehalfCallback)}
+  {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end"}
 
 {* Callback snippet: Load payment processor *}
-{if $snippet}
+{elseif $snippet}
 {include file="CRM/Core/BillingBlock.tpl" context="front-end"}
   {if $is_monetary}
   {* Put PayPal Express button after customPost block since it's the submit button in this case. *}
 
   {if $is_for_organization}
   <div id='onBehalfOfOrg' class="crm-section">
-    {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl}
+    {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"}
   </div>
   {/if}
 
index 8dbc5d970033305674b2be6ece7cbe2c38ca88a2..b6ec06bf925d6f65fc01e7c3ec07ae100625afc1 100644 (file)
   {/foreach}
 </div>
 <div>{$form.mode.html}</div>
+</fieldset>
 {/if}
-
+{if empty($snippet)}
 {literal}
 <script type="text/javascript">
   cj( "div#id-onbehalf-orgname-help").hide( );
 
 function showOnBehalf(onBehalfRequired) {
   if ( cj( "#is_for_organization" ).attr( 'checked' ) || onBehalfRequired ) {
-    var urlPath = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&onbehalf=1'}";
-    urlPath += "{$urlParams}";
+    var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
     {if $mode eq 'test'}
       urlPath += '&action=preview';
     {/if}
@@ -156,15 +156,8 @@ function showOnBehalf(onBehalfRequired) {
       urlPath += '&reset={$reset}';
     {/if}{literal}
     cj("#onBehalfOfOrg").show();
-    if (cj("#onBehalfOfOrg *").length < 1) {
-      cj.ajax({
-        url     : urlPath,
-        global  : false,
-        async   : false,
-        success : function ( content ) {
-          cj( "#onBehalfOfOrg" ).html( content );
-        }
-      });
+    if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
+      cj('#onBehalfOfOrg').load(urlPath);
     }
   }
   else {
@@ -318,4 +311,4 @@ function selectCreateOrg( orgOption, reset ) {
 {/if}
 
 </script>
-</fieldset>
+{/if}