diff --git a/djangorota/djangorota/templates/rota/leaves_global.html b/djangorota/djangorota/templates/rota/leaves_global.html
index f9ab44b..edf254f 100644
--- a/djangorota/djangorota/templates/rota/leaves_global.html
+++ b/djangorota/djangorota/templates/rota/leaves_global.html
@@ -8,11 +8,19 @@
View all leave requests across workers. Click and drag to select dates to open the leave form (you'll need to choose a worker in the modal).
- {% if request.GET.rota_id %}
- Showing leaves for rota id {{ request.GET.rota_id }}.
- {% endif %}
+ 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).
@@ -37,34 +45,43 @@
} catch (e) {
console.debug('Unable to parse embedded leaves JSON', e);
}
- // Provide a leavesUrl so the calendar will fetch the authoritative all-leaves list
- // Pass rota_id if present in the querystring so the server filters to rota workers.
- const rotaParam = new URLSearchParams(window.location.search).get('rota_id');
- let leavesUrl = '{% url "rota:leaves_global_json" %}';
- if(rotaParam) leavesUrl += '?rota_id=' + encodeURIComponent(rotaParam);
- window.initCalendar('calendar', { leaves: leaves, leavesUrl: leavesUrl, requestUrl: '{% url "rota:request_leave" %}', mode: container.dataset.mode || 'inline' });
- })();
-
+ // Base URL for leaves JSON
+ let leavesUrlBase = '{% url "rota:leaves_global_json" %}';
+ // Read initial rota selection provided by the view (if any)
+ const initialRota = {% if selected_rota_id %} '{{ selected_rota_id }}' {% else %} null {% endif %};
+ window.initCalendar('calendar', { leaves: leaves, leavesUrl: leavesUrlBase, rotaId: initialRota, requestUrl: '{% url "rota:request_leave" %}', mode: container.dataset.mode || 'inline' });
- {% if request.GET.rota_id %}
-
-
Workers on this rota
-
-
-
- {% endif %}
+ }
+ if(selector){
+ selector.addEventListener('change', function(){
+ const v = selector.value || null;
+ try{ const cal = window._calendars && window._calendars['calendar']; if(cal && typeof cal.setRotaId === 'function'){ cal.setRotaId(v); } }
+ catch(e){ console.debug('Unable to set rotaId on calendar', e); }
+ refreshLegendFor(v);
+ });
+ // initial legend
+ refreshLegendFor(initialRota);
+ }
+ })();
+
+
+
+
Workers on this rota
+
+
Select a rota to show its workers.
+
+
{% endblock %}
diff --git a/djangorota/djangorota/templates/rota/rota_detail.html b/djangorota/djangorota/templates/rota/rota_detail.html
index e13454c..0d557b6 100644
--- a/djangorota/djangorota/templates/rota/rota_detail.html
+++ b/djangorota/djangorota/templates/rota/rota_detail.html
@@ -14,7 +14,7 @@
diff --git a/djangorota/rota/urls.py b/djangorota/rota/urls.py
index 4029fb5..3e83254 100644
--- a/djangorota/rota/urls.py
+++ b/djangorota/rota/urls.py
@@ -22,6 +22,10 @@ urlpatterns = [
path("worker/settings/token/
/", views.worker_settings_token, name="worker_settings_token"),
path("leaves/all/", views.leaves_global, name="leaves_global"),
path("leaves/all.json", views.leaves_global_json, name="leaves_global_json"),
+ # Rota-scoped variants which render the same views but with rota_id supplied
+ path("rota//leaves/all/", views.leaves_global, name="leaves_global_rota"),
+ path("rota//leaves/all.json", views.leaves_global_json, name="leaves_global_json_rota"),
+ path("rota//leave/select_workers/", views.select_workers_modal, name="select_workers_modal_rota"),
path("leave/select_workers/", views.select_workers_modal, name="select_workers_modal"),
path("leave/apply_multi/", views.apply_leave_multi, name="apply_leave_multi"),
path("leave//delete/", views.leave_delete, name="leave_delete"),
diff --git a/djangorota/rota/views.py b/djangorota/rota/views.py
index 1528e5a..21ef01c 100644
--- a/djangorota/rota/views.py
+++ b/djangorota/rota/views.py
@@ -1039,12 +1039,12 @@ def leaves_json(request, worker_id):
return JsonResponse({'leaves': data})
-def leaves_global_json(request):
+def leaves_global_json(request, rota_id=None):
"""Return JSON list of all leave ranges across all workers."""
from .models import Leave
# Optionally filter by rota_id (provided as query param) so the global
# calendar can be scoped to a particular rota's workers.
- rota_id = request.GET.get('rota_id')
+ rota_id = request.GET.get('rota_id') if rota_id is None else rota_id
qs = Leave.objects.select_related('worker')
if rota_id:
try:
@@ -1078,22 +1078,23 @@ def leaves_global_json(request):
return JsonResponse({'leaves': data})
-def leaves_global(request):
+def leaves_global(request, rota_id=None):
"""Page showing a global calendar with all leave requests."""
# Provide an empty JSON payload initially; the calendar will fetch the authoritative list
leaves_json = '[]'
- return render(request, 'rota/leaves_global.html', {'leaves_json': leaves_json})
+ selected = rota_id if rota_id is not None else request.GET.get('rota_id')
+ return render(request, 'rota/leaves_global.html', {'leaves_json': leaves_json, 'rotas': RotaSchedule.objects.all().order_by('name'), 'selected_rota_id': selected})
@require_http_methods(["GET"])
-def select_workers_modal(request):
+def select_workers_modal(request, rota_id=None):
"""Return an HTMX modal partial that lists workers to apply a selected leave range to.
Query params: start_date, end_date, rota_id (optional)
"""
start_date = request.GET.get('start_date')
end_date = request.GET.get('end_date')
- rota_id = request.GET.get('rota_id')
+ rota_id = request.GET.get('rota_id') if rota_id is None else rota_id
workers = Worker.objects.all()
if rota_id:
try: