CRM-17425 Batch entry PCP working at basic level
authorAndrew Hunt <andrew@aghstrategies.com>
Tue, 20 Oct 2015 16:42:59 +0000 (12:42 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Tue, 20 Oct 2015 16:46:26 +0000 (12:46 -0400)
----------------------------------------
* CRM-17425: Allow PCP selection in contribution batch entry
  https://issues.civicrm.org/jira/browse/CRM-17425

CRM/Batch/Form/Entry.php
templates/CRM/Batch/Form/Entry.js
templates/CRM/Batch/Form/Entry.tpl

index 6984c262b4a5f56362d9f1f2413dc573f0deb661..6a09ed9d17013a78f98a2bff12cac82d86cadd5e 100755 (executable)
@@ -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'
index 76de1283bcdb99e1e1b9b95cca778422836677db..50bcb09f75a950b5cddc9e159696adf65abcaeff 100755 (executable)
@@ -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');
index d7585e8d8b39b63d07874ae69159439f4aa0ad8f..e020571d4d45ef1492420cb56b52b869a54c2a9f 100755 (executable)
               {$form.soft_credit_type.$rowNumber.html}
             </div>
           {elseif $n eq 'contribution_soft_credit_pcp_id'}
-            <div>{$form.pcp_made_through_id.$rowNumber.html}{$form.pcp_made_through.$rowNumber.html}</div>
-            <div>{$form.pcp_display_in_roll.$rowNumber.label}&nbsp;{$form.pcp_display_in_roll.$rowNumber.html}</div>
-            <div>{$form.pcp_roll_nickname.$rowNumber.label}&nbsp;{$form.pcp_roll_nickname.$rowNumber.html}</div>
-            <div>{$form.pcp_personal_note.$rowNumber.label}&nbsp;{$form.pcp_personal_note.$rowNumber.html}</div>
+            <div class="compressed crm-grid-cell">
+              <div>{$form.pcp_made_through_id.$rowNumber.html}{$form.pcp_made_through.$rowNumber.html}</div>
+              <div>{$form.pcp_display_in_roll.$rowNumber.label}&nbsp;{$form.pcp_display_in_roll.$rowNumber.html}</div>
+              <div class="pcp_roll_display">{$form.pcp_roll_nickname.$rowNumber.label}&nbsp;{$form.pcp_roll_nickname.$rowNumber.html}</div>
+              <div class="pcp_roll_display">{$form.pcp_personal_note.$rowNumber.label}&nbsp;{$form.pcp_personal_note.$rowNumber.html}</div>
+            </div>
           {elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
             <div class="compressed crm-grid-cell">&nbsp;{$form.field.$rowNumber.$n.html}</div>
           {elseif $n eq 'total_amount'}