From bee6039a9e7d03a9aa639db45d4098720f90c5fa Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 31 Dec 2014 16:45:33 -0500 Subject: [PATCH] CRM-15495 - Improve entityRef contact_type filter --- CRM/Contact/BAO/Contact.php | 6 ++++++ CRM/Contact/BAO/ContactType.php | 2 +- CRM/Core/Resources.php | 3 +-- js/Common.js | 10 +++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 9a1ef236b9..900ab32e55 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3215,6 +3215,12 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) $params['condition'] = "parent_id = (SELECT id FROM civicrm_contact_type WHERE name='{$props['contact_type']}')"; } break; + case 'contact_type': + if ($context == 'search') { + // CRM-15495 - EntityRef filters expect this format + return CRM_Contact_BAO_ContactType::getSelectElements(); + } + break; } return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); } diff --git a/CRM/Contact/BAO/ContactType.php b/CRM/Contact/BAO/ContactType.php index 5ce037616b..76181fa440 100644 --- a/CRM/Contact/BAO/ContactType.php +++ b/CRM/Contact/BAO/ContactType.php @@ -409,7 +409,7 @@ AND ( p.is_active = 1 OR p.id IS NULL ) while ($dao->fetch()) { if (!empty($dao->parent_id)) { $key = $isSeparator ? $dao->parent_name . $separator . $dao->child_name : $dao->child_name; - $label = "- {$dao->child_label}"; + $label = "- {$dao->child_label}"; $pName = $dao->parent_name; } else { diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index dd81093b4f..ca6d0f003a 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -716,9 +716,8 @@ class CRM_Core_Resources { array('key' => 'status_id', 'value' => ts('Activity Status')), ); - $contactTypes = CRM_Utils_Array::makeNonAssociative(CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, '.')); $filters['contact'] = array( - array('key' => 'contact_type', 'value' => ts('Contact Type'), 'options' => $contactTypes), + array('key' => 'contact_type', 'value' => ts('Contact Type')), array('key' => 'group', 'value' => ts('Group'), 'entity' => 'group_contact'), array('key' => 'tag', 'value' => ts('Tag'), 'entity' => 'entity_tag'), array('key' => 'state_province', 'value' => ts('State/Province'), 'entity' => 'address'), diff --git a/js/Common.js b/js/Common.js index 945be34461..9dc4d20929 100644 --- a/js/Common.js +++ b/js/Common.js @@ -493,9 +493,9 @@ CRM.strings = CRM.strings || {}; filter = $.extend({}, $el.data('user-filter') || {}); if (filter.key && filter.value) { // Special case for contact type/sub-type combo - if (filter.key === 'contact_type' && (filter.value.indexOf('.') > 0)) { - combined.params.contact_type = filter.value.split('.')[0]; - combined.params.contact_sub_type = filter.value.split('.')[1]; + if (filter.key === 'contact_type' && (filter.value.indexOf('__') > 0)) { + combined.params.contact_type = filter.value.split('__')[0]; + combined.params.contact_sub_type = filter.value.split('__')[1]; } else { // Allow json-encoded api filters e.g. {"BETWEEN":[123,456]} combined.params[filter.key] = filter.value.charAt(0) === '{' ? $.parseJSON(filter.value) : filter.value; @@ -556,7 +556,7 @@ CRM.strings = CRM.strings || {}; } else if (this.key == 'contact_type' && typeof params.contact_sub_type === 'undefined') { this.options = _.remove(this.options, function(option) { - return option.key.indexOf(params.contact_type + '.') === 0; + return option.key.indexOf(params.contact_type + '__') === 0; }); result.push(this); } @@ -602,7 +602,7 @@ CRM.strings = CRM.strings || {}; CRM.utils.setOptions($valField, filterSpec.options, false, filter.value); } else { $valField.prop('disabled', true); - CRM.api3(filterSpec.entity || $el.data('api-entity'), 'getoptions', {field: filter.key, sequential: 1}) + CRM.api3(filterSpec.entity || $el.data('api-entity'), 'getoptions', {field: filter.key, context: 'search', sequential: 1}) .done(function(result) { var entity = $el.data('api-entity').toLowerCase(), globalFilterSpec = _.find(CRM.config.entityRef.filters[entity], {key: filter.key}) || {}; -- 2.25.1