diff --git a/djangorota/djangorota/templates/base.html b/djangorota/djangorota/templates/base.html index 28ed4a4..55428fe 100644 --- a/djangorota/djangorota/templates/base.html +++ b/djangorota/djangorota/templates/base.html @@ -141,6 +141,28 @@ if(window._calendars){ Object.values(window._calendars).forEach(c => c.refreshLeaves && c.refreshLeaves()); } }catch(e){ console.error('leaveUpdated handler', e); } }); + + // As a robustness measure, also listen to HTMX afterRequest and inspect + // the HX-Trigger header. Some flows use hx-swap="none" which may not + // produce an htmx:afterSwap event for #modal; reading the header here + // ensures we still honor closeModal/leaveUpdated triggers. + document.body.addEventListener('htmx:afterRequest', function(evt){ + try{ + const xhr = evt.detail && evt.detail.xhr; + if(!xhr) return; + const trig = xhr.getResponseHeader && xhr.getResponseHeader('HX-Trigger'); + if(!trig) return; + // HX-Trigger may be a JSON string or comma-separated names; handle both + let triggers = []; + try{ triggers = JSON.parse(trig); }catch(e){ triggers = String(trig).split(/\s*,\s*/); } + if(triggers.includes('closeModal')){ + try{ if(window.closeProcRotaModal) window.closeProcRotaModal(); }catch(e){} + } + if(triggers.includes('leaveUpdated')){ + try{ if(window._calendars){ Object.values(window._calendars).forEach(c => c.refreshLeaves && c.refreshLeaves()); } }catch(e){} + } + }catch(e){ console.error('htmx:afterRequest robustness handler', e); } + }); {% block scripts %}{% endblock %} diff --git a/djangorota/djangorota/templates/rota/partials/leave_request_modal.html b/djangorota/djangorota/templates/rota/partials/leave_request_modal.html index 4bb497e..d6ae7b5 100644 --- a/djangorota/djangorota/templates/rota/partials/leave_request_modal.html +++ b/djangorota/djangorota/templates/rota/partials/leave_request_modal.html @@ -7,7 +7,10 @@