CRM-16645 - More consistently use PCP autocomplete field
authorColeman Watts <coleman@civicrm.org>
Sat, 13 Jun 2015 17:48:23 +0000 (13:48 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 13 Jun 2015 18:43:51 +0000 (14:43 -0400)
CRM/Contribute/BAO/Query.php
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/PCP.js.tpl [new file with mode: 0644]
templates/CRM/Contribute/Form/Search/Common.tpl
templates/CRM/Contribute/Form/SoftCredit.tpl

index 9bee323ed93557395e576810bc4b5d9f26996e27..ca5c26abe2d153bdaf044348a3e6862696b72fc0 100644 (file)
@@ -877,16 +877,10 @@ class CRM_Contribute_BAO_Query {
       array('entity' => 'contribution', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -'))
     );
 
-    $form->add('select', 'contribution_pcp_made_through_id',
-      ts('Personal Campaign Page'),
-      array(
-        '' => ts('- any -'),
-      ) +
-      CRM_Contribute_PseudoConstant::pcPage(),
-      FALSE, array('class' => 'crm-select2')
-    );
-
-    $status = array();
+    // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
+    $form->add('text', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('class' => 'twenty', 'id' => 'pcp_made_through_id', 'placeholder' => ts('- any -')));
+    // stores the label
+    $form->add('hidden', 'pcp_made_through');
 
     $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status');
     // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
index eee9ffce6e93ccfa24bab51dd15969e54c5ee26a..fc482dd4e3a3b7924cd67f481210f35fd5a45b60 100644 (file)
@@ -145,8 +145,10 @@ class CRM_Contribute_Form_SoftCredit {
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
       $form->assign('siteHasPCPs', 1);
-      $form->add('hidden', 'pcp_made_through'); // stores the label
-      $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty'));
+      // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
+      $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
+      // stores the label
+      $form->add('hidden', 'pcp_made_through');
       $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
       $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
       $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
index 9a4e34a5bbeb15bf465717fb568f9e42935e9d73..09231b05300eb234ab882a3be8a87c126f1b3a52 100644 (file)
               <td class="label">{$form.pcp_made_through_id.label}</td>
               <td>
                 {$form.pcp_made_through_id.html} &nbsp;
-                <span class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</span>
+                <div class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</div>
 
                 <div class="spacer"></div>
                  <div class="crm-contribution-form-block-pcp_details">
                     <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
                       <td class="label">{$form.pcp_roll_nickname.label}</td>
                       <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
-                        <span class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</span>
+                        <div class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</div>
                       </td>
                     </tr>
                     <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
                       <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
                       <td>
                         {$form.pcp_personal_note.html}
-                        <span
-                          class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</span>
+                        <div
+                          class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</div>
                       </td>
                     </tr>
                   </table>
           </table>
         </div>
       </div>
+      {include file="CRM/Contribute/Form/PCP.js.tpl"}
     {/if}
     <!-- end of PCP -->
 
diff --git a/templates/CRM/Contribute/Form/PCP.js.tpl b/templates/CRM/Contribute/Form/PCP.js.tpl
new file mode 100644 (file)
index 0000000..846cc19
--- /dev/null
@@ -0,0 +1,54 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{literal}
+<script type="text/javascript">
+  CRM.$(function($) {
+    var $form = $("form.{/literal}{$form.formClass}{literal}");
+
+    // FIXME: This could be much simpler as an entityRef field but pcp doesn't have a searchable api :(
+    var pcpURL = CRM.url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
+    $('#pcp_made_through_id').crmSelect2({
+      minimumInputLength: 1,
+      ajax: {
+        url: pcpURL,
+        data: function(term, page) {
+          return {term: term, page: page};
+        },
+        results: function(response) {
+          return response;
+        }
+      },
+      initSelection: function(el, callback) {
+        callback({id: $(el).val(), text: $('[name=pcp_made_through]', $form).val()});
+      }
+    })
+      // This is just a cheap trick to store the name when the form reloads
+      .on('change', function() {
+        $('[name=pcp_made_through]', $form).val($(this).select2('data').text || '');
+      });
+  });
+</script>
+{/literal}
index 9e55106e759da74c6855e4b47c27b472f6f28df2..59702b860bc1a03d33dbcbb5cd3bd852e571cf3c 100644 (file)
 <tr>
   <td>
     {$form.contribution_pcp_made_through_id.label} <br />
-    {$form.contribution_pcp_made_through_id.html|crmAddClass:twenty}
+    {$form.contribution_pcp_made_through_id.html}
+    {include file="CRM/Contribute/Form/PCP.js.tpl"}
   </td>
   <td>
     {$form.contribution_pcp_display_in_roll.label}
index 9d30c5d0a560118d3e4a706af0eefb1fec4c058c..a1780524e82adc8a0ff9d6c65c3d4d5b82845d12 100644 (file)
       return false;
     });
 
-    // FIXME: This could be much simpler as an entityRef field but pcp doesn't have a searchable api :(
-    var pcpURL = CRM.url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
-    $('#pcp_made_through_id').crmSelect2({
-      placeholder: {/literal}'{ts escape="js"}- select -{/ts}'{literal},
-      minimumInputLength: 1,
-      ajax: {
-        url: pcpURL,
-        data: function(term, page) {
-          return {term: term, page: page};
-        },
-        results: function(response) {
-          return response;
-        }
-      },
-      initSelection: function(el, callback) {
-        callback({id: $(el).val(), text: $('[name=pcp_made_through]', $form).val()});
-      }
-    })
-      // This is just a cheap trick to store the name in case of a formrule error
-      .on('change', function() {
-        $('[name=pcp_made_through]', $form).val($(this).select2('data').text || '');
-      });
-
     $('.crm-soft-credit-block tr span').each(function () {
       if ($(this).hasClass('crm-error')) {
         $(this).parents('tr').show();