Commit 786d2085 authored by colemanw's avatar colemanw

CRM-21100 - Optimize group loading

parent bd1d9e43
......@@ -46,7 +46,7 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
</div>
<div>
<input
crm-entityref="{entity: 'Group', select: {allowClear:true}}"
crm-entityref="{entity: 'Group', api: {params: {is_hidden: 0, is_active: 1}}, select: {allowClear:true, minimumInputLength: 0}}"
ng-model="testGroup.gid"
class="crm-action-menu fa-envelope-o"
/>
......
......@@ -29,35 +29,32 @@
scope.previewTestGroup = function(e) {
var $dialog = $(this);
$dialog.html('<div class="crm-loading-element"></div>').parent().find('button[data-op=yes]').prop('disabled', true);
CRM.api3('group', 'getsingle', {id: scope.testGroup.gid, return: 'title'}).done(function(group) {
$dialog.dialog('option', 'title', ts('Send to %1', {1: group.title}));
CRM.api3('contact', 'get', {
group: scope.testGroup.gid,
options: {limit: 0},
return: 'display_name,email'
}).done(function(data) {
var count = 0,
// Fixme: should this be in a template?
markup = '<ol>';
_.each(data.values, function(row) {
// Fixme: contact api doesn't seem capable of filtering out contacts with no email, so we're doing it client-side
if (row.email) {
count++;
markup += '<li>' + row.display_name + ' - ' + row.email + '</li>';
}
});
markup += '</ol>';
markup = '<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup;
if (!count) {
markup = '<div class="messages status"><i class="crm-i fa-exclamation-triangle"></i> ' +
(data.count ? ts('None of the contacts in this group have an email address.') : ts('Group is empty.')) +
'</div>';
CRM.api3({
contact: ['contact', 'get', {group: scope.testGroup.gid, options: {limit: 0}, return: 'display_name,email'}],
group: ['group', 'getsingle', {id: scope.testGroup.gid, return: 'title'}]
}).done(function(data) {
$dialog.dialog('option', 'title', ts('Send to %1', {1: data.group.title}));
var count = 0,
// Fixme: should this be in a template?
markup = '<ol>';
_.each(data.contact.values, function(row) {
// Fixme: contact api doesn't seem capable of filtering out contacts with no email, so we're doing it client-side
if (row.email) {
count++;
markup += '<li>' + row.display_name + ' - ' + row.email + '</li>';
}
$dialog
.html(markup)
.trigger('crmLoad')
.parent().find('button[data-op=yes]').prop('disabled', !count);
});
markup += '</ol>';
markup = '<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup;
if (!count) {
markup = '<div class="messages status"><i class="crm-i fa-exclamation-triangle"></i> ' +
(data.contact.count ? ts('None of the contacts in this group have an email address.') : ts('Group is empty.')) +
'</div>';
}
$dialog
.html(markup)
.trigger('crmLoad')
.parent().find('button[data-op=yes]').prop('disabled', !count);
});
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment