CRM-16277 - crmMailingMgr.previewRecipientCount
authorTim Otten <totten@civicrm.org>
Thu, 16 Apr 2015 22:01:58 +0000 (15:01 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 17 Apr 2015 00:35:57 +0000 (17:35 -0700)
ang/crmMailing/services.js

index b0503376dad12ec7b93e6888e5b6db18c45dd570..4f2944d19d5fcb195ad88f27663a365cadf8eee3 100644 (file)
         });
       },
 
+      previewRecipientCount: function previewRecipientCount(mailing) {
+        // To get list of recipients, we tentatively save the mailing and
+        // get the resulting recipients -- then rollback any changes.
+        var params = angular.extend({}, mailing, mailing.recipients, {
+          name: 'placeholder', // for previewing recipients on new, incomplete mailing
+          subject: 'placeholder', // for previewing recipients on new, incomplete mailing
+          options: {force_rollback: 1},
+          'api.mailing_job.create': 1, // note: exact match to API default
+          'api.MailingRecipients.getcount': {
+            mailing_id: '$value.id'
+          }
+        });
+        delete params.recipients; // the content was merged in
+        return qApi('Mailing', 'create', params).then(function (recipResult) {
+          // changes rolled back, so we don't care about updating mailing
+          return recipResult.values[recipResult.id]['api.MailingRecipients.getcount'];
+        });
+      },
+
       // Save a (draft) mailing
       // @param mailing Object (per APIv3)
       // @return Promise