CRM-16142 - Variable scope fixes
authorColeman Watts <coleman@civicrm.org>
Thu, 19 Mar 2015 22:22:44 +0000 (18:22 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 19 Mar 2015 22:22:44 +0000 (18:22 -0400)
js/angular-crmMailing.js
js/angular-crmMailing/directives.js

index 57f09ba86486dca9c4cba4e1b4934793bcf7ea89..256cda54e88f641b2466e9b74288066ae7a35065 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 307df6369ee4e3aeb55ad4ce6aaca0f5d81f8bc6..aa32d86083544cac119b7cebd50533a7b85495ef 100644 (file)
             preview: {recipient: recipient}
           });
         };
+
+        scope.previewTestGroup = function(e) {
+          var $dialog = $(this);
+          $dialog.html('<div class="crm-loading-element"></div>');
+          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 = '<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');
+          });
+        };
       }
     };
   });