diff --git a/assets/datagrid/assets/datagrid.css b/assets/datagrid/assets/datagrid.css index f23db8f..4e7fd3e 100644 --- a/assets/datagrid/assets/datagrid.css +++ b/assets/datagrid/assets/datagrid.css @@ -5,7 +5,7 @@ overflow: hidden; } -.datagrid--slide-toggle:not(.active) { +.datagrid--slide-toggle:not(.is-active) { display: none; } @@ -235,22 +235,23 @@ .datagrid table tbody tr.ui-sortable-helper { display: table } - +/* .datagrid table tbody tr.row-item-detail { display: none } - -.datagrid table tbody tr.row-item-detail.toggled { +*/ +.datagrid table tbody tr.row-item-detail.toggled, +.datagrid table tbody tr.row-item-detail.is-active { display: table-row } - +/* .datagrid table tbody tr.row-item-detail .item-detail-content { display: none } .datagrid table tbody tr.row-item-detail-helper { display: none -} +}*/ .datagrid table tbody tr .datagrid-inline-edit .form-control { margin: -3px; diff --git a/assets/datagrid/datagrids.ts b/assets/datagrid/datagrids.ts index e6d006e..2240727 100644 --- a/assets/datagrid/datagrids.ts +++ b/assets/datagrid/datagrids.ts @@ -72,7 +72,7 @@ export const createFullDatagrids = (ajax: Ajax, _options: Partial("[data-toggle-detail-grid]") .forEach((el) => { - const toggleName = el.getAttribute("data-toggle-detail")!; - const fullName = el.getAttribute("data-toggle-detail-grid-fullname"); - const row = datagrid.el.querySelector( - `.item-detail-${fullName}-id-${toggleName}` - ); + if (el.getAttribute("data-toggle-detail-grid") !== datagrid.name) return; + const toggleId = el.getAttribute("data-toggle-detail")!; - if (row && row.querySelector(".item-detail-content")) { - attachSlideToggle(row); - } + el.addEventListener("click", (e) => { + const contentRow = datagrid.el.querySelector( + `.item-detail-${datagrid.name}-id-${toggleId}` + ); + if (contentRow) { + attachSlideToggle(contentRow, el); + } + }) }); return true; diff --git a/assets/datagrid/types/ajax.d.ts b/assets/datagrid/types/ajax.d.ts index c09269b..1df4939 100644 --- a/assets/datagrid/types/ajax.d.ts +++ b/assets/datagrid/types/ajax.d.ts @@ -25,7 +25,15 @@ export interface DatagridPayload { non_empty_filters?: string[]; } -export type Payload

= P & { +export interface DatagridState { + "grid-page": number | null, + "grid-perPage": number, + // TODO + "grid-sort": any | null, + "grid-filter": any | null +} + +export type Payload

= P & { snippets?: Record; redirect?: string; state: S; diff --git a/assets/datagrid/utils.ts b/assets/datagrid/utils.ts index e48ef1d..bbd60cf 100644 --- a/assets/datagrid/utils.ts +++ b/assets/datagrid/utils.ts @@ -26,7 +26,7 @@ export function window(): ExtendedWindow { return (window ?? {}) as unknown as ExtendedWindow; } -export function slideDown(element: HTMLElement, cb?: () => unknown) { +export function slideDown(element: HTMLElement, cb?: (nextStateShown: boolean) => unknown) { element.classList.add('is-active'); element.style.height = 'auto'; @@ -36,20 +36,23 @@ export function slideDown(element: HTMLElement, cb?: () => unknown) { setTimeout(function () { element.style.height = height; - cb?.(); + cb?.(true); }, 0); } -export function slideUp(element: HTMLElement, cb?: () => unknown) { +export function slideUp(element: HTMLElement, cb?: (nextStateShown: boolean) => unknown) { element.style.height = '0px'; - element.addEventListener('transitionend', () => { - element.classList.remove('is-active'); - cb?.(); - }, { once: true }); + setTimeout( () => { + if (element.classList.contains('is-active')) { + element.classList.remove('is-active'); + cb?.(false); + } + }, 250); // TODO } -export function slideToggle(element: HTMLElement, cb?: () => unknown) { +export function slideToggle(element: HTMLElement, cb?: (nextStateShown: boolean) => unknown) { + console.log("element", element); if (!element.classList.contains('is-active')) { slideDown(element, cb); } else { @@ -57,14 +60,17 @@ export function slideToggle(element: HTMLElement, cb?: () => unknown) { } } -export function attachSlideToggle(element: HTMLElement, cb?: () => unknown) { +export function attachSlideToggle(element: HTMLElement, control: HTMLElement, cb?: (nextStateShown: boolean) => unknown) { if (!element.classList.contains("datagrid--slide-toggle")) { + let sliding = false; element.classList.add("datagrid--slide-toggle"); - slideToggle(element, cb); + slideUp(element, cb); - element.addEventListener('click', () => { - slideToggle(element, cb); + control.addEventListener('click', () => { + if (sliding) return; + sliding = true; + slideToggle(element, () => (sliding = false)); }); } } diff --git a/assets/js/main.js b/assets/js/main.js index 5341c0d..40f086b 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -37,9 +37,7 @@ document.addEventListener("DOMContentLoaded", () => { naja.initialize(); Array.from(document.querySelectorAll('.dropdown')) - .forEach(el => { - console.log(new Dropdown(el)) - }) + .forEach(el => new Dropdown(el)) createDatagrids(new NajaAjax(naja), { datagrid: {