--CRM-15055, code changes to handle separate membership
[civicrm-core.git] / js / crm.searchForm.js
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._);