From 00c2ff9ee144f2a29af199b6b816584a61424c52 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 9 Dec 2016 01:14:57 -0500 Subject: [PATCH] CRM-19723 - Display activity type icons in ui --- CRM/Activity/Form/ActivityLinks.php | 96 ++++++++----------- CRM/Core/OptionValue.php | 1 + js/Common.js | 11 ++- templates/CRM/Activity/Form/ActivityLinks.tpl | 12 ++- templates/CRM/Admin/Page/Options.tpl | 9 ++ 5 files changed, 70 insertions(+), 59 deletions(-) diff --git a/CRM/Activity/Form/ActivityLinks.php b/CRM/Activity/Form/ActivityLinks.php index f0252ec75d..cddd1bbf3a 100644 --- a/CRM/Activity/Form/ActivityLinks.php +++ b/CRM/Activity/Form/ActivityLinks.php @@ -49,69 +49,57 @@ class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form { } $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype="; - $activityTypes = $urls = array(); + $allTypes = CRM_Utils_Array::value('values', civicrm_api3('OptionValue', 'get', array( + 'option_group_id' => 'activity_type', + 'is_active' => 1, + 'options' => array('limit' => 0, 'sort' => 'weight'), + ))); - $emailTypeId = CRM_Core_OptionGroup::getValue('activity_type', - 'Email', - 'name' - ); + $activityTypes = array(); - $letterTypeId = CRM_Core_OptionGroup::getValue('activity_type', - 'Print PDF Letter', - 'name' - ); - $SMSId = CRM_Core_OptionGroup::getValue('activity_type', - 'Text Message (SMS)', - 'label' - ); - - if (CRM_Utils_Mail::validOutBoundMail() && $contactId) { - list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId); - if (!$doNotEmail && $email && !$isDeseased) { - $activityTypes = array($emailTypeId => ts('Send an Email')); - } - } - - if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) { - // Check for existence of a mobile phone and ! do not SMS privacy setting - $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name'); - list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID); - - if (!$doNotSMS && $phone) { - $sendSMS = array($SMSId => ts('Send SMS')); - $activityTypes += $sendSMS; - } - } - // this returns activity types sorted by weight - $otherTypes = CRM_Core_PseudoConstant::activityType(FALSE); - - $activityTypes += $otherTypes; - - foreach (array_keys($activityTypes) as $typeId) { - if ($typeId == $emailTypeId) { - $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add', - "{$urlParams}{$typeId}", FALSE, NULL, FALSE - ); + foreach ($allTypes as $id => $act) { + $url = 'civicrm/activity/add'; + if ($act['name'] == 'Email') { + if (!CRM_Utils_Mail::validOutBoundMail() || !$contactId) { + continue; + } + list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId); + if (!$doNotEmail && $email && !$isDeseased) { + $url = 'civicrm/activity/email/add'; + $act['label'] = ts('Send an Email'); + } + else { + continue; + } } - elseif ($typeId == $SMSId) { - $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add', - "{$urlParams}{$typeId}", FALSE, NULL, FALSE - ); + elseif ($act['name'] == 'SMS') { + if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount()) { + continue; + } + // Check for existence of a mobile phone and ! do not SMS privacy setting + $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name'); + list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID); + if (!$doNotSMS && $phone) { + $url = 'civicrm/activity/sms/add'; + } + else { + continue; + } } - elseif ($typeId == $letterTypeId) { - $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add', - "{$urlParams}{$typeId}", FALSE, NULL, FALSE - ); + elseif ($act['name'] == 'Print PDF Letter') { + $url = 'civicrm/activity/pdf/add'; } - else { - $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add', - "{$urlParams}{$typeId}", FALSE, NULL, FALSE - ); + elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) { + continue; } + $act['url'] = CRM_Utils_System::url($url, + "{$urlParams}{$id}", FALSE, NULL, FALSE + ); + $act += array('icon' => 'fa-plus-square-o'); + $activityTypes[$act['value']] = $act; } $self->assign('activityTypes', $activityTypes); - $self->assign('urls', $urls); $self->assign('suppressForm', TRUE); } diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index 576227da87..e45a81f43a 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -148,6 +148,7 @@ class CRM_Core_OptionValue { $optionValue[$dao->id]['label'] = htmlspecialchars($optionValue[$dao->id]['label']); $optionValue[$dao->id]['order'] = $optionValue[$dao->id]['weight']; + $optionValue[$dao->id]['icon'] = CRM_Utils_Array::value('icon', $optionValue[$dao->id], ''); $optionValue[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array( 'id' => $dao->id, diff --git a/js/Common.js b/js/Common.js index 0c0dfc4950..38a2a20939 100644 --- a/js/Common.js +++ b/js/Common.js @@ -372,6 +372,11 @@ if (!CRM.vars) CRM.vars = {}; return settings; }; + function formatCrmSelect2(row) { + var icon = $(row.element).data('icon'); + return (icon ? ' ' : '') + _.escape(row.text); + } + /** * Wrapper for select2 initialization function; supplies defaults * @param options object @@ -388,7 +393,11 @@ if (!CRM.vars) CRM.vars = {}; var $el = $(this), iconClass, - settings = {allowClear: !$el.hasClass('required')}; + settings = { + allowClear: !$el.hasClass('required'), + formatResult: formatCrmSelect2, + formatSelection: formatCrmSelect2 + }; // quickform doesn't support optgroups so here's a hack :( $('option[value^=crm_optgroup]', this).each(function () { $(this).nextUntil('option[value^=crm_optgroup]').wrapAll(''); diff --git a/templates/CRM/Activity/Form/ActivityLinks.tpl b/templates/CRM/Activity/Form/ActivityLinks.tpl index be77083c8b..ac1f9384ab 100644 --- a/templates/CRM/Activity/Form/ActivityLinks.tpl +++ b/templates/CRM/Activity/Form/ActivityLinks.tpl @@ -32,8 +32,8 @@ {if $as_select} {* on 3.2, the activities can be either a drop down select (on the activity tab) or a list (on the action menu) *} {literal} @@ -56,8 +56,12 @@ {else}