Skip to content

Commit

Permalink
dev/core#785: Differentiate smart group from regular group using icon…
Browse files Browse the repository at this point in the history
… in select2 field
  • Loading branch information
monishdeb committed Sep 3, 2019
1 parent 2c55712 commit 59f5ecd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
17 changes: 11 additions & 6 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ public static function getGroupsHierarchy(
$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
";
Expand Down Expand Up @@ -1102,22 +1102,25 @@ public static function getGroupsHierarchy(
'title' => $dao->title,
'visibility' => $dao->visibility,
'description' => $dao->description,
];
'icon' => empty($dao->saved_search_id) ? NULL : 'fa-lightbulb-o',
);
}
else {
$roots[] = [
'id' => $dao->id,
'title' => $dao->title,
'visibility' => $dao->visibility,
'description' => $dao->description,
];
'icon' => empty($dao->saved_search_id) ? NULL : 'fa-lightbulb-o',
);
}
}

$hierarchy = [];
for ($i = 0; $i < count($roots); $i++) {
self::buildGroupHierarchy($hierarchy, $roots[$i], $tree, $titleOnly, $spacer, 0);
}

return $hierarchy;
}

Expand All @@ -1140,11 +1143,13 @@ private static function buildGroupHierarchy(&$hierarchy, $group, $tree, $titleOn
$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.
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contact/Form/Edit/TagsAndGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function buildQuickForm(
}

if ($groupElementType == 'select') {
$groupsOptions[$id] = $group['title'];
$groupsOptions[$id] = $group;
}
else {
$form->_tagGroup[$fName][$id]['description'] = $group['description'];
Expand All @@ -127,8 +127,8 @@ public static function buildQuickForm(
}

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));
}
Expand Down
15 changes: 8 additions & 7 deletions CRM/Contact/Form/Search/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ public function buildQuickForm() {

// add select for groups
// Get hierarchical listing of groups, respecting ACLs for CRM-16836.
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '&nbsp;&nbsp;', TRUE);
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '&nbsp;&nbsp;');
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'])) {
Expand Down
13 changes: 6 additions & 7 deletions ang/crmMailing/Recipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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});
}
Expand Down Expand Up @@ -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':
Expand All @@ -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)) };
}
})
};
Expand Down

0 comments on commit 59f5ecd

Please sign in to comment.