planning_controller.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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('.period-controller');
  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. });
  36. this.showAll.dataset.action = "hide";
  37. this.showAll.innerHTML = 'Cacher les autres périodes';
  38. this.arrows.forEach(arrow => { console.log(arrow); arrow.classList.add('is-hidden') });
  39. } else {
  40. this.containers.forEach(container => {
  41. if (container.id === this.showAll.dataset.store) {
  42. container.classList.remove('is-hidden');
  43. } else {
  44. container.classList.add('is-hidden');
  45. }
  46. this.arrows.forEach(arrow => { arrow.classList.remove('is-hidden') });
  47. });
  48. this.showAll.dataset.action = "show";
  49. this.showAll.innerHTML = 'Afficher toutes les périodes à la suite';
  50. }
  51. }
  52. }