// 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);
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
if (!$scope.mailing) {
return;
}
- crmMailingMgr.previewRecipients($scope.mailing, RECIPIENTS_PREVIEW_LIMIT).then(function(recipients) {
+ crmMailingMgr.previewRecipientCount($scope.mailing).then(function(recipients) {
$scope.recipients = recipients;
});
});
$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.
<div ng-controller="PreviewRecipCtrl">
<!--
Controller: PreviewRecipCtrl
- Required vars: model.recipients
+ Required vars: model.sample
-->
- <p><em>{{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.')}}</em></p>
- <div ng-show="model.recipients == 0">
+
+ <div class="help">
+ <p>{{ts('Based on current data, approximately %1 contacts will receive a copy of the mailing.', {1: model.count})}}</p>
+
+ <p ng-show="model.sample.length == model.sampleLimit">{{ts('Below is a sample of the first %1 recipients.', {1: model.sampleLimit})}}</p>
+
+ <p>{{ts('If individual contacts are separately modified, added, or removed, then the final list may change.')}}</p>
+ </div>
+
+ <div ng-show="model.sample == 0">
{{ts('No recipients')}}
</div>
- <table ng-show="model.recipients.length > 0">
+ <table ng-show="model.sample.length > 0">
<thead>
<tr>
<th>{{ts('Name')}}</th>
</tr>
</thead>
<tbody>
- <tr ng-repeat="recipient in model.recipients">
+ <tr ng-repeat="recipient in model.sample">
<td>{{recipient['api.contact.getvalue']}}</td>
<td>{{recipient['api.email.getvalue']}}</td>
</tr>