From 956b9960e80f68f0c057dc2c248d93089e83e110 Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Fri, 8 Mar 2019 16:41:37 +0530 Subject: [PATCH] dev/core#785: Differentiate smart group from regular group using icon in select2 field --- CRM/Contact/BAO/Group.php | 17 +++++++++++------ CRM/Contact/Form/Edit/TagsAndGroups.php | 6 +++--- CRM/Contact/Form/Search/Basic.php | 15 ++++++++------- ang/crmMailing/Recipients.js | 13 ++++++------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index ec214b8142..567ca95a81 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -1052,7 +1052,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $groups = []; $args = [1 => [$groupIdString, 'String']]; $query = " -SELECT id, title, description, visibility, parents +SELECT id, title, description, visibility, parents, saved_search_id FROM civicrm_group WHERE id IN $groupIdString "; @@ -1081,7 +1081,8 @@ WHERE id IN $groupIdString 'title' => $dao->title, 'visibility' => $dao->visibility, 'description' => $dao->description, - ]; + 'icon' => empty($dao->saved_search_id) ? NULL : 'fa-lightbulb-o', + ); } else { $roots[] = [ @@ -1089,7 +1090,8 @@ WHERE id IN $groupIdString 'title' => $dao->title, 'visibility' => $dao->visibility, 'description' => $dao->description, - ]; + 'icon' => empty($dao->saved_search_id) ? NULL : 'fa-lightbulb-o', + ); } } @@ -1097,6 +1099,7 @@ WHERE id IN $groupIdString for ($i = 0; $i < count($roots); $i++) { self::buildGroupHierarchy($hierarchy, $roots[$i], $tree, $titleOnly, $spacer, 0); } + return $hierarchy; } @@ -1119,11 +1122,13 @@ WHERE id IN $groupIdString $hierarchy[$group['id']] = $spaces . $group['title']; } else { - $hierarchy[$group['id']] = [ - 'title' => $spaces . $group['title'], + $hierarchy[] = array( + 'id' => $group['id'], + 'text' => $spaces . $group['title'], 'description' => $group['description'], 'visibility' => $group['visibility'], - ]; + 'icon' => $group['icon'], + ); } // For performance reasons we use a for loop rather than a foreach. diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index c7d2692715..b4a82118df 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -102,7 +102,7 @@ class CRM_Contact_Form_Edit_TagsAndGroups { } if ($groupElementType == 'select') { - $groupsOptions[$id] = $group['title']; + $groupsOptions[$id] = $group; } else { $form->_tagGroup[$fName][$id]['description'] = $group['description']; @@ -111,8 +111,8 @@ class CRM_Contact_Form_Edit_TagsAndGroups { } if ($groupElementType == 'select' && !empty($groupsOptions)) { - $form->add('select', $fName, $groupName, $groupsOptions, FALSE, - ['id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2 twenty'] + $form->add('select2', $fName, $groupName, $groupsOptions, FALSE, + ['placeholder' => '- select -', 'multiple' => TRUE, 'class' => 'twenty'] ); $form->assign('groupCount', count($groupsOptions)); } diff --git a/CRM/Contact/Form/Search/Basic.php b/CRM/Contact/Form/Search/Basic.php index 1b6ae423fa..976e03dcce 100644 --- a/CRM/Contact/Form/Search/Basic.php +++ b/CRM/Contact/Form/Search/Basic.php @@ -49,14 +49,15 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search { // add select for groups // Get hierarchical listing of groups, respecting ACLs for CRM-16836. - $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '  ', TRUE); + $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '  '); if (!empty($searchOptions['groups'])) { - $this->addField('group', [ - 'entity' => 'group_contact', - 'label' => ts('in'), - 'placeholder' => ts('- any group -'), - 'options' => $groupHierarchy, - ]); + $this->addField('group', array[ + 'entity' => 'group_contact', + 'label' => ts('in'), + 'placeholder' => ts('- any group -'), + 'options' => $groupHierarchy, + 'type' => 'Select2', + ]); } if (!empty($searchOptions['tags'])) { diff --git a/ang/crmMailing/Recipients.js b/ang/crmMailing/Recipients.js index 0d39cde49e..6ff799f6a5 100644 --- a/ang/crmMailing/Recipients.js +++ b/ang/crmMailing/Recipients.js @@ -94,7 +94,7 @@ return item.text; } var option = convertValueToObj(item.id); - var icon = (option.entity_type === 'civicrm_mailing') ? 'fa-envelope' : 'fa-users'; + var icon = (option.entity_type === 'civicrm_mailing') ? 'fa-envelope' : item.is_smart ? 'fa-lightbulb-o' : 'fa-users'; var spanClass = (option.mode == 'exclude') ? 'crmMailing-exclude' : 'crmMailing-include'; if (option.entity_type != 'civicrm_mailing' && isMandatory(option.entity_id)) { spanClass = 'crmMailing-mandatory'; @@ -154,7 +154,7 @@ mids.push(0); } - CRM.api3('Group', 'getlist', { params: { id: { IN: gids }, options: { limit: 0 } }, extra: ["is_hidden"] } ).then( + CRM.api3('Group', 'getlist', { params: { id: { IN: gids }, options: { limit: 0 } }, extra: ["is_hidden"] }).then( function(glist) { CRM.api3('Mailing', 'getlist', { params: { id: { IN: mids }, options: { limit: 0 } } }).then( function(mlist) { @@ -165,8 +165,8 @@ $(glist.values).each(function (idx, group) { var key = group.id + ' civicrm_group include'; - groupNames.push({id: parseInt(group.id), title: group.label, is_hidden: group.extra.is_hidden}); + groupNames.push({id: parseInt(group.id), title: group.label, is_hidden: group.extra.is_hidden}); if (values.indexOf(key) >= 0) { datamap.push({id: key, text: group.label}); } @@ -239,7 +239,7 @@ transport: function(params) { switch(rcpAjaxState.entity) { case 'civicrm_group': - CRM.api3('Group', 'getlist', params.data).then(params.success, params.error); + CRM.api3('Group', 'get', params.data).then(params.success, params.error); break; case 'civicrm_mailing': @@ -255,9 +255,8 @@ return obj["api.MailingRecipients.getcount"] > 0 ? { id: obj.id + ' ' + rcpAjaxState.entity + ' ' + rcpAjaxState.type, text: obj.label } : ''; } - else { - return { id: obj.id + ' ' + rcpAjaxState.entity + ' ' + rcpAjaxState.type, - text: obj.label }; + else if (obj.is_hidden == 0) { + return { id: obj.id + ' ' + rcpAjaxState.entity + ' ' + rcpAjaxState.type, text: obj.title, is_smart: (!_.isEmpty(obj.saved_search_id)) }; } }) }; -- 2.25.1