CRM-15149 - Ensure search results are force-refreshed when a contact is updated
authorColeman Watts <coleman@civicrm.org>
Tue, 26 Aug 2014 21:06:38 +0000 (22:06 +0100)
committerColeman Watts <coleman@civicrm.org>
Tue, 26 Aug 2014 21:06:38 +0000 (22:06 +0100)
CRM/Core/Form/Search.php
js/crm.searchForm.js

index 2acc04af1dc431edfb18b0869ebacb9247da792b..d593639c3e4eae03d5e79948f156b3113350c579 100644 (file)
@@ -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);
     }
index b02a340362f9537f69133d552063963e8dfa51cc..4b4ad2e7fea220082b7d37a8289d195f83b7df4b 100644 (file)
@@ -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');
     });
   }
 
+  /**
+   * 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
         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._);