CRM-16277 - EditRecipCtrl - Separate AJAX calls for preview by count and by name
authorTim Otten <totten@civicrm.org>
Thu, 16 Apr 2015 23:13:55 +0000 (16:13 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 17 Apr 2015 00:35:57 +0000 (17:35 -0700)
ang/crmMailing/EditRecipCtrl.js
ang/crmMailing/PreviewRecipCtrl.html

index e42d9cdcf4fe3be17c541a4ef738bb4229fd2802..84a0a37ce0610b0cb667b172ed013da8c27a06d7 100644 (file)
@@ -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);
 
       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;
         });
       });
     $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.
index 0e56ada1d11461e8df152a3978a50dda204fd23b..6eb6459aa1c4fb29cb78cd99230e35b087db3719 100644 (file)
@@ -1,13 +1,21 @@
 <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>
@@ -15,7 +23,7 @@
       </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>