.
This commit is contained in:
@@ -17,9 +17,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<h2 class="subtitle">Historic runs</h2>
|
<details class="box">
|
||||||
<div class="box">
|
<summary class="subtitle" style="cursor:pointer; outline:none;">Historic runs</summary>
|
||||||
<div style="margin-bottom:0.5em;">
|
<div style="margin-bottom:0.5em; margin-top:0.5em;">
|
||||||
<form method="post" action="{% url 'rota:rota_runs_clear' rota.id %}" style="display:inline" onsubmit="return confirm('Delete all historic runs for this rota? This cannot be undone.')">
|
<form method="post" action="{% url 'rota:rota_runs_clear' rota.id %}" style="display:inline" onsubmit="return confirm('Delete all historic runs for this rota? This cannot be undone.')">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button class="button is-danger is-light is-small" type="submit">Clear all runs</button>
|
<button class="button is-danger is-light is-small" type="submit">Clear all runs</button>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<li>No previous runs</li>
|
<li>No previous runs</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
|||||||
@@ -46,16 +46,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% json_script leaves as worker_leaves_json %}
|
||||||
<script src="{% static 'js/calendar.js' %}"></script>
|
<script src="{% static 'js/calendar.js' %}"></script>
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
const container = document.getElementById('calendar');
|
const container = document.getElementById('calendar');
|
||||||
if(!container) return;
|
if(!container) return;
|
||||||
const leaves = [
|
let leaves = [];
|
||||||
{% for l in worker.leaves.all %}
|
try {
|
||||||
{start:'{{ l.start_date|date:"Y-m-d" }}', end:'{{ l.end_date|date:"Y-m-d" }}'},
|
const raw = document.getElementById('worker_leaves_json');
|
||||||
{% endfor %}
|
if (raw) {
|
||||||
];
|
leaves = JSON.parse(raw.textContent || raw.innerText || '[]');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.debug('Unable to parse embedded leaves JSON', e);
|
||||||
|
}
|
||||||
window.initCalendar('calendar', { workerId: container.dataset.workerId, leaves: leaves, requestUrl: '{% url "rota:request_leave" %}', leavesUrl: '{% url "rota:worker_leaves_json" worker.id %}', mode: container.dataset.mode || 'inline' });
|
window.initCalendar('calendar', { workerId: container.dataset.workerId, leaves: leaves, requestUrl: '{% url "rota:request_leave" %}', leavesUrl: '{% url "rota:worker_leaves_json" worker.id %}', mode: container.dataset.mode || 'inline' });
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -320,7 +320,23 @@ def worker_detail(request, worker_id):
|
|||||||
else:
|
else:
|
||||||
form = LeaveForm()
|
form = LeaveForm()
|
||||||
|
|
||||||
return render(request, "rota/worker_detail.html", {"worker": worker, "form": form})
|
# Build a JSON-serializable list of leaves for the calendar widget to consume
|
||||||
|
leaves = []
|
||||||
|
try:
|
||||||
|
for leave in worker.leaves.all():
|
||||||
|
try:
|
||||||
|
s = leave.start_date.isoformat()
|
||||||
|
except Exception:
|
||||||
|
s = str(leave.start_date)
|
||||||
|
try:
|
||||||
|
e = leave.end_date.isoformat()
|
||||||
|
except Exception:
|
||||||
|
e = str(leave.end_date)
|
||||||
|
leaves.append({"start": s, "end": e})
|
||||||
|
except Exception:
|
||||||
|
leaves = []
|
||||||
|
|
||||||
|
return render(request, "rota/worker_detail.html", {"worker": worker, "form": form, "leaves": leaves})
|
||||||
|
|
||||||
|
|
||||||
@require_http_methods(["GET", "POST"])
|
@require_http_methods(["GET", "POST"])
|
||||||
|
|||||||
Reference in New Issue
Block a user