Commit 876107d5 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Fix search by input

parent c228ff0b
......@@ -13,14 +13,18 @@ export default class FilterableList {
initSearch() {
// Wrap to prevent passing event arguments to .filterResults;
this.debounceFilter = _.debounce(() => {
this.filterResults();
}, 500);
this.debounceFilter = _.debounce(this.onFilterInput.bind(this), 500);
this.unbindEvents();
this.bindEvents();
}
onFilterInput() {
const url = this.filterForm.getAttribute('action');
const data = $(this.filterForm).serialize();
this.filterResults(url, data, 'filter-input');
}
bindEvents() {
this.listFilterElement.addEventListener('input', this.debounceFilter);
}
......@@ -29,7 +33,7 @@ export default class FilterableList {
this.listFilterElement.removeEventListener('input', this.debounceFilter);
}
filterResults(url, data) {
filterResults(url, data, comingFrom) {
const endpoint = url || this.filterForm.getAttribute('action');
const additionalData = data || $(this.filterForm).serialize();
......@@ -42,7 +46,13 @@ export default class FilterableList {
dataType: 'json',
context: this,
complete: this.onFilterComplete,
success: this.onFilterSuccess,
success: (response, textStatus, xhr) => {
if (this.preOnFilterSuccess) {
this.preOnFilterSuccess(comingFrom);
}
this.onFilterSuccess(response, xhr);
},
});
}
......
......@@ -16,12 +16,10 @@ export default {
},
methods: {
onClickRowGroup(e) {
// e.stopPropagation();
e.stopPropagation();
// Skip for buttons
if (e.target.tagName === 'A' ||
(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
} else {
if (!(e.target.tagName === 'A') && !(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
if (this.group.hasSubgroups) {
eventHub.$emit('toggleSubGroups', this.group);
} else {
......
......@@ -33,7 +33,13 @@ export default class GroupFilterableList extends FilterableList {
this.filterResults(this.filterUrl);
}
onFilterSuccess(data, textStatus, xhr) {
preOnFilterSuccess(comingFrom) {
if (comingFrom === 'filter-input') {
this.filterUrl = `${this.filterForm.getAttribute('action')}?${$(this.filterForm).serialize()}`;
}
}
onFilterSuccess(data, xhr) {
super.onFilterSuccess(data);
this.store.setGroups(data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment