From b4fdf77af509c783f63ddf4c7ab63569b60ee6f6 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Mon, 27 Nov 2017 22:27:45 +0530 Subject: [PATCH] CRM-21486: Support multiple test mail --- ang/crmMailing/BlockPreview.html | 5 +++-- ang/crmMailing/services.js | 2 +- ang/crmUi.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ang/crmMailing/BlockPreview.html b/ang/crmMailing/BlockPreview.html index 747c7b0e04..823ea8548d 100644 --- a/ang/crmMailing/BlockPreview.html +++ b/ang/crmMailing/BlockPreview.html @@ -30,11 +30,12 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
+ crm-multiple-email + />
diff --git a/ang/crmMailing/services.js b/ang/crmMailing/services.js index a4de098344..96d1340708 100644 --- a/ang/crmMailing/services.js +++ b/ang/crmMailing/services.js @@ -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: diff --git a/ang/crmUi.js b/ang/crmUi.js index a66334015a..3fc8598217 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -675,6 +675,38 @@ }; }) + // validate multiple email text + // usage: + .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
...content...
// WISHLIST: use a full Angular component instead of an incomplete jQuery wrapper .directive('crmUiTab', function($parse) { -- 2.25.1