From 55ee22a2f7588164d8650c8c2049a0ac3414299c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Wed, 2 Oct 2024 15:39:21 +0200 Subject: [PATCH] adapt siae activities list and delete modal to dsfr --- lemarche/static/js/siae_activity_delete.js | 45 ++++++----- .../_siae_activity_delete_modal.html | 59 +++++++++----- .../dashboard/siae_edit_activities.html | 19 ++--- .../templates/siaes/_siae_activity_card.html | 81 ++++++++++--------- 4 files changed, 117 insertions(+), 87 deletions(-) diff --git a/lemarche/static/js/siae_activity_delete.js b/lemarche/static/js/siae_activity_delete.js index 11821fbfc..118e730db 100644 --- a/lemarche/static/js/siae_activity_delete.js +++ b/lemarche/static/js/siae_activity_delete.js @@ -1,23 +1,30 @@ -document.addEventListener("DOMContentLoaded", function() { - $('#siae_activity_delete_modal').on('show.bs.modal', function (event) { - // Button that triggered the modal - var button = $(event.relatedTarget); +document.addEventListener('alpine:init', function () { + Alpine.data('activityItem', () => ({ + siaeSlug: null, + siaeActivityId: null, + siaeActivityNameDisplay: null, - // Extract info from data-* attributes - var siaeId = button.data('siae-id'); - var siaeSlug = button.data('siae-slug'); - var siaeActivityId = button.data('siae-activity-id'); - var siaeActivityNameDisplay = button.data('siae-activity-name-display'); + initOptions(siaeSlug, siaeActivityId, siaeActivityNameDisplay) { + this.siaeSlug = siaeSlug; + this.siaeActivityId = siaeActivityId; + this.siaeActivityNameDisplay = siaeActivityNameDisplay; + }, + remove() { + // Update the modal's content + // - siae activity name display + // - edit the form action url + // - open the modal + let modalID = 'siae_activity_delete_modal'; + let modal = document.querySelector(`#${modalID}`); + let modalForm = modal.querySelector('form'); + if (modal.querySelector('#siae-activity-name-display')) { + modal.querySelector('#siae-activity-name-display').textContent = this.siaeActivityNameDisplay; + } + let formActionUrl = modalForm.getAttribute('data-action'); + modalForm.setAttribute('action', formActionUrl.replace('siae-slug-to-replace', this.siaeSlug).replace('siae-activity-id-to-replace', this.siaeActivityId)); - // Update the modal's content - // - siae name display - // - edit the form action url - var modal = document.querySelector('#siae_activity_delete_modal'); - var modalForm = modal.querySelector('form'); - if (modal.querySelector('#siae-activity-name-display')) { - modal.querySelector('#siae-activity-name-display').textContent = siaeActivityNameDisplay; + const modalDialog = document.getElementById(modalID); + dsfr(modalDialog).modal.disclose(); } - var formActionUrl = modalForm.getAttribute('action'); - modalForm.setAttribute('action', formActionUrl.replace('siae-slug-to-replace', siaeSlug).replace('siae-activity-id-to-replace', siaeActivityId)); - }); + })); }); diff --git a/lemarche/templates/dashboard/_siae_activity_delete_modal.html b/lemarche/templates/dashboard/_siae_activity_delete_modal.html index a6621ff61..301df3e10 100644 --- a/lemarche/templates/dashboard/_siae_activity_delete_modal.html +++ b/lemarche/templates/dashboard/_siae_activity_delete_modal.html @@ -1,23 +1,42 @@ -