more work on CRM-12463, form building js fixes
authorKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 08:05:40 +0000 (01:05 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 08:05:40 +0000 (01:05 -0700)
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contact/Form/NewContact.tpl
templates/CRM/Contribute/Form/SoftCredit.tpl

index 115d1640e839e15da681154c88f19e13b7a47738..4cba140363769292914c1a83464037cdb432a909 100644 (file)
@@ -160,15 +160,20 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $cs->find();
 
     if ($cs->N > 0) {
+      $count = 1;
       while ($cs->fetch()) {
         if ($all) {
           foreach ($pcpFields as $val) {
             $softContribution['pcp'][$val] = $cs->$val;
           }
         }
-        $softContribution['soft_credit'][$cs->id]['soft_credit_to'] = $cs->contact_id;
-        $softContribution['soft_credit'][$cs->id]['soft_credit_id'] = $cs->id;
-        $softContribution['soft_credit'][$cs->id]['soft_credit_amount'] = $cs->amount;
+
+        $softContribution['soft_credit'][$count] = array(
+          'soft_credit_to' => $cs->contact_id,
+          'soft_credit_id' => $cs->id,
+          'soft_credit_amount' => $cs->amount,
+        );
+        $count++;
       }
     }
     return $softContribution;
index d6bd8fd1cd93f195b0d8f975125def4f3637bb3b..2cc49b1f38cd560bc485f98f842d0b2fd23f67d7 100644 (file)
@@ -51,14 +51,16 @@ class CRM_Contribute_Form_SoftCredit {
     // by default generate 5 blocks
     $item_count = 6;
 
+    $showSoftCreditRow = 2;
+    $showCreateNew = true;
     if ($form->_action & CRM_Core_Action::UPDATE) {
       $csParams = array('contribution_id' => $form->_id);
       $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
-      $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
-      $showSoftCreditRow++;
-    }
-    else {
-      $showSoftCreditRow = 2;
+      if (!empty($form->_softCreditInfo['soft_credit'])) {
+        $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
+        $showSoftCreditRow++;
+        $showCreateNew = false;
+      }
     }
 
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
@@ -68,6 +70,7 @@ class CRM_Contribute_Form_SoftCredit {
 
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
+    $form->assign('showCreateNew', $showCreateNew);
 
     // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page
     if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) {
@@ -81,8 +84,14 @@ class CRM_Contribute_Form_SoftCredit {
    */
   static function setDefaultValues(&$defaults, &$form) {
 
-    //crm_core_error::debug('$form->_softCreditInfo', $form->_softCreditInfo);
-    //exit;
+//    crm_core_error::debug('$form->_softCreditInfo', $form->_softCreditInfo);
+//    exit;
+
+    if (!empty($form->_softCreditInfo['soft_credit'])) {
+      foreach($form->_softCreditInfo['soft_credit'] as $key => $value) {
+        $defaults["soft_credit_amount[$key]"] = $value['soft_credit_amount'];
+      }
+    }
 
     /*
     if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
index ca5c4d35b3bbefdb9ac0791f337dc9644f0f7c77..e799cf05a154f896604e28eb0b2b951e8586ffc1 100644 (file)
@@ -37,7 +37,7 @@
         {/if}
       {else}
         {$form.$fldName.$blockNo.html}
-        {if $form.$profSelect}
+        {if $form.$profSelect and $showNewSelect}
           &nbsp;&nbsp;{ts}OR{/ts}&nbsp;&nbsp;{$form.$profSelect.$blockNo.html}<div id="contact-dialog-{$prefix}{$blockNo}" class="hiddenElement"></div>
         {/if}
       {/if}
index eb8d237158c337059709919f255da930fa0ea308..203041939406612584c35e9d1722b0413080068f 100644 (file)
   <tr id="soft-credit-row-{$rowNumber}" class="crm-contribution-form-block-soft_credit_to {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
     <td class="label">{ts}Soft Credit To{/ts}</td>
     <td>
+      {assign var='createNewStatus' value=true}
+      {if !$showCreateNew and $rowNumber lt $showSoftCreditRow}
+        {assign var='createNewStatus' value=false}
+      {/if}
       {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber
-      prefix="soft_credit_"}
+      prefix="soft_credit_" showNewSelect=$createNewStatus}
     </td>
          <td>
                  {$form.soft_credit_amount.$rowNumber.label}&nbsp;{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}