Merge pull request #630 from kurund/CRM-12463-fixes
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.js
CommitLineData
81bc499e
KJ
1// http://civicrm.org/licensing
2cj(function($) {
81bc499e
KJ
3 $('#showPCP, #showSoftCredit').click(function(){
4 return showHideSoftCreditAndPCP();
5 });
6
7 function showHideSoftCreditAndPCP() {
8 $('.crm-contribution-pcp-block').toggle();
9 $('.crm-contribution-pcp-block-link').toggle();
10 $('.crm-contribution-form-block-soft_credit_to').toggle();
11 return false;
12 }
13
65377546
KJ
14 $('#addMoreSoftCredit').click(function(){
15 $('.crm-soft-credit-block tr.hiddenElement :first').show().removeClass('hiddenElement');
16 if ( $('.crm-soft-credit-block tr.hiddenElement').length < 1 ) {
17 $('#addMoreSoftCredit').hide();
18 }
19 return false;
20 });
81bc499e 21
291f6bec
KJ
22 var pcpURL = CRM.url('civicrm/ajax/rest',
23 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
24 $('#pcp_made_through').autocomplete(pcpURL,
25 { width : 360, selectFirst : false, matchContains: true
81bc499e 26 }).result( function(event, data, formatted) {
c7e376bf 27 $("#pcp_made_through_id" ).val( data[1]);
291f6bec 28 });
c7e376bf
KJ
29
30 var rowCnt = 1;
31 $('input[name^="soft_credit_contact_select_id["]').each(function(){
32 if ($(this).val()){
33 var dataUrl = CRM.url('civicrm/ajax/rest',
34 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&id=' + $(this).val());
35 $.ajax({
36 url : dataUrl,
37 success : function(html){
38 htmlText = html.split( '|' , 2);
39 $('#soft_credit_contact_' + rowCnt).val(htmlText[0]);
40 rowCnt++;
41 }
42 });
43 }
44 });
45
291f6bec 46});