From: Kurund Jalmi Date: Thu, 2 May 2013 08:05:40 +0000 (-0700) Subject: more work on CRM-12463, form building js fixes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3572923494faeb7fc106b7175af3c8638445af4c;p=civicrm-core.git more work on CRM-12463, form building js fixes --- diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index 115d1640e8..4cba140363 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -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; diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index d6bd8fd1cd..2cc49b1f38 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -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)) { diff --git a/templates/CRM/Contact/Form/NewContact.tpl b/templates/CRM/Contact/Form/NewContact.tpl index ca5c4d35b3..e799cf05a1 100644 --- a/templates/CRM/Contact/Form/NewContact.tpl +++ b/templates/CRM/Contact/Form/NewContact.tpl @@ -37,7 +37,7 @@ {/if} {else} {$form.$fldName.$blockNo.html} - {if $form.$profSelect} + {if $form.$profSelect and $showNewSelect}   {ts}OR{/ts}  {$form.$profSelect.$blockNo.html}
{/if} {/if} diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index eb8d237158..2030419394 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -31,8 +31,12 @@ {ts}Soft Credit To{/ts} + {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} {$form.soft_credit_amount.$rowNumber.label} {$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}