CRM-12463, fixed setdefaults for soft credit
authorKurund Jalmi <kurund@civicrm.org>
Fri, 3 May 2013 00:26:18 +0000 (17:26 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Fri, 3 May 2013 00:26:18 +0000 (17:26 -0700)
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contribute/Form/SoftCredit.js

index 721cd7d7b11e4cdea3e345cee41db9d42ed93a4a..22d653083be687c1514fd80bdcf500436fadffa6 100644 (file)
@@ -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);
     }
-
   }
 }
 
index ae8ac9a9a0525a4eab6bf20e328db2ab5db7e1e1..668b007e3146a9fdc36c6e4f1c8df7d42f82bbd5 100644 (file)
@@ -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++;
+        }
+      });
+    }
+  });
+
 });