From: Coleman Watts Date: Fri, 23 Dec 2016 21:58:56 +0000 (-0500) Subject: CRM-19769 - Add colors to entityRef output X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4fcc98770643f94433aa39cde9b787a9d9a9e9e7;hp=b733747a3397f585160e3ca0b950308ff28188a6;p=civicrm-core.git CRM-19769 - Add colors to entityRef output --- diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 139321abe4..4374d62403 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -266,7 +266,7 @@ class CRM_Admin_Page_AJAX { // query to list mergable tags $query = " -SELECT t1.name, t1.id, t1.used_for, t2.name as parent +SELECT t1.name, t1.id, t1.used_for, t1.color, t2.name as parent FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id WHERE t1.id <> {$fromId} AND @@ -280,6 +280,7 @@ LIMIT $limit"; $row = array( 'id' => $dao->id, 'text' => ($dao->parent ? "{$dao->parent} :: " : '') . $dao->name, + 'color' => isset($dao->color) ? $dao->color : NULL, ); // Add warning about used_for types if (!empty($dao->used_for)) { diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index b9334989ce..1d4cac1dc0 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -88,6 +88,7 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults 'page_num' => 1, 'input' => '', 'image_field' => NULL, + 'color_field' => isset($fields['color']) ? 'color' : NULL, 'id_field' => $entity == 'option_value' ? 'value' : 'id', 'description_field' => array(), 'params' => array(), @@ -149,6 +150,9 @@ function _civicrm_api3_generic_getlist_params(&$request) { if (!empty($request['image_field'])) { $fieldsToReturn[] = $request['image_field']; } + if (!empty($request['color_field'])) { + $fieldsToReturn[] = $request['color_field']; + } if (!empty($request['description_field'])) { $fieldsToReturn = array_merge($fieldsToReturn, (array) $request['description_field']); } @@ -193,6 +197,9 @@ function _civicrm_api3_generic_getlist_output($result, $request, $entity, $field if (!empty($request['image_field'])) { $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : ''; } + if (isset($row[$request['color_field']])) { + $data['color'] = $row[$request['color_field']]; + } $output[] = $data; } } diff --git a/js/Common.js b/js/Common.js index c5685fdd16..346e926f26 100644 --- a/js/Common.js +++ b/js/Common.js @@ -492,9 +492,7 @@ if (!CRM.vars) CRM.vars = {}; }, minimumInputLength: 1, formatResult: CRM.utils.formatSelect2Result, - formatSelection: function(row) { - return _.escape((row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : '')); - }, + formatSelection: formatEntityRefSelection, escapeMarkup: _.identity, initSelection: function($el, callback) { var @@ -828,6 +826,7 @@ if (!CRM.vars) CRM.vars = {}; markup += '
'; } markup += '
' + + (row.color ? ' ' : '') + _.escape((row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : '')) + '
' + '
'; @@ -838,6 +837,11 @@ if (!CRM.vars) CRM.vars = {}; return markup; }; + function formatEntityRefSelection(row) { + return (row.color ? ' ' : '') + + _.escape((row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : '')); + } + function renderEntityRefCreateLinks($el) { var createLinks = $el.data('create-links'),