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
+
+
+
+ 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 %}