Skip to content

Commit

Permalink
added IommiBase.getContainer in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
berycz authored and boxed committed Feb 28, 2024
1 parent ff963f1 commit 74e0120
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions iommi/static/js/iommi.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ class IommiBase {
window.history.replaceState(null, null, `${window.location.pathname}?${params.toString()}`);
}

/**
* returns iommi table container or null if none found
* @param {Element} element filter form or any other element with data-iommi-id-of-table attribute or any element inside container
* @return {(Element|null)} container element or null
*/
getContainer(element) {
if(element.hasAttribute('data-iommi-id-of-table')) {
return document.querySelector(
`.iommi-table-container[data-iommi-id="${element.getAttribute('data-iommi-id-of-table')}"]`
);
}
return element.closest(".iommi-table-container");
}

debounce(func, wait) {
let timeout;

Expand Down Expand Up @@ -279,9 +293,7 @@ class IommiBase {
}
}

const tableIommiID = form.getAttribute('data-iommi-id-of-table');
const table = document.querySelector(`[data-iommi-id="${tableIommiID}"]`);
const container = table.closest('.iommi-table-container');
const container = this.getContainer(form);

// remove "page" for this table to always jump to the first page after filtering
const paginator = container.querySelector('[data-iommi-page-parameter]');
Expand All @@ -304,10 +316,7 @@ class IommiBase {
}

enhanceFilterForm(form) {
let table = document.querySelector(
`[data-iommi-id="${form.getAttribute('data-iommi-id-of-table')}"]`
)
const container = table.closest('.iommi-table-container');
const container = this.getContainer(form);

form.setAttribute('autocomplete', 'off');
const debouncedPopulate = this.debounce(this.queryPopulate, 400);
Expand Down

0 comments on commit 74e0120

Please sign in to comment.