Commit | Line | Data |
---|---|---|
b396fc59 TO |
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) { | |
7 | return { | |
8 | link: function(scope, element, attrs) { | |
9 | var placeholder = attrs.crmMailingFromAddress; | |
10 | var mailing = null; | |
11 | scope.$watch(attrs.crmMailing, function(newValue) { | |
12 | mailing = newValue; | |
13 | scope[placeholder] = { | |
14 | label: crmFromAddresses.getByAuthorEmail(mailing.from_name, mailing.from_email, true).label | |
15 | }; | |
16 | }); | |
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; | |
70f43ffb | 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; | |
24 | } | |
b396fc59 TO |
25 | }); |
26 | // FIXME: Shouldn't we also be watching mailing.from_name and mailing.from_email? | |
27 | } | |
28 | }; | |
29 | }); | |
30 | })(angular, CRM.$, CRM._); |