Skip to content

Commit

Permalink
additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Oct 12, 2017
1 parent 548d260 commit 71c4245
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CRM/Admin/Form/Preferences/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
),
);

Expand Down
10 changes: 0 additions & 10 deletions ang/crmMailing.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 3 additions & 7 deletions ang/crmMailing/BlockRecipients.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
name="{{crmMailingBlockRecipients.name}}"
ng-required="true" />
<a crm-icon="fa-wrench" ng-click="editOptions(mailing)" class="crm-hover-button" title="{{ts('Edit Recipient Options')}}"></a>
<div>
<button ng-click="rebuildRecipients()" class="ng-binding crm-button" title="{{ts('Preview a List of Recipients')}}">{{getRecipientsEstimate()}}</button>
<a ng-click="previewRecipients()" class="crm-hover-button" title="{{ts('Click to refresh recipient count')}}">
<span class="{{((outdated || recipient == 0) ? 'crmMailing-outdated-count' : 'crmMailing-latest-count')}}">
{{getRecipientCount()}}
</span>
</a>
<div ng-style="{display: permitRecipientRebuild ? '' : 'inline-block'}">
<button ng-click="rebuildRecipients()" ng-show="isRecipientBuildEnabled()" class="ng-binding crm-button" title="{{ts('Click to refresh recipient count')}}">{{getRecipientsEstimate()}}</button>
<a ng-click="previewRecipients()" class="crm-hover-button" title="{{ts('Preview a List of Recipients')}}" style="font-weight: bold;">{{getRecipientCount()}}</a>
</div>
</div>
24 changes: 18 additions & 6 deletions ang/crmMailing/EditRecipCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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});
};
Expand All @@ -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;
});
});
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions settings/Mailing.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
),
);

0 comments on commit 71c4245

Please sign in to comment.