From 3cc9c0480059156749237460873246c40469edd3 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 14 Dec 2014 14:32:46 -0800 Subject: [PATCH] CRM-15578 - body_text, body_html - Allow multiple instances This commit removes the previous crmUiId() service and makes consistent use of the newer, more adaptible crmUiId and crmUiIdScope directives. --- js/angular-crm-ui.js | 28 +++++++---------------- js/angular-crmMailing2-directives.js | 20 ++++------------ partials/crmMailing2/body_html.html | 10 ++++---- partials/crmMailing2/body_text.html | 8 ++++--- partials/crmMailing2/mailing.html | 2 +- partials/crmMailingAB2/joint-mailing.html | 6 ++--- 6 files changed, 28 insertions(+), 46 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 8bd92becbb..f38e208011 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -9,19 +9,6 @@ angular.module('crmUi', []) - .factory('crmUiId', function() { - var idCount = 0; - // Get the HTML ID of an element. If none available, assign one. - return function crmUiId(el){ - var id = el.attr('id'); - if (!id) { - id = 'crmUi_' + (++idCount); - el.attr('id', id); - } - return id; - }; - }) - // example
...content...
// WISHLIST: crmCollapsed should support two-way/continous binding .directive('crmUiAccordion', function() { @@ -115,7 +102,7 @@ // example:
{{mydata}}
// example:
// example:
- .directive('crmUiField', function(crmUiId) { + .directive('crmUiField', function() { // Note: When writing new templates, the "label" position is particular. See/patch "var label" below. var templateUrls = { default: partialUrl('field.html'), @@ -147,9 +134,11 @@ return { require: '^crmUiIdScope', restrict: 'EA', - link: function (scope, element, attrs, crmUiIdCtrl) { - var id = crmUiIdCtrl.get(attrs.crmUiId); - element.attr('id', id); + link: { + pre: function (scope, element, attrs, crmUiIdCtrl) { + var id = crmUiIdCtrl.get(attrs.crmUiId); + element.attr('id', id); + } } }; }) @@ -271,12 +260,11 @@ }; }) - // example: - .directive('crmUiRichtext', function (crmUiId, $timeout) { + // example: + .directive('crmUiRichtext', function ($timeout) { return { require: '?ngModel', link: function (scope, elm, attr, ngModel) { - crmUiId(elm); var ck = CKEDITOR.replace(elm[0]); if (!ngModel) { diff --git a/js/angular-crmMailing2-directives.js b/js/angular-crmMailing2-directives.js index 4c3abf75f7..cd11e3e30e 100644 --- a/js/angular-crmMailing2-directives.js +++ b/js/angular-crmMailing2-directives.js @@ -89,25 +89,14 @@ // example: // WISHLIST: Instead of global CRM.crmMailing.mailTokens, accept token list as an input - crmMailing2.directive('crmMailingToken', function (crmUiId) { + crmMailing2.directive('crmMailingToken', function () { return { + require: '^crmUiIdScope', scope: { crmFor: '@' }, template: '', - link: function (scope, element, attrs) { - // 1. Find the corresponding input element (crmFor) - - var form = $(element).closest('form'); - var crmForEl = $('input[name="' + attrs.crmFor + '"],textarea[name="' + attrs.crmFor + '"]', form); - if (form.length != 1 || crmForEl.length != 1) { - if (console.log) { - console.log('crmMailingToken cannot be matched to input element. Expected to find one form and one input.', form.length, crmForEl.length); - } - return; - } - - // 2. Setup the token selector + link: function (scope, element, attrs, crmUiIdCtrl) { $(element).select2({ width: "10em", dropdownAutoWidth: true, @@ -115,13 +104,14 @@ placeholder: ts('Insert') }); $(element).on('select2-selecting', function (e) { - var id = crmUiId(crmForEl); + 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); diff --git a/partials/crmMailing2/body_html.html b/partials/crmMailing2/body_html.html index 4c4813f18b..6805929dad 100644 --- a/partials/crmMailing2/body_html.html +++ b/partials/crmMailing2/body_html.html @@ -1,8 +1,10 @@ -
- -
+
+
+ +
- + +
\ No newline at end of file diff --git a/partials/crmMailing2/body_text.html b/partials/crmMailing2/body_text.html index c4dc4600dc..2b41e981be 100644 --- a/partials/crmMailing2/body_text.html +++ b/partials/crmMailing2/body_text.html @@ -1,7 +1,9 @@ -
- +
+
+ +
+
- diff --git a/partials/crmMailing2/mailing.html b/partials/crmMailing2/mailing.html index 7e93c12147..ed33ec2d11 100644 --- a/partials/crmMailing2/mailing.html +++ b/partials/crmMailing2/mailing.html @@ -75,7 +75,7 @@ It could perhaps be thinned by 30-60% by making more directives.
- +
- +
- +
- +