From 7801d9b5bc8467b41606d067b5f2afa577eb8709 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 4 Nov 2014 18:57:40 -0800 Subject: [PATCH] CRM-15578 - crmMailing2 - Add dedupe and recipients widgets. Refresh recipients automatically. --- js/angular-crmMailing2.js | 71 ++++++++++++++++++++- partials/crmMailing2/dialog/recipients.html | 24 +++++++ partials/crmMailing2/field/recipients.html | 30 ++++++--- 3 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 partials/crmMailing2/dialog/recipients.html diff --git a/js/angular-crmMailing2.js b/js/angular-crmMailing2.js index 04b9ae1e16..99d5d6dda2 100644 --- a/js/angular-crmMailing2.js +++ b/js/angular-crmMailing2.js @@ -5,6 +5,9 @@ var crmMailing2 = angular.module('crmMailing2', ['ngRoute', 'ui.utils', 'crmUi', 'dialogService']); // TODO ngSanitize, unsavedChanges + // Time to wait before triggering AJAX update to recipients list + var RECIPIENTS_DEBOUNCE_MS = 100; + /** * Initialize a new mailing * TODO Move to separate file or service @@ -24,7 +27,8 @@ from: _.where(CRM.crmMailing.fromAddress, {is_default: "1"})[0].label, replyto_email: "", subject: "", - groups: {include: [], exclude: [4]}, // fixme + dedupe_email: "1", + groups: {include: [2], exclude: [4]}, // fixme mailings: {include: [], exclude: []}, body_html: "", body_text: "", @@ -118,4 +122,69 @@ }; }); + // Controller for the edit-recipients fields ( + // WISHLIST: Move most of this to a (cache-enabled) service + // Scope members: + // - [input] mailing: object + // - [output] recipients: array of recipient records + crmMailing2.controller('EditRecipCtrl', function ($scope, dialogService, crmApi) { + // TODO load & live update real recipients list + $scope.recipients = null; + $scope.getRecipientsEstimate = function () { + var ts = $scope.ts; + if ($scope.recipients == null) + return ts('(Estimating)'); + if ($scope.recipients.length == 0) + return ts('No recipients'); + if ($scope.recipients.length == 1) + return ts('~1 recipient'); + return ts('~%1 recipients', {1: $scope.recipients.length}); + }; + // We monitor four fields -- use debounce so that changes across the + // four fields can settle-down before AJAX. + var refreshRecipients = _.debounce(function () { + $scope.$apply(function () { + $scope.recipients = null; + crmApi('Mailing', 'preview_recipients', $scope.mailing) + .then(function (recipResult) { + $scope.$apply(function () { + $scope.recipients = recipResult.values; + }); + }); + }); + }, RECIPIENTS_DEBOUNCE_MS); + $scope.$watchCollection("mailing.groups.include", refreshRecipients); + $scope.$watchCollection("mailing.groups.exclude", refreshRecipients); + $scope.$watchCollection("mailing.mailings.include", refreshRecipients); + $scope.$watchCollection("mailing.mailings.exclude", refreshRecipients); + + $scope.previewRecipients = function () { + var model = { + recipients: $scope.recipients + }; + var options = { + autoOpen: false, + modal: true, + title: ts('Preview (%1)', { + 1: $scope.getRecipientsEstimate() + }), + }; + dialogService.open('recipDialog', partialUrl('dialog/recipients.html'), model, options) + .then( + function (result) { + // console.log('Closed!'); + }, + function (error) { + // console.log('Cancelled!'); + } + ); + }; + }); + + // Controller for the "Preview Recipients" dialog + // Note: Expects $scope.model to be an object with properties: + // - recipients: array of contacts + crmMailing2.controller('PreviewRecipCtrl', function ($scope) { + $scope.ts = CRM.ts('CiviMail'); + }); })(angular, CRM.$, CRM._); diff --git a/partials/crmMailing2/dialog/recipients.html b/partials/crmMailing2/dialog/recipients.html new file mode 100644 index 0000000000..0e56ada1d1 --- /dev/null +++ b/partials/crmMailing2/dialog/recipients.html @@ -0,0 +1,24 @@ +
+ +

{{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('No recipients')}} +
+ + + + + + + + + + + + + +
{{ts('Name')}}{{ts('Email')}}
{{recipient['api.contact.getvalue']}}{{recipient['api.email.getvalue']}}
+
diff --git a/partials/crmMailing2/field/recipients.html b/partials/crmMailing2/field/recipients.html index 78374240c0..3c3da6d161 100644 --- a/partials/crmMailing2/field/recipients.html +++ b/partials/crmMailing2/field/recipients.html @@ -2,11 +2,25 @@ Controller: EditMailingCtrl Required vars: mailing, crmMailingConst --> - +
+
+ +
+ + +
+
+ + +
\ No newline at end of file -- 2.25.1