Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21486: Support multiple test mail #11332

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ang/crmMailing/BlockPreview.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
<div>
<input
name="preview_test_email"
type="email"
type="text"
class="crm-form-text"
ng-model="testContact.email"
placeholder="example@example.org"
/>
crm-multiple-email
/>
</div>
<button crm-icon="fa-paper-plane" title="{{crmMailing.$invalid || !testContact.email ? ts('Complete all required fields first') : ts('Send test message to %1', {1: testContact.email})}}" ng-disabled="crmMailing.$invalid || !testContact.email" ng-click="doSend({email: testContact.email})">{{ts('Send test')}}</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ang/crmMailing/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
return crmLegacy.url('civicrm/contact/search/advanced',
'force=1&mailing_id=' + mailing.id + statType.searchFilter);
case 'report':
var reportIds = CRM.crmMailing.reportIds;
var reportIds = CRM.crmMailing.reportIds;
return crmLegacy.url('civicrm/report/instance/' + reportIds[statType.reportType],
'reset=1&mailing_id_value=' + mailing.id + statType.reportFilter);
default:
Expand Down
32 changes: 32 additions & 0 deletions ang/crmUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,38 @@
};
})

// validate multiple email text
// usage: <input crm-multiple-email type="text" ng-model="myobj.field" />
.directive('crmMultipleEmail', function ($parse, $timeout) {
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
ctrl.$parsers.unshift(function(viewValue) {
// if empty value provided simply bypass validation
if (_.isEmpty(viewValue)) {
ctrl.$setValidity('crmMultipleEmail', true);
return viewValue;
}

// split email string on basis of comma
var emails = viewValue.split(',');
// regex pattern for single email
var emailRegex = /\S+@\S+\.\S+/;

var validityArr = emails.map(function(str){
return emailRegex.test(str.trim());
});

if ($.inArray(false, validityArr) > -1) {
ctrl.$setValidity('crmMultipleEmail', false);
} else {
ctrl.$setValidity('crmMultipleEmail', true);
}
return viewValue;
});
}
};
})
// example <div crm-ui-tab id="tab-1" crm-title="ts('My Title')" count="3">...content...</div>
// WISHLIST: use a full Angular component instead of an incomplete jQuery wrapper
.directive('crmUiTab', function($parse) {
Expand Down