2026-01-19 17:56:57 +01:00
|
|
|
import './admin.scss';
|
2026-01-15 20:42:55 +01:00
|
|
|
import * as Sentry from "@sentry/browser";
|
|
|
|
|
import * as Turbo from "@hotwired/turbo";
|
2026-01-27 19:35:54 +01:00
|
|
|
|
2026-01-19 17:56:57 +01:00
|
|
|
import { RepeatLine } from "./libs/RepeatLine.js";
|
|
|
|
|
import { DevisManager } from "./libs/DevisManager.js";
|
2026-01-28 10:30:47 +01:00
|
|
|
import { CrmEditor } from "./libs/CrmEditor.js";
|
2026-01-19 17:56:57 +01:00
|
|
|
import { initTomSelect } from "./libs/initTomSelect.js";
|
2026-01-28 12:39:30 +01:00
|
|
|
import { SearchProduct, SearchOptions } from "./libs/SearchProduct.js";
|
|
|
|
|
import { SearchProductDevis, SearchOptionsDevis } from "./libs/SearchProductDevis.js";
|
|
|
|
|
import { SearchProductFormule, SearchOptionsFormule } from "./libs/SearchProductFormule.js";
|
2026-01-29 09:31:02 +01:00
|
|
|
import PlaningLogestics from "./libs/PlaningLogestics.js";
|
2026-01-28 12:39:30 +01:00
|
|
|
|
|
|
|
|
// --- CONFIGURATION SENTRY ---
|
2026-01-15 20:42:55 +01:00
|
|
|
Sentry.init({
|
|
|
|
|
dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24",
|
|
|
|
|
tunnel: "/sentry-tunnel",
|
2026-01-28 12:39:30 +01:00
|
|
|
integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
|
2026-01-15 20:42:55 +01:00
|
|
|
tracesSampleRate: 1.0,
|
|
|
|
|
replaysSessionSampleRate: 0.1,
|
|
|
|
|
replaysOnErrorSampleRate: 1.0
|
|
|
|
|
});
|
2026-01-15 18:51:17 +01:00
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
/**
|
|
|
|
|
* Enregistre les Custom Elements de manière groupée
|
|
|
|
|
*/
|
|
|
|
|
const registerCustomElements = () => {
|
|
|
|
|
const elements = [
|
|
|
|
|
{ name: 'repeat-line', class: RepeatLine, extends: 'div' },
|
|
|
|
|
{ name: 'devis-manager', class: DevisManager, extends: 'div' },
|
|
|
|
|
{ name: 'search-product', class: SearchProduct, extends: 'button' },
|
|
|
|
|
{ name: 'search-productformule', class: SearchProductFormule, extends: 'button' },
|
|
|
|
|
{ name: 'search-optionsformule', class: SearchOptionsFormule, extends: 'button' },
|
2026-01-29 09:31:02 +01:00
|
|
|
{ name: 'planing-logestics', class: PlaningLogestics },
|
2026-01-28 12:39:30 +01:00
|
|
|
{ name: 'search-options', class: SearchOptions, extends: 'button' },
|
|
|
|
|
{ name: 'search-productdevis', class: SearchProductDevis, extends: 'button' },
|
|
|
|
|
{ name: 'search-optionsdevis', class: SearchOptionsDevis, extends: 'button' },
|
|
|
|
|
{ name: 'crm-editor', class: CrmEditor, extends: 'textarea' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
elements.forEach(el => {
|
|
|
|
|
if (!customElements.get(el.name)) {
|
2026-01-29 09:31:02 +01:00
|
|
|
if(el.extends != undefined) {
|
|
|
|
|
customElements.define(el.name, el.class, { extends: el.extends });
|
|
|
|
|
} else {
|
|
|
|
|
customElements.define(el.name, el.class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Preview d'image optimisée
|
|
|
|
|
*/
|
2026-01-28 09:08:53 +01:00
|
|
|
function initImagePreview() {
|
|
|
|
|
const input = document.getElementById('product_image_input');
|
|
|
|
|
const preview = document.getElementById('product-image-preview');
|
|
|
|
|
const placeholder = document.getElementById('product-image-placeholder');
|
|
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
input?.addEventListener('change', ({ target }) => {
|
|
|
|
|
const file = target.files[0];
|
|
|
|
|
if (!file) return;
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = (e) => {
|
|
|
|
|
if (preview) {
|
|
|
|
|
preview.src = e.target.result;
|
|
|
|
|
preview.classList.remove('hidden');
|
2026-01-28 09:08:53 +01:00
|
|
|
}
|
2026-01-28 12:39:30 +01:00
|
|
|
placeholder?.classList.add('hidden');
|
|
|
|
|
};
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
});
|
2026-01-28 09:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:58:57 +01:00
|
|
|
/**
|
2026-01-28 12:39:30 +01:00
|
|
|
* Filtrage dynamique (Contrats, Devis, etc.)
|
2026-01-22 15:58:57 +01:00
|
|
|
*/
|
|
|
|
|
function initDynamicSearch() {
|
|
|
|
|
const searchInput = document.getElementById('searchContrat');
|
|
|
|
|
const listContainer = document.getElementById('contratsList');
|
2026-01-19 17:56:57 +01:00
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
searchInput?.addEventListener('input', (e) => {
|
|
|
|
|
const filter = e.target.value.toLowerCase();
|
|
|
|
|
const cards = listContainer?.querySelectorAll('.contrat-card');
|
|
|
|
|
|
|
|
|
|
cards?.forEach(card => {
|
|
|
|
|
const isVisible = card.textContent.toLowerCase().includes(filter);
|
|
|
|
|
card.classList.toggle('hidden', !isVisible);
|
|
|
|
|
card.style.opacity = isVisible ? "1" : "0";
|
|
|
|
|
card.style.transform = isVisible ? "scale(1)" : "scale(0.95)";
|
2026-01-22 15:58:57 +01:00
|
|
|
});
|
2026-01-28 12:39:30 +01:00
|
|
|
});
|
2026-01-22 15:58:57 +01:00
|
|
|
}
|
2026-01-28 12:39:30 +01:00
|
|
|
|
2026-01-15 20:35:46 +01:00
|
|
|
/**
|
2026-01-28 12:39:30 +01:00
|
|
|
* Gestion UI : Sidebar, Submenus et Flash messages
|
2026-01-15 20:35:46 +01:00
|
|
|
*/
|
2026-01-28 12:39:30 +01:00
|
|
|
function initUI() {
|
|
|
|
|
// Sidebar
|
|
|
|
|
const elements = {
|
|
|
|
|
sidebar: document.getElementById('sidebar'),
|
|
|
|
|
overlay: document.getElementById('sidebar-overlay'),
|
|
|
|
|
toggleBtn: document.getElementById('sidebar-toggle'),
|
|
|
|
|
settingsToggle: document.getElementById('settings-toggle'),
|
|
|
|
|
settingsSubmenu: document.getElementById('settings-submenu')
|
|
|
|
|
};
|
2026-01-19 17:56:57 +01:00
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
const toggleSidebar = () => {
|
|
|
|
|
elements.sidebar?.classList.toggle('-translate-x-full');
|
|
|
|
|
elements.overlay?.classList.toggle('hidden');
|
|
|
|
|
};
|
2026-01-15 18:51:17 +01:00
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
elements.toggleBtn?.addEventListener('click', toggleSidebar);
|
|
|
|
|
elements.overlay?.addEventListener('click', toggleSidebar);
|
2026-01-15 18:51:17 +01:00
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
// Settings Submenu
|
|
|
|
|
elements.settingsToggle?.addEventListener('click', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const isHidden = elements.settingsSubmenu?.classList.toggle('hidden');
|
|
|
|
|
localStorage.setItem('admin_settings_open', !isHidden);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Flash Messages (Délégation pour performance)
|
|
|
|
|
document.querySelectorAll('.flash-message').forEach(flash => {
|
2026-01-15 18:51:17 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
flash.classList.add('opacity-0', 'translate-x-10');
|
|
|
|
|
setTimeout(() => flash.remove(), 500);
|
2026-01-19 17:56:57 +01:00
|
|
|
}, 5000);
|
2026-01-15 18:51:17 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
// --- INITIALISATION ---
|
2026-01-19 17:56:57 +01:00
|
|
|
document.addEventListener('turbo:load', () => {
|
2026-01-28 12:39:30 +01:00
|
|
|
registerCustomElements();
|
|
|
|
|
initDynamicSearch();
|
|
|
|
|
initImagePreview();
|
|
|
|
|
initUI();
|
|
|
|
|
initTomSelect();
|
2026-01-19 17:56:57 +01:00
|
|
|
});
|
|
|
|
|
|
2026-01-28 12:39:30 +01:00
|
|
|
// Confirmation de suppression Turbo
|
2026-01-15 18:51:17 +01:00
|
|
|
document.addEventListener("turbo:click", (event) => {
|
2026-01-28 12:39:30 +01:00
|
|
|
const attr = event.target.closest("[data-turbo-confirm]")?.getAttribute("data-turbo-confirm");
|
|
|
|
|
if (attr && !confirm(attr)) {
|
2026-01-15 18:51:17 +01:00
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
});
|