From 05752ee500b987652b8a968ef6e2447b769599b0 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 13 Oct 2017 01:42:28 +0530 Subject: [PATCH] additional fixes --- CRM/Admin/Form/Preferences/Mailing.php | 6 ++++++ ang/crmMailing.css | 10 ---------- ang/crmMailing/BlockRecipients.html | 10 +++------- ang/crmMailing/EditRecipCtrl.js | 26 ++++++++++++++++++++------ settings/Mailing.setting.php | 13 +++++++++++++ 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Mailing.php b/CRM/Admin/Form/Preferences/Mailing.php index 2b8af0a29a..1abfbc26c7 100644 --- a/CRM/Admin/Form/Preferences/Mailing.php +++ b/CRM/Admin/Form/Preferences/Mailing.php @@ -108,6 +108,12 @@ class CRM_Admin_Form_Preferences_Mailing extends CRM_Admin_Form_Preferences { 'weight' => 11, 'description' => 'If enabled, a randomized hash key will be used to reference the mailing URL in the mailing.viewUrl token, instead of the mailing ID', ), + 'auto_recipient_rebuild' => array( + 'html_type' => 'checkbox', + 'title' => ts('Enable automatic CiviMail recipient count display'), + 'weight' => 12, + 'description' => 'Enable this setting to rebuild recipient list automatically during composing mail. Disable will allow you to rebuild recipient manually.', + ), ), ); diff --git a/ang/crmMailing.css b/ang/crmMailing.css index 3c39b69312..b853cb4466 100644 --- a/ang/crmMailing.css +++ b/ang/crmMailing.css @@ -111,13 +111,3 @@ input[name=preview_test_email]:-ms-input-placeholder { margin: 0.5em; color: red; } - -.crmMailing-outdated-count { - color: red; - font-weight: bold; -} - -.crmMailing-latest-count { - color: green; - font-weight: bold; -} diff --git a/ang/crmMailing/BlockRecipients.html b/ang/crmMailing/BlockRecipients.html index d205f478f2..cedfa6dc24 100644 --- a/ang/crmMailing/BlockRecipients.html +++ b/ang/crmMailing/BlockRecipients.html @@ -8,12 +8,8 @@ name="{{crmMailingBlockRecipients.name}}" ng-required="true" /> -
- - - - {{getRecipientCount()}} - - +
+ + {{getRecipientCount()}}
diff --git a/ang/crmMailing/EditRecipCtrl.js b/ang/crmMailing/EditRecipCtrl.js index 3064384065..05d3e13c15 100644 --- a/ang/crmMailing/EditRecipCtrl.js +++ b/ang/crmMailing/EditRecipCtrl.js @@ -8,6 +8,7 @@ angular.module('crmMailing').controller('EditRecipCtrl', function EditRecipCtrl($scope, dialogService, crmApi, crmMailingMgr, $q, crmMetadata, crmStatus, crmMailingCache) { // Time to wait before triggering AJAX update to recipients list var RECIPIENTS_DEBOUNCE_MS = 100; + var SETTING_DEBOUNCE_MS = 5000; var RECIPIENTS_PREVIEW_LIMIT = 50; var ts = $scope.ts = CRM.ts(null); @@ -19,11 +20,12 @@ $scope.recipients = null; $scope.outdated = null; + $scope.permitRecipientRebuild = null; $scope.getRecipientsEstimate = function() { var ts = $scope.ts; if ($scope.recipients === null) { - return ts('(Estimating)'); + return ts('Estimating...'); } if ($scope.recipients === 0) { return ts('Estimate recipient count'); @@ -33,8 +35,8 @@ $scope.getRecipientCount = function() { var ts = $scope.ts; - if ($scope.recipients === 0) { - return ts('(unknown)'); + if ($scope.recipients === 0 || $scope.outdated) { + return $scope.permitRecipientRebuild ? ts('(unknown)') : ts('No Recipients'); } return ($scope.recipients === 1) ? ts('~1 recipient') : ts('~%1 recipients', {1 : $scope.recipients}); }; @@ -46,8 +48,8 @@ if (!$scope.mailing) { return; } - crmMailingMgr.previewRecipientCount($scope.mailing, crmMailingCache, false).then(function(recipients) { - $scope.outdated = (_.difference($scope.mailing.recipients, crmMailingCache.get('mailing-' + $scope.mailing.id + '-recipient-params')) !== 0); + crmMailingMgr.previewRecipientCount($scope.mailing, crmMailingCache, !$scope.permitRecipientRebuild).then(function(recipients) { + $scope.outdated = ($scope.permitRecipientRebuild && _.difference($scope.mailing.recipients, crmMailingCache.get('mailing-' + $scope.mailing.id + '-recipient-params')) !== 0); $scope.recipients = recipients; }); }); @@ -60,6 +62,16 @@ $scope.$watchCollection("mailing.recipients.mailings.include", refreshRecipients); $scope.$watchCollection("mailing.recipients.mailings.exclude", refreshRecipients); + // refresh setting at a duration on 5sec + var refreshSetting = _.debounce(function() { + $scope.$apply(function() { + crmApi('Setting', 'getvalue', {"name": 'auto_recipient_rebuild', "return": "value"}).then(function(response) { + $scope.permitRecipientRebuild = (response.result === 0); + }); + }); + }, SETTING_DEBOUNCE_MS); + $scope.$watchCollection("permitRecipientRebuild", refreshSetting); + $scope.previewRecipients = function previewRecipients() { var model = { count: $scope.recipients, @@ -73,7 +85,7 @@ }); // don't open preview dialog if there is no recipient to show. - if ($scope.recipients !== 0) { + if ($scope.recipients !== 0 && !$scope.outdated) { if (!_.isEmpty(model.sample)) { dialogService.open('recipDialog', '~/crmMailing/PreviewRecipCtrl.html', model, options); } @@ -87,6 +99,8 @@ }; $scope.rebuildRecipients = function rebuildRecipients() { + // setting null will put 'Estimating..' text on refresh button + $scope.recipients = null; return crmMailingMgr.previewRecipientCount($scope.mailing, crmMailingCache, true).then(function(recipients) { $scope.outdated = (recipients === 0) ? true : false; $scope.recipients = recipients; diff --git a/settings/Mailing.setting.php b/settings/Mailing.setting.php index 1969df133a..cc2626fa4c 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -333,4 +333,17 @@ return array( 'description' => 'The number of emails sendable via simple mail. Make sure you understand the implications for your spam reputation and legal requirements for bulk emails before editing. As there is some risk both to your spam reputation and the products if this is misused it is a hidden setting', 'help_text' => 'CiviCRM forces users sending more than this number of mails to use CiviMails. CiviMails have additional precautions: not sending to contacts who do not want bulk mail, adding domain name and opt out links. You should familiarise yourself with the law relevant to you on bulk mailings if changing this setting. For the US https://en.wikipedia.org/wiki/CAN-SPAM_Act_of_2003 is a good place to start.', ), + 'auto_recipient_rebuild' => array( + 'group_name' => 'Mailing Preferences', + 'group' => 'mailing', + 'name' => 'auto_recipient_rebuild', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => '1', + 'title' => 'Enable automatic CiviMail recipient count display', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Enable this setting to rebuild recipient list automatically during composing mail. Disable will allow you to rebuild recipient manually.', + 'help_text' => 'CiviMail automatically fetches recipient list and count whenever mailing groups are included or excluded while composing bulk mail. This phenomena may degrade performance for large sites, so disable this setting to build and fetch recipients for selected groups, manually.', + ), ); -- 2.25.1