Skip to content

Commit

Permalink
Arriver en haut de la page quand on revient sur l’évènement
Browse files Browse the repository at this point in the history
  • Loading branch information
alanzirek committed Mar 4, 2025
1 parent daebd94 commit 2e42b4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 22 additions & 1 deletion sv/static/sv/evenement_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,36 @@ function initializeDetectionTags() {
});
}

function selectZoneTab() {
const params = new URLSearchParams(window.location.search);
if (params.get('tab') === 'zone') {
const tabzone = document.getElementById("tabpanel-zone-panel");
dsfr(tabzone).tabPanel.disclose();
}
}

function updateURLParameters(paramName, paramValue) {
const params = new URLSearchParams(window.location.search);
params.set(paramName, paramValue);
window.history.pushState({}, '', `?${params.toString()}`);
}

document.addEventListener('DOMContentLoaded', function() {

document.documentElement.addEventListener('dsfr.start', () => {
setTimeout(() => {
selectZoneTab();
}, 1000);
});

const viewManager = new ViewManager(evenementViewModeConfig);
viewManager.initialize();

document.querySelectorAll(".no-tab-look .fr-tabs__panel").forEach(element =>{
element.addEventListener('dsfr.disclose', event=>{
const tabId = event.target.getAttribute("id").replace("tabpanel-", "").replace("-panel", "")
showOnlyActionsForDetection(tabId)
window.history.pushState({}, '', `?detection=${tabId}`);
updateURLParameters('detection', tabId);
})
})

Expand Down
4 changes: 2 additions & 2 deletions sv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class FicheZoneDelimiteeCreateView(WithFormErrorsAsMessagesMixin, CreateView):
context_object_name = "fiche"

def get_success_url(self):
return reverse("evenement-details", args=[self.object.evenement.numero]) + "#tabpanel-zone-panel"
return reverse("evenement-details", args=[self.object.evenement.numero]) + "?tab=zone"

def dispatch(self, request, *args, **kwargs):
try:
Expand Down Expand Up @@ -595,7 +595,7 @@ class FicheZoneDelimiteeUpdateView(
context_object_name = "fiche"

def get_success_url(self):
return self.get_object().get_absolute_url() + "#tabpanel-zone-panel"
return self.get_object().get_absolute_url() + "?tab=zone"

def test_func(self) -> bool | None:
return self.get_object().evenement.can_user_access(self.request.user)
Expand Down

0 comments on commit 2e42b4b

Please sign in to comment.