// Trait provides base methods and properties common to all search display types
angular.module('crmSearchDisplay').factory('searchDisplayBaseTrait', function(crmApi4) {
- var ts = CRM.ts('org.civicrm.search_kit');
+ var ts = CRM.ts('org.civicrm.search_kit'),
+ runCount = 0;
// Replace tokens keyed to rowData.
// Pass view=true to replace with view value, otherwise raw value is used.
$scope.$apply(function() {
ctrl.runSearch();
});
- }, 100);
+ }, 800);
// If search is embedded in contact summary tab, display count in tab-header
var contactTab = $element.closest('.crm-contact-page .ui-tabs-panel').attr('id');
// Call SearchDisplay.run and update ctrl.results and ctrl.rowCount
runSearch: function(editedRow) {
var ctrl = this,
+ requestId = ++runCount;
apiParams = this.getApiParams();
this.loading = true;
_.each(ctrl.onPreRun, function(callback) {
callback.call(ctrl, apiParams);
});
return crmApi4('SearchDisplay', 'run', apiParams).then(function(results) {
+ if (requestId < runCount) {
+ return; // Another request started after this one
+ }
ctrl.results = results;
ctrl.editing = ctrl.loading = false;
if (!ctrl.rowCount) {
callback.call(ctrl, results, 'success', editedRow);
});
}, function(error) {
+ if (requestId < runCount) {
+ return; // Another request started after this one
+ }
ctrl.results = [];
ctrl.editing = ctrl.loading = false;
_.each(ctrl.onPostRun, function(callback) {