From 60bd8073ee20b7343a8457a04cc7e40d2e5005bb Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 17 Dec 2025 14:29:22 +0000 Subject: [PATCH] Refactor global leave legend to include back navigation and improve loading messages --- .../templates/rota/leaves_global.html | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/djangorota/djangorota/templates/rota/leaves_global.html b/djangorota/djangorota/templates/rota/leaves_global.html index 798dbe6..d9b5736 100644 --- a/djangorota/djangorota/templates/rota/leaves_global.html +++ b/djangorota/djangorota/templates/rota/leaves_global.html @@ -15,10 +15,19 @@

View all leave requests across workers. Choose a rota to scope the calendar, or select "All rotas" to see everything. Click and drag to select dates to open the leave form (you'll need to choose workers in the modal).

-
- Legend: - Existing leave - Selected range +
+
+
Legend:
+
+ {% if selected_rota_id %} + Back to rota + {% endif %} +
+
+
+ Existing leave + Selected range +
@@ -48,26 +57,34 @@ }catch(e){ initialRota = null; } window.initCalendar('calendar', { leaves: leaves, leavesUrl: leavesUrlBase, rotaId: initialRota, requestUrl: '{% url "rota:request_leave" %}', mode: container.dataset.mode || 'inline' }); function refreshLegendFor(id){ - const legend = document.getElementById('rota-worker-legend'); - if(!legend) return; - if(!id){ legend.innerText = 'Showing leave for all rotas.'; return; } - legend.innerText = 'Loading legend…'; + const globalLegendContent = document.getElementById('global-legend-content'); + if(!globalLegendContent) return; + if(!id){ + globalLegendContent.innerHTML = ' Existing leave' + + ' Selected range'; + return; + } + globalLegendContent.innerText = 'Loading legend…'; fetch(leavesUrlBase + '?rota_id=' + encodeURIComponent(id), {credentials:'same-origin'}).then(r=>r.json()).then(data=>{ const byWorker = {}; (data.leaves||[]).forEach(l=>{ if(l.worker_id){ byWorker[l.worker_id] = {name:l.reason, color:l.color}; } }); - if(Object.keys(byWorker).length===0){ legend.innerText = 'No workers with leaves in this rota.'; return; } - legend.innerHTML = Object.entries(byWorker).map(([id,info])=> `
${info.name}
`).join(''); - }).catch(e=>{ legend.innerText = 'Unable to load legend'; console.debug(e); }); + if(Object.keys(byWorker).length===0){ + globalLegendContent.innerText = 'No workers with leaves in this rota.'; + return; + } + const workerHtml = Object.entries(byWorker).map(([id,info])=> `
${info.name}
`).join(''); + globalLegendContent.innerHTML = workerHtml + ' Selected range'; + }).catch(e=>{ globalLegendContent.innerText = 'Unable to load legend'; console.debug(e); }); } // Refresh legend for the initially selected rota (or show all rotas) - refreshLegendFor(initialRota); + // Ensure the legend element exists (script is before the legend markup) + if(document.readyState === 'loading'){ + document.addEventListener('DOMContentLoaded', function(){ refreshLegendFor(initialRota); }); + } else { + refreshLegendFor(initialRota); + } })(); -
-

Workers on this rota

-
-
Select a rota to show its workers.
-
-
+ {# Consolidated legend above replaces the separate 'Workers on this rota' box #} {% endblock %}