From bf2ce887f326b4941d2e01c0c8f539a24eb70bd4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 30 Aug 2015 06:36:03 -0700 Subject: [PATCH] CRM-13422 - Form/ScheduleReminders - Allow role filters on custom mappings Previously, the 'Recipient Role' was only displayed if the results were limited to 'participant_role'. Now, the field will be displayed if the mapping's getRecipientListing($recipientType) returns any data. --- CRM/Admin/Page/AJAX.php | 22 +++++++++++++++++++ CRM/Core/xml/Menu/Admin.xml | 4 ++-- .../CRM/Admin/Form/ScheduleReminders.tpl | 20 +++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 2b42cc238b..06a34e186c 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -327,6 +327,28 @@ LIMIT $limit"; CRM_Utils_JSON::output($output); } + /** + * (Scheduled Reminders) Get the list of possible recipient filters. + * + * Ex: GET /civicrm/ajax/recipientListing?mappingID=contribpage&recipientType= + */ + public static function recipientListing() { + $mappingID = filter_input(INPUT_GET, 'mappingID', FILTER_VALIDATE_REGEXP, array( + 'options' => array( + 'regexp' => '/^[a-zA-Z0-9_\-]+$/', + ), + )); + $recipientType = filter_input(INPUT_GET, 'recipientType', FILTER_VALIDATE_REGEXP, array( + 'options' => array( + 'regexp' => '/^[a-zA-Z0-9_\-]+$/', + ), + )); + + CRM_Utils_JSON::output(array( + 'recipients' => CRM_Utils_Array::toKeyValueRows(CRM_Core_BAO_ActionSchedule::getRecipientListing($mappingID, $recipientType)), + )); + } + public static function mergeTags() { $tagAId = CRM_Utils_Type::escape($_POST['fromId'], 'Integer'); $tagBId = CRM_Utils_Type::escape($_POST['toId'], 'Integer'); diff --git a/CRM/Core/xml/Menu/Admin.xml b/CRM/Core/xml/Menu/Admin.xml index 1754e15aca..cdd615205f 100644 --- a/CRM/Core/xml/Menu/Admin.xml +++ b/CRM/Core/xml/Menu/Admin.xml @@ -723,8 +723,8 @@ administer CiviCRM,access CiviCRM - civicrm/ajax/mapping1 - CRM_Admin_Page_AJAX::mappingList1 + civicrm/ajax/recipientListing + CRM_Admin_Page_AJAX::recipientListing administer CiviCRM,access CiviCRM diff --git a/templates/CRM/Admin/Form/ScheduleReminders.tpl b/templates/CRM/Admin/Form/ScheduleReminders.tpl index 321607fd5b..557613bb54 100644 --- a/templates/CRM/Admin/Form/ScheduleReminders.tpl +++ b/templates/CRM/Admin/Form/ScheduleReminders.tpl @@ -194,17 +194,19 @@ $('#mode', $form).change(loadMsgBox); function populateRecipient() { + var mappingID = $('#entity_0', $form).val(); var recipient = $("#recipient", $form).val(); - if ((recipientMapping[recipient] == 'Participant Status' || recipientMapping[recipient] == 'participant_role') && $('#limit_to').val() != '') { - CRM.api3('participant', 'getoptions', {field: recipientMapping[recipient] == 'participant_role' ? 'role_id' : 'status_id', sequential: 1}) - .done(function(result) { - CRM.utils.setOptions($('#recipient_listing', $form), result.values); - }); - $("#recipientList", $form).show(); + $("#recipientList", $form).hide(); + if ($('#limit_to').val() != '' ) { + $.getJSON(CRM.url('civicrm/ajax/recipientListing'), {mappingID: mappingID, recipientType: recipient}, + function (result) { + if (!CRM._.isEmpty(result.recipients)) { + CRM.utils.setOptions($('#recipient_listing', $form), result.recipients); + $("#recipientList", $form).show(); + } + } + ); } - else { - $("#recipientList", $form).hide(); - } showHideLimitTo(); } -- 2.25.1