CRM-16142 - Disable test send if group is empty
authorColeman Watts <coleman@civicrm.org>
Fri, 20 Mar 2015 04:15:26 +0000 (00:15 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 20 Mar 2015 04:15:26 +0000 (00:15 -0400)
js/angular-crmMailing/directives.js

index 25267923751b6c0e4309ee0564b3ab5ccf0417bc..05c22cf690d5f9d8a95ed4324add81ddd05a8f0b 100644 (file)
@@ -64,7 +64,7 @@
 
         scope.previewTestGroup = function(e) {
           var $dialog = $(this);
-          $dialog.html('<div class="crm-loading-element"></div>');
+          $dialog.html('<div class="crm-loading-element"></div>').parent().find('button[data-op=yes]').prop('disabled', true);
           $dialog.dialog('option', 'title', ts('Send to %1', {1: _.pluck(_.where(scope.crmMailingConst.groupNames, {id: scope.testGroup.gid}), 'title')[0]}));
           CRM.api3('contact', 'get', {group: scope.testGroup.gid, options: {limit: 0}, return: 'display_name,email'}).done(function(data) {
             var count = 0,
               }
             });
             markup += '</ol>';
-            $dialog.html('<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup).trigger('crmLoad');
+            markup = '<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup;
+            if (!count) {
+              markup = '<div class="messages status"><div class="icon ui-icon-alert"></div> ' +
+              (data.count ? ts('None of the contacts in this group have an email address.') : ts('Group is empty.')) +
+              '</div>';
+            }
+            $dialog
+              .html(markup)
+              .trigger('crmLoad')
+              .parent().find('button[data-op=yes]').prop('disabled', !count);
           });
         };
       }