From 786d208542b0e8ab8d57d496c8fca6e065d24ebf Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 9 Apr 2018 21:57:43 -0400 Subject: [PATCH] CRM-21100 - Optimize group loading --- ang/crmMailing/BlockPreview.html | 2 +- ang/crmMailing/BlockPreview.js | 51 +++++++++++++++----------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/ang/crmMailing/BlockPreview.html b/ang/crmMailing/BlockPreview.html index d913c5875a..1addd5fb46 100644 --- a/ang/crmMailing/BlockPreview.html +++ b/ang/crmMailing/BlockPreview.html @@ -46,7 +46,7 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
diff --git a/ang/crmMailing/BlockPreview.js b/ang/crmMailing/BlockPreview.js index 659578d147..c2b692462e 100644 --- a/ang/crmMailing/BlockPreview.js +++ b/ang/crmMailing/BlockPreview.js @@ -29,35 +29,32 @@ scope.previewTestGroup = function(e) { var $dialog = $(this); $dialog.html('
').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 = '
    '; - _.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 += '
  1. ' + row.display_name + ' - ' + row.email + '
  2. '; - } - }); - markup += '
'; - markup = '

' + ts('A test message will be sent to %1 people:', {1: count}) + '

' + markup; - if (!count) { - markup = '
' + - (data.count ? ts('None of the contacts in this group have an email address.') : ts('Group is empty.')) + - '
'; + 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 = '
    '; + _.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 += '
  1. ' + row.display_name + ' - ' + row.email + '
  2. '; } - $dialog - .html(markup) - .trigger('crmLoad') - .parent().find('button[data-op=yes]').prop('disabled', !count); }); + markup += '
'; + markup = '

' + ts('A test message will be sent to %1 people:', {1: count}) + '

' + markup; + if (!count) { + markup = '
' + + (data.contact.count ? ts('None of the contacts in this group have an email address.') : ts('Group is empty.')) + + '
'; + } + $dialog + .html(markup) + .trigger('crmLoad') + .parent().find('button[data-op=yes]').prop('disabled', !count); }); }; } -- 2.25.1