From 79d21cce24d53550a9f9e835a88eb40096667e2e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 16 Apr 2015 15:01:58 -0700 Subject: [PATCH] CRM-16277 - crmMailingMgr.previewRecipientCount --- ang/crmMailing/services.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ang/crmMailing/services.js b/ang/crmMailing/services.js index b0503376da..4f2944d19d 100644 --- a/ang/crmMailing/services.js +++ b/ang/crmMailing/services.js @@ -309,6 +309,25 @@ }); }, + 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 -- 2.25.1