From b7714c8061c998d2b62d2569ee2ee797138cb076 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Tue, 20 Oct 2015 12:42:59 -0400 Subject: [PATCH] CRM-17425 Batch entry PCP working at basic level ---------------------------------------- * CRM-17425: Allow PCP selection in contribution batch entry https://issues.civicrm.org/jira/browse/CRM-17425 --- CRM/Batch/Form/Entry.php | 15 ++++++++- templates/CRM/Batch/Form/Entry.js | 49 ++++++++++++++++++++++++++++-- templates/CRM/Batch/Form/Entry.tpl | 10 +++--- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 6984c262b4..6a09ed9d17 100755 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -102,7 +102,6 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } CRM_Core_Resources::singleton() ->addScriptFile('civicrm', 'templates/CRM/Batch/Form/Entry.js', 1, 'html-header') - ->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/PCP.js.tpl', 1, 'html-header') ->addSetting(array('batch' => array('type_id' => $this->_batchInfo['type_id']))) ->addSetting(array('setting' => array('monetaryThousandSeparator' => CRM_Core_Config::singleton()->monetaryThousandSeparator))) ->addSetting(array('setting' => array('monetaryDecimalPoint' => CRM_Core_Config::singleton()->monetaryDecimalPoint))); @@ -307,6 +306,8 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount'); } + // TODO: validate for PCP + //membership type is required for membership batch entry if ($self->_batchInfo['type_id'] == $batchTypes['Membership']) { if (empty($value['membership_type'][1])) { @@ -467,6 +468,18 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } } + // Build PCP params + if (!empty($params['pcp_made_through_id'][$key])) { + $value['pcp']['pcp_made_through_id'] = $params['pcp_made_through_id'][$key]; + $value['pcp']['pcp_display_in_roll'] = !empty($params['pcp_display_in_roll'][$key]); + if (!empty($params['pcp_roll_nickname'][$key])) { + $value['pcp']['pcp_roll_nickname'] = $params['pcp_roll_nickname'][$key]; + } + if (!empty($params['pcp_personal_note'][$key])) { + $value['pcp']['pcp_personal_note'] = $params['pcp_personal_note'][$key]; + } + } + $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, NULL, 'Contribution' diff --git a/templates/CRM/Batch/Form/Entry.js b/templates/CRM/Batch/Form/Entry.js index 76de1283bc..50bcb09f75 100755 --- a/templates/CRM/Batch/Form/Entry.js +++ b/templates/CRM/Batch/Form/Entry.js @@ -31,6 +31,43 @@ CRM.$(function($) { $('#soft_credit_type_'+ rowNum).val($('#sct_default_id').val()); }); + var pcpURL = CRM.url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1'); + $('input[name^="pcp_made_through_id"]').each(function() { + // Figure out the name of the corresponding pcp_made_through[X] field + var thisMadeThroughName = $(this).attr('name').replace('through_id', 'through'); + $(this).crmSelect2({ + minimumInputLength: 1, + ajax: { + url: pcpURL, + data: function(term, page) { + return {term: term, page_num: page}; + }, + results: function(response) { + return response; + } + }, + initSelection: function(el, callback) { + callback({id: $(el).val(), text: $('[name="'+thisMadeThroughName+'"]').val()}); + } + }) + // This is just a cheap trick to store the name when the form reloads + .on('change', function() { + var fieldNameVal = $(this).select2('data'); + if (!fieldNameVal) { + fieldNameVal = ''; + } + $('[name="'+thisMadeThroughName+'"]').val(fieldNameVal.text); + }); + }) + + $('input[name^="pcp_display_in_roll"]').each(function() { + showHidePCPRoll(this); + $(this).change(function() { + showHidePCPRoll(this); + }); + }); + + // validate rows validateRow(); @@ -74,10 +111,18 @@ CRM.$(function($) { //set the focus on first element $('#primary_contact_1').focus(); - }); - +function showHidePCPRoll(elem) { + CRM.$(function($) { + if ($(elem).prop('checked')) { + $(elem).parents('.crm-grid-cell').children('.pcp_roll_display').show(); + } + else { + $(elem).parents('.crm-grid-cell').children('.pcp_roll_display').hide(); + } + }); +} function setPaymentBlock(form, memType) { var rowID = form.closest('div.crm-grid-row').attr('entity_id'); diff --git a/templates/CRM/Batch/Form/Entry.tpl b/templates/CRM/Batch/Form/Entry.tpl index d7585e8d8b..e020571d4d 100755 --- a/templates/CRM/Batch/Form/Entry.tpl +++ b/templates/CRM/Batch/Form/Entry.tpl @@ -102,10 +102,12 @@ {$form.soft_credit_type.$rowNumber.html} {elseif $n eq 'contribution_soft_credit_pcp_id'} -
{$form.pcp_made_through_id.$rowNumber.html}{$form.pcp_made_through.$rowNumber.html}
-
{$form.pcp_display_in_roll.$rowNumber.label} {$form.pcp_display_in_roll.$rowNumber.html}
-
{$form.pcp_roll_nickname.$rowNumber.label} {$form.pcp_roll_nickname.$rowNumber.html}
-
{$form.pcp_personal_note.$rowNumber.label} {$form.pcp_personal_note.$rowNumber.html}
+
+
{$form.pcp_made_through_id.$rowNumber.html}{$form.pcp_made_through.$rowNumber.html}
+
{$form.pcp_display_in_roll.$rowNumber.label} {$form.pcp_display_in_roll.$rowNumber.html}
+
{$form.pcp_roll_nickname.$rowNumber.label} {$form.pcp_roll_nickname.$rowNumber.html}
+
{$form.pcp_personal_note.$rowNumber.label} {$form.pcp_personal_note.$rowNumber.html}
+
{elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
 {$form.field.$rowNumber.$n.html}
{elseif $n eq 'total_amount'} -- 2.25.1