Skip to content

Instantly share code, notes, and snippets.

@elchele
Created July 7, 2015 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchele/a78e17efb780d2edd894 to your computer and use it in GitHub Desktop.
Save elchele/a78e17efb780d2edd894 to your computer and use it in GitHub Desktop.
Filter controller extension to change behavior to utilize OR operand
({
/* File: ./custom/modules/<Module>/clients/base/layouts/filter/filter.js */
extendsFrom: 'FilterLayout',
applyFilter: function(query, dynamicFilterDef) {
var customFilterDef = [{'$or':[{'billing_address_city':{'$starts':query}},{'name':{'$starts':query}}]}];
// TODO: getRelevantContextList needs to be refactored to handle filterpanels in drawer layouts,
// as it will return the global context instead of filtering a list view within the drawer context.
// As a result, this flag is needed to prevent filtering on the global context.
var filterOptions = this.context.get('filterOptions') || {};
if (filterOptions.auto_apply === false) {
return;
}
//If the quicksearch field is not empty, append a remove icon so the user can clear the search easily
this._toggleClearQuickSearchIcon(!_.isEmpty(query));
// reset the selected on filter apply
var massCollection = this.context.get('mass_collection');
if (massCollection && massCollection.models && massCollection.models.length > 0) {
massCollection.reset([],{silent: true});
}
var self = this,
ctxList = this.getRelevantContextList();
_.each(ctxList, function(ctx) {
var ctxCollection = ctx.get('collection'),
origFilterDef = dynamicFilterDef || ctxCollection.origFilterDef || [],
filterDef = customFilterDef,
options = {
//Show alerts for this request
showAlerts: true,
success: function(collection, response, options) {
// Close the preview pane to ensure that the preview
// collection is in sync with the list collection.
app.events.trigger('preview:close');
}};
ctxCollection.filterDef = filterDef;
ctxCollection.origFilterDef = origFilterDef;
ctxCollection.resetPagination();
options = _.extend(options, ctx.get('collectionOptions'));
ctx.resetLoadFlag(false);
if (!_.isEmpty(ctx._recordListFields)) {
ctx.set('fields', ctx._recordListFields);
}
ctx.set('skipFetch', false);
ctx.loadData(options);
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment