diff --git a/assets/admin.js b/assets/admin.js index 5d37a0f..e614706 100644 --- a/assets/admin.js +++ b/assets/admin.js @@ -5,6 +5,7 @@ import TomSelect from "tom-select"; import { RepeatLine } from "./libs/RepeatLine.js"; import { DevisManager } from "./libs/DevisManager.js"; import { initTomSelect } from "./libs/initTomSelect.js"; +import { SearchProduct } from "./libs/SearchProduct.js"; // --- INITIALISATION SENTRY --- Sentry.init({ dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24", @@ -36,6 +37,9 @@ function initAdminLayout() { customElements.define('devis-manager', DevisManager, { extends: 'div' }); } + if (!customElements.get('search-product')) { + customElements.define('search-product', SearchProduct, { extends: 'button' }); + } // Sidebar & UI const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebar-overlay'); diff --git a/assets/libs/SearchProduct.js b/assets/libs/SearchProduct.js new file mode 100644 index 0000000..62e3df3 --- /dev/null +++ b/assets/libs/SearchProduct.js @@ -0,0 +1,143 @@ +export class SearchProduct extends HTMLButtonElement { + constructor() { + super(); + this.allProducts = []; // Stockage local pour la recherche + } + + connectedCallback() { + this.addEventListener('click', () => this.openModal()); + } + + async openModal() { + let modal = document.getElementById('modal-search-product'); + if (!modal) { + modal = this.createModalStructure(); + document.body.appendChild(modal); + this.setupSearchEvent(modal); + } + + modal.classList.remove('hidden'); + const container = modal.querySelector('#results-container'); + const searchInput = modal.querySelector('#modal-search-input'); + + searchInput.value = ''; // Reset recherche + container.innerHTML = '
Appuyez sur Échap pour fermer
+