From a670e04e87df25e9f78bb412b1aed741a73aa8a1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 16 Apr 2015 16:13:55 -0700 Subject: [PATCH] CRM-16277 - EditRecipCtrl - Separate AJAX calls for preview by count and by name --- ang/crmMailing/EditRecipCtrl.js | 41 ++++++++++++++-------------- ang/crmMailing/PreviewRecipCtrl.html | 18 ++++++++---- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/ang/crmMailing/EditRecipCtrl.js b/ang/crmMailing/EditRecipCtrl.js index e42d9cdcf4..84a0a37ce0 100644 --- a/ang/crmMailing/EditRecipCtrl.js +++ b/ang/crmMailing/EditRecipCtrl.js @@ -5,10 +5,10 @@ // Scope members: // - [input] mailing: object // - [output] recipients: array of recipient records - angular.module('crmMailing').controller('EditRecipCtrl', function EditRecipCtrl($scope, dialogService, crmApi, crmMailingMgr, $q, crmMetadata) { + angular.module('crmMailing').controller('EditRecipCtrl', function EditRecipCtrl($scope, dialogService, crmApi, crmMailingMgr, $q, crmMetadata, crmStatus) { // Time to wait before triggering AJAX update to recipients list var RECIPIENTS_DEBOUNCE_MS = 100; - var RECIPIENTS_PREVIEW_LIMIT = 10000; + var RECIPIENTS_PREVIEW_LIMIT = 50; var ts = $scope.ts = CRM.ts(null); @@ -23,16 +23,13 @@ if ($scope.recipients === null) { return ts('(Estimating)'); } - if ($scope.recipients.length === 0) { + if ($scope.recipients === 0) { return ts('No recipients'); } - if ($scope.recipients.length === 1) { + if ($scope.recipients === 1) { return ts('~1 recipient'); } - if (RECIPIENTS_PREVIEW_LIMIT > 0 && $scope.recipients.length >= RECIPIENTS_PREVIEW_LIMIT) { - return ts('>%1 recipients', {1: RECIPIENTS_PREVIEW_LIMIT}); - } - return ts('~%1 recipients', {1: $scope.recipients.length}); + return ts('~%1 recipients', {1: CRM.sigfig($scope.recipients, 2)}); }; // We monitor four fields -- use debounce so that changes across the @@ -43,7 +40,7 @@ if (!$scope.mailing) { return; } - crmMailingMgr.previewRecipients($scope.mailing, RECIPIENTS_PREVIEW_LIMIT).then(function(recipients) { + crmMailingMgr.previewRecipientCount($scope.mailing).then(function(recipients) { $scope.recipients = recipients; }); }); @@ -54,17 +51,21 @@ $scope.$watchCollection("mailing.recipients.mailings.exclude", refreshRecipients); $scope.previewRecipients = function previewRecipients() { - var model = { - recipients: $scope.recipients - }; - var options = CRM.utils.adjustDialogDefaults({ - width: '40%', - autoOpen: false, - title: ts('Preview (%1)', { - 1: $scope.getRecipientsEstimate() - }) - }); - dialogService.open('recipDialog', '~/crmMailing/PreviewRecipCtrl.html', model, options); + return crmStatus({start: ts('Previewing...'), success: ''}, crmMailingMgr.previewRecipients($scope.mailing, RECIPIENTS_PREVIEW_LIMIT).then(function(recipients) { + var model = { + count: $scope.recipients, + sample: recipients, + sampleLimit: RECIPIENTS_PREVIEW_LIMIT + }; + var options = CRM.utils.adjustDialogDefaults({ + width: '40%', + autoOpen: false, + title: ts('Preview (%1)', { + 1: $scope.getRecipientsEstimate() + }) + }); + dialogService.open('recipDialog', '~/crmMailing/PreviewRecipCtrl.html', model, options); + })); }; // Open a dialog for editing the advanced recipient options. diff --git a/ang/crmMailing/PreviewRecipCtrl.html b/ang/crmMailing/PreviewRecipCtrl.html index 0e56ada1d1..6eb6459aa1 100644 --- a/ang/crmMailing/PreviewRecipCtrl.html +++ b/ang/crmMailing/PreviewRecipCtrl.html @@ -1,13 +1,21 @@
-

{{ts('Based on current data, the following contacts will receive a copy of the mailing. If contacts are added or removed from the target groups, then the final list may change.')}}

-
+ +
+

{{ts('Based on current data, approximately %1 contacts will receive a copy of the mailing.', {1: model.count})}}

+ +

{{ts('Below is a sample of the first %1 recipients.', {1: model.sampleLimit})}}

+ +

{{ts('If individual contacts are separately modified, added, or removed, then the final list may change.')}}

+
+ +
{{ts('No recipients')}}
- +
@@ -15,7 +23,7 @@ - + -- 2.25.1
{{ts('Name')}}
{{recipient['api.contact.getvalue']}} {{recipient['api.email.getvalue']}}