1 (function(angular
, $, _
) {
2 // Convert between a mailing "From Address" (mailing.from_name,mailing.from_email) and a unified label ("Name" <e@ma.il>)
3 // example: <span crm-mailing-from-address="myPlaceholder" crm-mailing="myMailing"><select ng-model="myPlaceholder.label"></select></span>
4 // NOTE: This really doesn't belong in a directive. I've tried (and failed) to make this work with a getterSetter binding, eg
5 // <select ng-model="mailing.convertFromAddress" ng-model-options="{getterSetter: true}">
6 angular
.module('crmMailing').directive('crmMailingFromAddress', function(crmFromAddresses
) {
8 link: function(scope
, element
, attrs
) {
9 var placeholder
= attrs
.crmMailingFromAddress
;
11 scope
.$watch(attrs
.crmMailing
, function(newValue
) {
13 scope
[placeholder
] = {
14 label
: crmFromAddresses
.getByAuthorEmail(mailing
.from_name
, mailing
.from_email
, true).label
17 scope
.$watch(placeholder
+ '.label', function(newValue
) {
18 var addr
= crmFromAddresses
.getByLabel(newValue
);
19 mailing
.from_name
= addr
.author
;
20 mailing
.from_email
= addr
.email
;
21 // CRM-18364: set replyTo as from_email only if custom replyTo is disabled in mail settings.
22 if (!CRM
.crmMailing
.enableReplyTo
) {
23 mailing
.replyto_email
= crmFromAddresses
.getByAuthorEmail(mailing
.from_name
, mailing
.from_email
, true).label
;
26 // FIXME: Shouldn't we also be watching mailing.from_name and mailing.from_email?
30 })(angular
, CRM
.$, CRM
._
);