From: Coleman Watts Date: Thu, 19 Mar 2015 22:22:44 +0000 (-0400) Subject: CRM-16142 - Variable scope fixes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8935eb8546c4710a52602f0d8f931e03391dafef;p=civicrm-core.git CRM-16142 - Variable scope fixes --- diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index 57f09ba864..256cda54e8 100644 --- a/js/angular-crmMailing.js +++ b/js/angular-crmMailing.js @@ -109,27 +109,6 @@ })); }; - $scope.previewTestGroup = function(e) { - var $dialog = $(this), - // Fixme: how to get this from the scope? - gid = $('select[name=preview_test_group]').val(); - $dialog.html('
'); - CRM.api3('contact', 'get', {group: gid, options: {limit: 0}, return: 'display_name,email'}).done(function(data) { - // Fixme: should this be in a template? - var count = 0, - markup = '
    '; - _.each(data.values, function(row) { - // Fixme: contact api doesn't seem capable of filtering out contacts with no email, so we're doing it client-side - if (row.email) { - count++; - markup += '
  1. ' + row.display_name + ' - ' + row.email + '
  2. '; - } - }); - markup += '
'; - $dialog.html('

' + ts('A test message will be sent to %1 people:', {1: count}) + '

' + markup).trigger('crmLoad'); - }); - }; - // @return Promise $scope.submit = function submit(options) { options = options || {}; diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index 307df6369e..aa32d86083 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -61,6 +61,25 @@ preview: {recipient: recipient} }); }; + + scope.previewTestGroup = function(e) { + var $dialog = $(this); + $dialog.html('
'); + CRM.api3('contact', 'get', {group: scope.testGroup.gid, options: {limit: 0}, return: 'display_name,email'}).done(function(data) { + var count = 0, + // Fixme: should this be in a template? + markup = '
    '; + _.each(data.values, function(row) { + // Fixme: contact api doesn't seem capable of filtering out contacts with no email, so we're doing it client-side + if (row.email) { + count++; + markup += '
  1. ' + row.display_name + ' - ' + row.email + '
  2. '; + } + }); + markup += '
'; + $dialog.html('

' + ts('A test message will be sent to %1 people:', {1: count}) + '

' + markup).trigger('crmLoad'); + }); + }; } }; });