| 1 | (function(angular, $, _) { |
| 2 | // example: <input name="subject" /> <input crm-mailing-token on-select="doSomething(token.name)" /> |
| 3 | // WISHLIST: Instead of global CRM.crmMailing.mailTokens, accept token list as an input |
| 4 | angular.module('crmMailing').directive('crmMailingToken', function() { |
| 5 | return { |
| 6 | require: '^crmUiIdScope', |
| 7 | scope: { |
| 8 | onSelect: '@' |
| 9 | }, |
| 10 | template: '<input type="text" class="crmMailingToken" />', |
| 11 | link: function(scope, element, attrs, crmUiIdCtrl) { |
| 12 | $(element).addClass('crm-action-menu fa-code').crmSelect2({ |
| 13 | width: "12em", |
| 14 | dropdownAutoWidth: true, |
| 15 | data: CRM.crmMailing.mailTokens, |
| 16 | placeholder: ts('Tokens') |
| 17 | }); |
| 18 | $(element).on('select2-selecting', function(e) { |
| 19 | e.preventDefault(); |
| 20 | $(element).select2('close').select2('val', ''); |
| 21 | scope.$parent.$eval(attrs.onSelect, { |
| 22 | token: {name: e.val} |
| 23 | }); |
| 24 | }); |
| 25 | } |
| 26 | }; |
| 27 | }); |
| 28 | })(angular, CRM.$, CRM._); |