From f8f8576410bcf9767ebc64a8d128cbf75e91840b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 12 Feb 2015 08:53:38 -0800 Subject: [PATCH] crmMailingToken - Use $broadcast to link insertions and their targets --- js/angular-crm-ui.js | 33 ++++++++++++++++++++++++ js/angular-crmMailing/directives.js | 29 +++++---------------- partials/crmMailing/body_html.html | 19 +++++++++----- partials/crmMailing/body_text.html | 18 +++++++++---- partials/crmMailing/mailing.html | 3 ++- partials/crmMailingAB/joint-mailing.html | 9 ++++--- 6 files changed, 73 insertions(+), 38 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index cfc451866a..0527396f20 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -277,6 +277,39 @@ }; }) + // Example: + // .directive('crmUiRichtext', function ($timeout) { diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index 1ba5449fbe..214ed8e5e3 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -180,13 +180,13 @@ }; }); - // example: + // example: // WISHLIST: Instead of global CRM.crmMailing.mailTokens, accept token list as an input angular.module('crmMailing').directive('crmMailingToken', function () { return { require: '^crmUiIdScope', scope: { - crmFor: '@' + onSelect: '@' }, template: '', link: function (scope, element, attrs, crmUiIdCtrl) { @@ -197,28 +197,11 @@ placeholder: ts('Tokens') }); $(element).on('select2-selecting', function (e) { - var id = crmUiIdCtrl.get(attrs.crmFor); - if (CKEDITOR.instances[id]) { - CKEDITOR.instances[id].insertText(e.val); - $(element).select2('close').select2('val', ''); - CKEDITOR.instances[id].focus(); - } - else { - var crmForEl = $('#' + id); - var origVal = crmForEl.val(); - var origPos = crmForEl[0].selectionStart; - var newVal = origVal.substring(0, origPos) + e.val + origVal.substring(origPos, origVal.length); - crmForEl.val(newVal); - var newPos = (origPos + e.val.length); - crmForEl[0].selectionStart = newPos; - crmForEl[0].selectionEnd = newPos; - - $(element).select2('close').select2('val', ''); - crmForEl.triggerHandler('change'); - crmForEl.focus(); - } - e.preventDefault(); + $(element).select2('close').select2('val', ''); + scope.$parent.$eval(attrs.onSelect, { + token: {name: e.val} + }); }); } }; diff --git a/partials/crmMailing/body_html.html b/partials/crmMailing/body_html.html index 1953d51291..9fd7469b77 100644 --- a/partials/crmMailing/body_html.html +++ b/partials/crmMailing/body_html.html @@ -2,12 +2,19 @@ Required vars: mailing -->
-
- -
-
- - +
+ +
+ +
+ + +
diff --git a/partials/crmMailing/body_text.html b/partials/crmMailing/body_text.html index 2d4665c8dd..1e2ad5cda3 100644 --- a/partials/crmMailing/body_text.html +++ b/partials/crmMailing/body_text.html @@ -2,11 +2,19 @@ Required vars: mailing, crmMailingConst -->
-
- -
- - +
+ +
+ +
+ + +
diff --git a/partials/crmMailing/mailing.html b/partials/crmMailing/mailing.html index 9bbfd28295..de2068fdda 100644 --- a/partials/crmMailing/mailing.html +++ b/partials/crmMailing/mailing.html @@ -54,10 +54,11 @@ It could perhaps be thinned by 30-60% by making more directives.
- +
- +
- +
- +