CRM-19723 - Display activity type icons in ui
authorColeman Watts <coleman@civicrm.org>
Fri, 9 Dec 2016 06:14:57 +0000 (01:14 -0500)
committerColeman Watts <coleman@civicrm.org>
Thu, 15 Dec 2016 18:27:09 +0000 (13:27 -0500)
CRM/Activity/Form/ActivityLinks.php
CRM/Core/OptionValue.php
js/Common.js
templates/CRM/Activity/Form/ActivityLinks.tpl
templates/CRM/Admin/Page/Options.tpl

index f0252ec75da0f458d63d866758c0e02f34380ad3..cddd1bbf3a548969713f7bb7a8bda06ee35dece2 100644 (file)
@@ -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);
   }
index 576227da874e9bcdac165451068ecf9b219dc903..e45a81f43aa15a14793513b4130926ee24a98be0 100644 (file)
@@ -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,
index 0c0dfc4950475bb101e3b841b140a0040eb154d3..38a2a20939d58cb978086703937bc3da6a982b77 100644 (file)
@@ -372,6 +372,11 @@ if (!CRM.vars) CRM.vars = {};
     return settings;
   };
 
+  function formatCrmSelect2(row) {
+    var icon = $(row.element).data('icon');
+    return (icon ? '<i class="crm-i ' + icon + '"></i> ' : '') + _.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('<optgroup label="' + $(this).text() + '" />');
index be77083c8bc2e3d9111b495138af8b7aba8c34fc..ac1f9384ab405d37c04474f4158082d731d38586 100644 (file)
@@ -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) *}
 <select name="other_activity" class="crm-form-select crm-select2 crm-action-menu fa-plus">
   <option value="">{ts}New Activity{/ts}</option>
-{foreach from=$activityTypes key=k item=link}
-  <option value="{$urls.$k}">{$link}</option>
+{foreach from=$activityTypes item=act}
+  <option value="{$act.url}" data-icon="{$act.icon}">{$act.label}</option>
 {/foreach}
 </select>
 {literal}
 {else}
 <ul>
   <li class="crm-activity-tab"><a href="#" data-tab="activity">{ts}Record Activity:{/ts}</a></li>
-{foreach from=$activityTypes key=k item=link}
-<li class="crm-activity-type_{$k}"><a href="{$urls.$k}" data-tab="activity">{$link}</a></li>
+{foreach from=$activityTypes key=k item=act}
+<li class="crm-activity-type_{$k}">
+  <a href="{$act.url}" data-tab="activity">
+    <i class="crm-i {$act.icon}"></i> {$act.label}
+  </a>
+</li>
 {/foreach}
 
 {* add hook links if any *}
index 080c2fde1b0db651c29e477a9e280a462908560c..455baee40c8caa5f5fac6f2d9160b6c63c2ad621 100644 (file)
@@ -75,6 +75,9 @@
         {crmButton p="civicrm/admin/options/$gName" q='action=add&reset=1' class="new-option" icon="plus-circle"}{ts 1=$gLabel}Add %1{/ts}{/crmButton}
     </div>
 {/if}
+{foreach from=$rows item=row}
+  {if !empty($row.icon)}{assign var='hasIcons' value=TRUE}{/if}
+{/foreach}
 <div id={$gName}>
         {strip}
   {* handle enable/disable actions*}
@@ -82,6 +85,9 @@
         <table id="options" class="row-highlight">
          <thead>
          <tr>
+            {if !empty($hasIcons)}
+              <th></th>
+            {/if}
             {if $showComponent}
                 <th>{ts}Component{/ts}</th>
             {/if}
           <tbody>
         {foreach from=$rows item=row}
           <tr id="option_value-{$row.id}" class="crm-admin-options crm-admin-options_{$row.id} crm-entity {cycle values="odd-row,even-row"}{if NOT $row.is_active} disabled{/if}">
+            {if !empty($hasIcons)}
+              <td class="crm-admin-options-icon"><i class="crm-i {$row.icon}"></i></td>
+            {/if}
             {if $showComponent}
               <td class="crm-admin-options-component_name">{$row.component_name}</td>
             {/if}