From c7e376bf0740298047258fd2ba125de24957de59 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Thu, 2 May 2013 17:26:18 -0700 Subject: [PATCH] CRM-12463, fixed setdefaults for soft credit --- CRM/Contribute/Form/SoftCredit.php | 8 +++----- templates/CRM/Contribute/Form/SoftCredit.js | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 721cd7d7b1..22d653083b 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -52,13 +52,13 @@ class CRM_Contribute_Form_SoftCredit { $item_count = 6; $showSoftCreditRow = 2; - $showCreateNew = true; + $showCreateNew = TRUE; if ($form->_action & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; - $showCreateNew = false; + $showCreateNew = FALSE; } } @@ -80,7 +80,6 @@ class CRM_Contribute_Form_SoftCredit { if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) { $form->assign('pcpLinked', 1); } - $form->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id')); } /** @@ -88,7 +87,7 @@ class CRM_Contribute_Form_SoftCredit { */ static function setDefaultValues(&$defaults, &$form) { if (!empty($form->_softCreditInfo['soft_credit'])) { - foreach($form->_softCreditInfo['soft_credit'] as $key => $value) { + foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) { $defaults["soft_credit_amount[$key]"] = $value['amount']; $defaults["soft_credit_contact_select_id[$key]"] = $value['contact_id']; } @@ -105,7 +104,6 @@ class CRM_Contribute_Form_SoftCredit { $defaults['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo); $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo); } - } } diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js index ae8ac9a9a0..668b007e31 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.js +++ b/templates/CRM/Contribute/Form/SoftCredit.js @@ -24,6 +24,23 @@ cj(function($) { $('#pcp_made_through').autocomplete(pcpURL, { width : 360, selectFirst : false, matchContains: true }).result( function(event, data, formatted) { - cj( "#pcp_made_through_id" ).val( data[1] ); + $("#pcp_made_through_id" ).val( data[1]); }); + + var rowCnt = 1; + $('input[name^="soft_credit_contact_select_id["]').each(function(){ + if ($(this).val()){ + var dataUrl = CRM.url('civicrm/ajax/rest', + 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&id=' + $(this).val()); + $.ajax({ + url : dataUrl, + success : function(html){ + htmlText = html.split( '|' , 2); + $('#soft_credit_contact_' + rowCnt).val(htmlText[0]); + rowCnt++; + } + }); + } + }); + }); -- 2.25.1