planning_controller.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Controller } from '@hotwired/stimulus';
  2. export default class extends Controller {
  3. connect() {
  4. console.log("Stimulus: contrôleur de planning actif");
  5. this.arrows = this.element.querySelectorAll('[data-id]');
  6. this.showAll = this.element.querySelector('[data-store]');
  7. this.containers = document.querySelectorAll('.period-panel');
  8. this.arrows.forEach(arrow => {
  9. arrow.addEventListener('click', (event) => {
  10. event.preventDefault();
  11. this.activatePanel(arrow);
  12. });
  13. });
  14. this.showAll.addEventListener('click', (event)=> {
  15. event.preventDefault();
  16. this.togglePanels();
  17. })
  18. }
  19. activatePanel(selectedPanel) {
  20. const targetId = selectedPanel.dataset.id;
  21. // Affichage du bon bloc
  22. this.containers.forEach(container => {
  23. if (container.id === targetId) {
  24. container.classList.remove('is-hidden');
  25. this.showAll.dataset.store = container.id;
  26. } else {
  27. container.classList.add('is-hidden');
  28. }
  29. });
  30. }
  31. togglePanels() {
  32. if (this.showAll.dataset.action == "show") {
  33. this.containers.forEach(container => {
  34. container.classList.remove('is-hidden');
  35. this.showAll.dataset.action = "hide";
  36. this.showAll.innerHTML = 'Cacher les autres périodes';
  37. });
  38. } else {
  39. this.containers.forEach(container => {
  40. if (container.id === this.showAll.dataset.store) {
  41. container.classList.remove('is-hidden');
  42. } else {
  43. container.classList.add('is-hidden');
  44. }
  45. });
  46. this.showAll.dataset.action = "show";
  47. this.showAll.innerHTML = 'Afficher toutes les périodes à la suite';
  48. }
  49. }
  50. }