CRM-15955 move credit card block to close to the top of the back office contribution...
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 11 Feb 2015 22:20:33 +0000 (11:20 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 11 Feb 2015 22:20:33 +0000 (11:20 +1300)
CRM/Contribute/Form/Contribution.php
templates/CRM/Contribute/Form/Contribution.tpl

index 53d6750d8811ff46422e1be20c7c416f61202953..35ca917350d9e82e23b8e60cce40c63064e4f4fc 100644 (file)
@@ -573,53 +573,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $paneNames[ts('Premium Information')] = 'Premium';
     }
 
+    $billingPanes = array();
     if ($this->_mode) {
       if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE) == TRUE) {
         $buildRecurBlock = TRUE;
         foreach ($this->billingPane as $name => $label) {
           if (!empty($this->billingFieldSets[$name]['fields'])) {
-            //@todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard'
-            $paneNames[$label] = CRM_Utils_String::convertStringToCamel($name);
+            // @todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard'
+            $billingPanes[$label] = $this->generatePane(CRM_Utils_String::convertStringToCamel($name), $defaults);
           }
         }
       }
     }
 
     foreach ($paneNames as $name => $type) {
-      $urlParams = "snippet=4&formType={$type}";
-      if ($this->_mode) {
-        $urlParams .= "&mode={$this->_mode}";
-      }
-
-      $open = 'false';
-      if ($type == 'CreditCard' ||
-        $type == 'DirectDebit'
-      ) {
-        $open = 'true';
-      }
-
-      $allPanes[$name] = array(
-        'url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams),
-        'open' => $open,
-        'id' => $type,
-      );
-
-      // see if we need to include this paneName in the current form
-      if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
-        CRM_Utils_Array::value("hidden_{$type}", $defaults)
-      ) {
-        $showAdditionalInfo = TRUE;
-        $allPanes[$name]['open'] = 'true';
-      }
-
-      if ($type == 'CreditCard' || $type == 'DirectDebit') {
-        //@todo would be good to align tpl name with form name...
-        $this->add('hidden', 'hidden_' . $type, 1);
-      }
-      else {
-        $additionalInfoFormFunction = 'build' . $type;
-        CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this);
-      }
+      $allPanes[$name] = $this->generatePane($type, $defaults);
     }
     if (empty($this->_recurPaymentProcessors)) {
       $buildRecurBlock = FALSE;
@@ -631,8 +599,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     $this->assign('buildRecurBlock', $buildRecurBlock);
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
+    $this->assign('billingPanes', $billingPanes);
     $this->assign('allPanes', $allPanes);
-    $this->assign('showAdditionalInfo', $showAdditionalInfo);
 
     if ($this->_formType) {
       $this->assign('formType', $this->_formType);
@@ -1833,4 +1801,60 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
   }
 
+  /**
+   * Generate the data to construct a snippet based pane.
+   *
+   * This form also assigns the showAdditionalInfo var based on historical code.
+   * This appears to mean 'there is a pane to show'.
+   *
+   * @param string $type
+   *   Type of Pane - this is generally used to determine the function name used to build it
+   *   - e.g CreditCard, AdditionalDetail
+   * @param array $defaults
+   *
+   * @return array
+   *   We aim to further refactor & simplify this but currently
+   *   - the panes array
+   *   - should additional info be shown?
+   */
+  protected function generatePane($type, $defaults) {
+    $urlParams = "snippet=4&formType={$type}";
+    if ($this->_mode) {
+      $urlParams .= "&mode={$this->_mode}";
+    }
+
+    $open = 'false';
+    if ($type == 'CreditCard' ||
+      $type == 'DirectDebit'
+    ) {
+      $open = 'true';
+    }
+
+    $pane = array(
+      'url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams),
+      'open' => $open,
+      'id' => $type,
+    );
+
+    // See if we need to include this paneName in the current form.
+    if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
+      CRM_Utils_Array::value("hidden_{$type}", $defaults)
+    ) {
+      $this->assign('showAdditionalInfo', TRUE);
+      $pane['open'] = 'true';
+    }
+
+    if ($type == 'CreditCard' || $type == 'DirectDebit') {
+      // @todo would be good to align tpl name with form name...
+      // @todo document why this hidden variable is required.
+      $this->add('hidden', 'hidden_' . $type, 1);
+      return $pane;
+    }
+    else {
+      $additionalInfoFormFunction = 'build' . $type;
+      CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this);
+      return $pane;
+    }
+  }
+
 }
index 721a156e00a7fa611eb2d60aeac3b5cbcfdb73b2..f42e0d97414e86a8e2273009e81d23c0abe51d3b 100644 (file)
     {/if}
 
   </table>
+
+  <div class="accordion ui-accordion ui-widget ui-helper-reset">
+    {* Billing Pane is the only billing pane currently *}
+    {foreach from=$billingPanes key=paneName item=paneValue}
+      <div class="crm-accordion-wrapper crm-ajax-accordion crm-{$paneValue.id}-accordion {if $paneValue.open neq 'true'}collapsed{/if}">
+        <div class="crm-accordion-header" id="{$paneValue.id}">
+          {$paneName}
+        </div><!-- /.crm-accordion-header -->
+        <div class="crm-accordion-body">
+          <div class="{$paneValue.id}"></div>
+        </div>
+      </div>
+    {/foreach}
+  </div>
+
     <!-- start of soft credit -->
     <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
       <div class="crm-accordion-header">