diff --git a/CRM/Admin/Form/Preferences/Mailing.php b/CRM/Admin/Form/Preferences/Mailing.php index 2b8af0a29a73..d7cd4ae3778a 100644 --- a/CRM/Admin/Form/Preferences/Mailing.php +++ b/CRM/Admin/Form/Preferences/Mailing.php @@ -108,6 +108,12 @@ public function preProcess() { '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', ), + 'enable_recipient_rebuild' => array( + 'html_type' => 'checkbox', + 'title' => ts('Enable recipient rebuild'), + 'weight' => 12, + 'description' => 'Enable this setting to rebuild recipient list on demand during composing mail', + ), ), ); diff --git a/ang/crmMailing.css b/ang/crmMailing.css index 3c39b693128a..b853cb4466e3 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 d205f478f22c..8024c1e4396c 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 3064384065eb..5659bdc13655 100644 --- a/ang/crmMailing/EditRecipCtrl.js +++ b/ang/crmMailing/EditRecipCtrl.js @@ -19,11 +19,21 @@ $scope.recipients = null; $scope.outdated = null; + $scope.permitRecipientRebuild = $scope.permitRecipientRebuild || null; + + $scope.isRecipientBuildEnabled = function() { + if ($scope.permitRecipientRebuild === null) { + crmApi('Setting', 'getvalue', {"name": 'enable_recipient_rebuild', "return": "value"}).then(function(response) { + $scope.permitRecipientRebuild = (response.result === 1); + }); + } + return $scope.permitRecipientRebuild; + }; $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 +43,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 +56,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; }); }); @@ -73,7 +83,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 +97,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 1969df133aea..2f4fd0edd400 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -333,4 +333,17 @@ '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.', ), + 'enable_recipient_rebuild' => array( + 'group_name' => 'Mailing Preferences', + 'group' => 'mailing', + 'name' => 'enable_recipient_rebuild', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => '0', + 'title' => 'Enable recipient rebuild', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Enable this setting to rebuild recipient list on demand during composing mail.', + '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 this setting enables user to build and fetch recipients for selected groups, on demand.', + ), );