Merge branch '5.26' of https://github.com/civicrm/civicrm-core
[civicrm-core.git] / ang / crmMailing / EditUnsubGroupCtrl.js
index c0e7d3e71fb1e3285dd4e09483f8fc0ada991767..56070e03e64482df2f7001a8776ba1327bdbeb00 100644 (file)
@@ -3,14 +3,16 @@
   angular.module('crmMailing').controller('EditUnsubGroupCtrl', function EditUnsubGroupCtrl($scope) {
     // CRM.crmMailing.groupNames is a global constant - since it doesn't change, we can digest & cache.
     var mandatoryIds = [];
-    _.each(CRM.crmMailing.groupNames, function(grp) {
-      if (grp.is_hidden == "1") {
-        mandatoryIds.push(parseInt(grp.id));
-      }
-    });
 
     $scope.isUnsubGroupRequired = function isUnsubGroupRequired(mailing) {
-      return _.intersection(mandatoryIds, mailing.recipients.groups.include).length > 0;
+      if (!_.isEmpty(CRM.crmMailing.groupNames)) {
+        _.each(CRM.crmMailing.groupNames, function(grp) {
+          if (grp.is_hidden == "1") {
+            mandatoryIds.push(parseInt(grp.id));
+          }
+        });
+        return _.intersection(mandatoryIds, mailing.recipients.groups.include).length > 0;
+      }
     };
   });