Fix onBehalf profile for contribution pages CRM-12149
authorColeman Watts <coleman@civicrm.org>
Sun, 31 Mar 2013 03:31:23 +0000 (20:31 -0700)
committerColeman Watts <coleman@civicrm.org>
Sun, 31 Mar 2013 04:00:39 +0000 (21:00 -0700)
The onBehalfOf template seems way more complicated than it needs to be,
but trying to minimize impact for 4.3 so not changing too much.

CRM/Contribute/Form/Contribution/Main.php
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

index 6eb94d59a7b509c91543bbf2cd1ffb5e4d0f25ac..0e002b5ccfee4e018916170051950eb380caa28d 100644 (file)
@@ -101,18 +101,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
 
     $this->_onbehalf = FALSE;
     if (CRM_Utils_Array::value('is_for_organization', $this->_values)) {
-      $urlParams = "&id={$this->_id}&qfKey={$this->controller->_key}";
-      $this->assign('urlParams', $urlParams);
-      $this->_onbehalf = CRM_Utils_Array::value('onbehalf', $_GET);
-
+      $this->_onbehalf = TRUE;
       CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this);
-      if (CRM_Utils_Array::value('hidden_onbehalf_profile', $_POST) &&
-        (CRM_Utils_Array::value('is_for_organization', $_POST) ||
-          CRM_Utils_Array::value('is_for_organization', $this->_values) == 2
-        )
-      ) {
-        CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
-      }
     }
 
     if (CRM_Utils_Array::value('id', $this->_pcpInfo) &&
@@ -388,8 +378,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $this->_onBehalfRequired = 1;
     }
     if ($this->_onbehalf) {
-      $this->assign('onbehalf', TRUE);
-      return CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
+      CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
     }
 
     $this->applyFilter('__ALL__', 'trim');
index 17d67d4bb506f0ad8a37009305baf925eebd5e03..502dcfca8cba90ec757b48c67d45d0ff02d33a37 100644 (file)
@@ -52,9 +52,7 @@
     {/if}
   {/if}
 
-{* Callback snippet: Load on-behalf profile *}
-{elseif $onbehalf and $snippet}
-  {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl}
+{* Main Form *}  
 {else}
   {literal}
   <script type="text/javascript">
   {/if}
 
   {if $is_for_organization}
-  <div id='onBehalfOfOrg' class="crm-section"></div>
-  {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl}
+  <div id='onBehalfOfOrg' class="crm-section">
+    {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl}
+  </div>
   {/if}
 
   {* User account registration option. Displays if enabled for one of the profiles on this page. *}
index b50b698f24e50ec73c98cfe0efe925975de02092..a3aece0358cac10a5ad73ce39c23c0f28414ebf0 100644 (file)
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
 *}
-{* This file provides the HTML for the on-behalf-of form. Can also be used for related contact edit form. *}
+{**
+ * This file provides the HTML for the on-behalf-of form. 
+ * Also used for related contact edit form.
+ * FIXME: This is way more complex than it needs to be
+ * FIXME: About 1% of this javascript is needed for contribution forms
+ * FIXME: Why are we not just using the dynamic form tpl to display this profile?
+ *}
 
 {if $buildOnBehalfForm or $onBehalfRequired}
 <fieldset id="for_organization" class="for_organization-group">
 
 {literal}
 <script type="text/javascript">
-  var reset            = {/literal}"{$reset}"{literal};
-  var onBehalfRequired = {/literal}"{$onBehalfRequired}"{literal};
-  var mainDisplay      = {/literal}"{$mainDisplay}"{literal};
-  var mode             = {/literal}"{$mode}"{literal};
   cj( "div#id-onbehalf-orgname-help").hide( );
 
-  if (mainDisplay) {
-    showOnBehalf(false);
-  }
+  showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
 
   cj( "#mode" ).hide( );
   cj( "#mode" ).attr( 'checked', 'checked' );
-  if ( cj( "#mode" ).attr( 'checked' ) && !reset ) {
+  if ( cj( "#mode" ).attr( 'checked' ) && !{/literal}"{$reset}"{literal} ) {
     $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
     cj( "#createNewOrg" ).text( $text );
     cj( "#mode" ).removeAttr( 'checked' );
 
 function showOnBehalf(onBehalfRequired) {
   if ( cj( "#is_for_organization" ).attr( 'checked' ) || onBehalfRequired ) {
-    cj( "#for_organization" ).html( '' );
-    var urlPath = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&onbehalf=1'}"{literal};
-    urlPath     = urlPath  + {/literal}"{$urlParams}"{literal};
-    if ( mode == 'test' ) {
-      urlPath = urlPath  + '&action=preview';
-    }
-    if ( reset ) {
-      urlPath = urlPath + '&reset=' + reset;
+    var urlPath = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&onbehalf=1'}";
+    urlPath += "{$urlParams}";
+    {if $mode eq 'test'}
+      urlPath += '&action=preview';
+    {/if}
+    {if $reset}
+      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 );
+        }
+      });
     }
-
-    cj.ajax({
-      url     : urlPath,
-      async   : false,
-      global  : false,
-      success : function ( content ) {
-        cj( "#onBehalfOfOrg" ).html( content );
-      }
-    });
   }
   else {
-    cj( "#onBehalfOfOrg" ).html('');
-    cj( "#for_organization" ).html( '' );
-    return;
+    cj("#onBehalfOfOrg").hide();
   }
 }
 
@@ -193,14 +192,13 @@ function resetValues( filter ) {
 
 function createNew( ) {
   if (cj("#mode").attr('checked')) {
-    textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
+    var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
     cj("#onbehalf_organization_name").removeAttr('readonly');
     cj("#mode").removeAttr('checked');
-
     resetValues( false );
   }
   else {
-    textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
+    var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
     cj("#mode").attr('checked', 'checked');
     setOrgName( );
   }