From 3da9b9f20c70a480671dd954422942e1c29b41d0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 26 Aug 2014 22:06:38 +0100 Subject: [PATCH] CRM-15149 - Ensure search results are force-refreshed when a contact is updated --- CRM/Core/Form/Search.php | 1 - js/crm.searchForm.js | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 2acc04af1d..d593639c3e 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -84,7 +84,6 @@ class CRM_Core_Form_Search extends CRM_Core_Form { $resources = CRM_Core_Resources::singleton(); if ($resources->ajaxPopupsEnabled) { - $resources->addScriptFile('civicrm', 'js/crm.livePage.js'); // Script needed by some popups $this->assign('includeWysiwygEditor', TRUE); } diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index b02a340362..4b4ad2e7fe 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -2,7 +2,8 @@ (function($, _, undefined) { "use strict"; var selected = 0, - form = 'form.crm-search-form'; + form = 'form.crm-search-form', + active = 'a.button, a.action-item, a.crm-popup'; function clearTaskMenu() { $('select#task', form).val('').select2('val', '').prop('disabled', true).select2('disable'); @@ -57,6 +58,18 @@ }); } + /** + * Refresh the current page + */ + function refresh() { + // Clear cached search results using force=1 argument + var location = $('#crm-main-content-wrapper').crmSnippet().crmSnippet('option', 'url'); + if (!(location.match(/[?&]force=1/))) { + location += '&force=1'; + } + $('#crm-main-content-wrapper').crmSnippet({url: location}).crmSnippet('refresh'); + } + // Handle user interactions with search results $('#crm-container') // When initially loading and reloading (paging) the results @@ -111,12 +124,17 @@ url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json'; clearTaskMenu(); $.post(url, data, function(data) { - CRM.loadForm(data.userContext).on('crmFormSuccess', function() { - CRM.refreshParent($form); - }); + CRM.loadForm(data.userContext).on('crmFormSuccess', refresh); enableTaskMenu(); }, 'json'); } }); + // Add a specialized version of livepage functionality + $('#crm-main-content-wrapper') + // Open action links in a popup + .off('.crmLivePage') + .on('click.crmLivePage', active, CRM.popup) + .on('crmPopupFormSuccess.crmLivePage', active, refresh); + })(CRM.$, CRM._); -- 2.25.1