+
{% if perms.recruitment.change_attendanceovertime or request.user|is_reportingmanager %}
-
+
{% endif %}
- {% if perms.recruitment.delete_attendance %}
- {% comment %}
{% endcomment %}
+ {% if perms.attendance.delete_attendanceovertime or request.user|is_reportingmanager %}
+
{% endif %}
@@ -222,25 +233,6 @@
$("#unselectAllInstances").click(function () {
unselectAllHourAcconts();
});
- $(".deletebutton").click(function () {
- var id = $(this).attr("data-id");
- var url = `/attendance/attendance-overtime-delete/${id}/`;
-
- // Create a form element
- var form = $("
");
- form.attr("method", "POST");
- form.attr("action", url);
-
- // Create a hidden input field for the CSRF token
- var csrf_token = $('input[name="csrfmiddlewaretoken"]').val();
- var csrf_input = $('
');
- csrf_input.val(csrf_token);
- form.append(csrf_input);
-
- // Append the form to the body and submit it
- $(document.body).append(form);
- form.submit();
- });
$(".oh-table__sticky-collaspable-sort").click(function (e) {
e.preventDefault();
diff --git a/attendance/templates/attendance/attendance_account/overtime_list.html b/attendance/templates/attendance/attendance_account/overtime_list.html
index 25fb28c37..c254c1463 100644
--- a/attendance/templates/attendance/attendance_account/overtime_list.html
+++ b/attendance/templates/attendance/attendance_account/overtime_list.html
@@ -1,6 +1,17 @@
{% load i18n %}
{% load static %}
{% load basefilters %}
+{% if messages %}
+
+ {% for message in messages %}
+
+ {% endfor %}
+
+{% endif %}
{% include 'filter_tags.html' %}
{% if accounts %}
@@ -80,10 +91,10 @@
{% if perms.attendance.change_attendanceovertime or request.user|is_reportingmanager %}
{% endif %}
- {% if perms.attendance.delete_attendanceovertime or request.user|is_reportingmanager %}
-
diff --git a/attendance/views/views.py b/attendance/views/views.py
index 2db26ac23..1525028ac 100644
--- a/attendance/views/views.py
+++ b/attendance/views/views.py
@@ -695,14 +695,23 @@ def attendance_overtime_delete(request, obj_id):
args:
obj_id : attendance overtime id
"""
+ previous_data = request.GET.urlencode()
+ hx_target = request.META.get("HTTP_HX_TARGET", None)
try:
- AttendanceOverTime.objects.get(id=obj_id).delete()
- messages.success(request, _("Hour account deleted."))
+ attendance = AttendanceOverTime.objects.get(id=obj_id)
+ attendance.delete()
+ if hx_target == "ot-table":
+ messages.success(request, _("Hour account deleted."))
except (AttendanceOverTime.DoesNotExist, OverflowError, ValueError):
- messages.error(request, _("Hour account not found"))
+ if hx_target == "ot-table":
+ messages.error(request, _("Hour account not found"))
except ProtectedError:
- messages.error(request, _("You cannot delete this hour account"))
- return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
+ if hx_target == "ot-table":
+ messages.error(request, _("You cannot delete this hour account"))
+ if hx_target and hx_target == "ot-table":
+ return redirect(f"/attendance/attendance-overtime-search?{previous_data}")
+ elif hx_target:
+ return HttpResponse()
@login_required