CRM-201100 Convert list of test groups into AJAX based select2 like receipients box
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 24 Aug 2017 10:15:22 +0000 (20:15 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 9 Apr 2018 21:04:23 +0000 (07:04 +1000)
Switch to entity ref as per coleman

ang/crmMailing/BlockPreview.html
ang/crmMailing/BlockPreview.js

index 823ea8548d925fede2ba512d585dbc1196bbbd56..d913c5875a93982e1897f69d6739001752659e6e 100644 (file)
@@ -45,16 +45,11 @@ Vars: mailing:obj, testContact:obj, testGroup:obj, crmMailing:FormController
       <a crm-ui-help="hs({id: 'test', title: ts('Test Email')})"></a>
     </div>
     <div>
-      <select
-        name="preview_test_group"
-        ui-jq="crmSelect2"
-        ui-options="{dropdownAutoWidth : true, allowClear: true, placeholder: ts('Select Group')}"
+      <input
+        crm-entityref="{entity: 'Group', select: {allowClear:true}}"
         ng-model="testGroup.gid"
-        ng-options="group.id as group.title for group in crmMailingConst.testGroupNames|orderBy:'title'"
         class="crm-action-menu fa-envelope-o"
-        >
-        <option value=""></option>
-      </select>
+        />
     </div>
     <button crm-icon="fa-paper-plane" title="{{crmMailing.$invalid || !testGroup.gid ? ts('Complete all required fields first') : ts('Send test message 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>
index 36b72ea981dfe91cde338439a877c741385386d0..659578d1476444316ef4f7663214147d71ef4e65 100644 (file)
         scope.previewTestGroup = function(e) {
           var $dialog = $(this);
           $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.testGroupNames, {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,
-            // Fixme: should this be in a template?
+          CRM.api3('group', 'getsingle', {id: scope.testGroup.gid, return: 'title'}).done(function(group) {
+            $dialog.dialog('option', 'title', ts('Send to %1', {1: group.title}));
+            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>';
+              _.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>';
+              markup = '<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup;
+              if (!count) {
+                markup = '<div class="messages status"><i class="crm-i fa-exclamation-triangle"></i> ' +
+                (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);
             });
-            markup += '</ol>';
-            markup = '<h4>' + ts('A test message will be sent to %1 people:', {1: count}) + '</h4>' + markup;
-            if (!count) {
-              markup = '<div class="messages status"><i class="crm-i fa-exclamation-triangle"></i> ' +
-              (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);
           });
         };
       }