From b792e485d560dca82f3694782cb287695e554f9c Mon Sep 17 00:00:00 2001 From: Maggie Date: Thu, 1 May 2014 20:54:52 -0400 Subject: [PATCH] Updated SMS Task Form with crmSelect2 and prepopulated --- CRM/Contact/Form/Task/SMSCommon.php | 6 ++--- CRM/Contact/Page/AJAX.php | 4 ++-- templates/CRM/Contact/Form/Task/SMS.tpl | 30 +++++++++++++++++-------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/Form/Task/SMSCommon.php b/CRM/Contact/Form/Task/SMSCommon.php index 22dff6b61a..76350522b2 100644 --- a/CRM/Contact/Form/Task/SMSCommon.php +++ b/CRM/Contact/Form/Task/SMSCommon.php @@ -106,8 +106,8 @@ class CRM_Contact_Form_Task_SMSCommon { $form->_contactIds = array($cid); } - $to = $form->add('text', 'to', ts('To'), '', TRUE); - $form->add('text', 'activity_subject', ts('Name The SMS'), '', TRUE); + $to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE); + $form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE); $toSetDefault = TRUE; if (property_exists($form, '_context') && $form->_context == 'standalone') { @@ -246,7 +246,7 @@ class CRM_Contact_Form_Task_SMSCommon { if ($phone) { $toArray[] = array( - 'name' => '"' . $value['sort_name'] . '" <' . $phone . '>', + 'text' => '"' . $value['sort_name'] . '" (' . $phone . ')', 'id' => "$contactId::{$phone}", ); } diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 5e35702a1b..610e2b0efd 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -716,7 +716,7 @@ LIMIT {$offset}, {$rowCount} $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { - //working here + //working here $result[] = array( 'text' => '"' . $dao->name . '" <' . $dao->email . '>', 'id' => (CRM_Utils_Array::value('id', $_GET)) ? "{$dao->id}::{$dao->email}" : '"' . $dao->name . '" <' . $dao->email . '>', @@ -788,7 +788,7 @@ LIMIT {$offset}, {$rowCount} while ($dao->fetch()) { $result[] = array( - 'name' => '"' . $dao->name . '" <' . $dao->phone . '>', + 'text' => '"' . $dao->name . '" (' . $dao->phone . ')', 'id' => (CRM_Utils_Array::value('id', $_GET)) ? "{$dao->id}::{$dao->phone}" : '"' . $dao->name . '" <' . $dao->phone . '>', ); } diff --git a/templates/CRM/Contact/Form/Task/SMS.tpl b/templates/CRM/Contact/Form/Task/SMS.tpl index ca92703a43..95ce29b86f 100644 --- a/templates/CRM/Contact/Form/Task/SMS.tpl +++ b/templates/CRM/Contact/Form/Task/SMS.tpl @@ -49,7 +49,7 @@ {if $single eq false}{ts}Recipient(s){/ts}{else}{$form.to.label}{/if} {$form.to.html} -
+
{$form.activity_subject.label} @@ -63,7 +63,7 @@ {$form.template.html} {/if} - + {include file="CRM/Contact/Form/Task/SMSCommon.tpl"} @@ -92,13 +92,25 @@ {/if} {literal} - -var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name or email address of an existing contact.{/ts}{literal}"; -var sourceDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkphone' h=0 }{literal}"; -var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkphone' q='id=1' h=0 }{literal}"; - -cj( "#to" ).tokenInput( toDataUrl, { prePopulate: toContact, theme: 'facebook', hintText: hintText }); -cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' ); +CRM.$(function($){ + var sourceDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkphone' h=0 }{literal}"; + function phoneSelect(el){ + $(el).data('api-entity', 'contact').crmSelect2({ + minimumInputLength: 1, + multiple: true, + ajax: { + url: sourceDataUrl, + data: function(term) { + return { name: term,}; + }, + results: function(response) { + return { results: response }; + } + } + }).select2('data', toContact); + } + phoneSelect('#to'); +}); {/literal} {include file="CRM/common/formNavigate.tpl"} -- 2.25.1