From bd1d9e43f9b099cb52dde1b82574c8cee1dec6b3 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 24 Aug 2017 20:15:22 +1000 Subject: [PATCH] CRM-201100 Convert list of test groups into AJAX based select2 like receipients box Switch to entity ref as per coleman --- ang/crmMailing/BlockPreview.html | 11 ++----- ang/crmMailing/BlockPreview.js | 50 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/ang/crmMailing/BlockPreview.html b/ang/crmMailing/BlockPreview.html index 823ea8548d..d913c5875a 100644 --- a/ang/crmMailing/BlockPreview.html +++ b/ang/crmMailing/BlockPreview.html @@ -45,16 +45,11 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
- + />
diff --git a/ang/crmMailing/BlockPreview.js b/ang/crmMailing/BlockPreview.js index 36b72ea981..659578d147 100644 --- a/ang/crmMailing/BlockPreview.js +++ b/ang/crmMailing/BlockPreview.js @@ -29,33 +29,35 @@ scope.previewTestGroup = function(e) { var $dialog = $(this); $dialog.html('
').parent().find('button[data-op=yes]').prop('disabled', true); - $dialog.dialog('option', 'title', ts('Send to %1', {1: _.pluck(_.where(scope.crmMailingConst.testGroupNames, {id: scope.testGroup.gid}), 'title')[0]})); - 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? + 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. '; + _.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 += '
  3. ' + row.display_name + ' - ' + row.email + '
  4. '; + } + }); + 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.')) + + '
'; } + $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.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