CRM-16142 - Confirm before sending test mailing to a group
authorColeman Watts <coleman@civicrm.org>
Thu, 19 Mar 2015 20:52:31 +0000 (16:52 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 19 Mar 2015 20:52:31 +0000 (16:52 -0400)
js/angular-crmMailing.js
partials/crmMailing/preview.html

index 256cda54e88f641b2466e9b74288066ae7a35065..57f09ba86486dca9c4cba4e1b4934793bcf7ea89 100644 (file)
         }));
     };
 
+    $scope.previewTestGroup = function(e) {
+      var $dialog = $(this),
+        // Fixme: how to get this from the scope?
+        gid = $('select[name=preview_test_group]').val();
+      $dialog.html('<div class="crm-loading-element"></div>');
+      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 = '<ol>';
+        _.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 += '<li>' + row.display_name + ' - ' + row.email + '</li>';
+          }
+        });
+        markup += '</ol>';
+        $dialog.html('<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup).trigger('crmLoad');
+      });
+    };
+
     // @return Promise
     $scope.submit = function submit(options) {
       options = options || {};
index bfc7120dc13eb3630ccf32d5b3cabcce9db37319..9a514d4f409988a7ff4cb6ad52090c20a661821d 100644 (file)
@@ -52,7 +52,7 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
         <option value=""></option>
       </select>
     </div>
-    <button crm-icon="mail-closed" ng-disabled="crmMailing.$invalid || !testGroup.gid" ng-click="doSend({gid: testGroup.gid})">{{ts('Send test')}}</button>
+    <button crm-icon="mail-closed" title="{{ts('Send to group')}}" ng-disabled="crmMailing.$invalid || !testGroup.gid" crm-confirm="{resizable: true, width: '40%', height: '40%', open: previewTestGroup}" on-yes="doSend({gid: testGroup.gid})">{{ts('Send test')}}</button>
   </div>
   <div class="clear"></div>
 </div>