| 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; |
| 21 | }); |
| 22 | // FIXME: Shouldn't we also be watching mailing.from_name and mailing.from_email? |
| 23 | } |
| 24 | }; |
| 25 | }); |
| 26 | })(angular, CRM.$, CRM._); |