[UPDT] OFFBOARDING: Offboarding resignation request enable method by adding htmx attributes

This commit is contained in:
Horilla
2024-12-25 12:02:37 +05:30
parent 1479d624c9
commit 65af991745
2 changed files with 33 additions and 11 deletions

View File

@@ -3,15 +3,18 @@
<div class="oh-inner-sidebar-content__header mt-4">
<h2 class="oh-inner-sidebar-content__title">{% trans 'Resignation Request' %}</h2>
</div>
<form hx-get="{% url 'enable-resignation-request' %}" hx-swap="none">
<div class="oh-label__info" for="application_tracking">
<label class="oh-label" for="application_tracking">{% trans "Resignation Request" %}</label>
<span class="oh-info mr-2" title="{% trans "By enabling this normal users can request for their resignationprogress" %}">
</span>
</div>
<div class="oh-switch p-3">
<input type="checkbox"class="oh-switch__checkbox" name="resignation_request" onchange="$(this).closest('form').find('input[type=submit]').click()" {% if enabled_resignation_request %} checked{% endif %} />
</div>
<input type="submit" hidden />
<form hx-get="{% url 'enable-resignation-request' %}" hx-trigger="change from:#enableResignationRequest" hx-swap="afterend"
hx-on-htmx-after-request="reloadMessage(this);">
<div class="oh-label__info" for="application_tracking">
<label class="oh-label" for="application_tracking">{% trans "Resignation Request" %}</label>
<span class="oh-info mr-2"
title="{% trans 'By enabling this normal users can request for their resignation progress' %}">
</span>
</div>
<div class="oh-switch p-3">
<input type="checkbox" class="oh-switch__checkbox" id="enableResignationRequest" name="resignation_request"
{% if enabled_resignation_request %} checked {% endif %} />
</div>
<input type="submit" hidden />
</form>
<div class="oh-inner-sidebar-content__footer"></div>

View File

@@ -13,6 +13,7 @@ from django.utils.translation import gettext_lazy as _
from base.context_processors import intial_notice_period
from base.methods import closest_numbers, eval_validate, paginator_qry, sortby
from base.views import general_settings
from employee.models import Employee
from horilla.decorators import (
hx_request_required,
@@ -928,7 +929,25 @@ def enable_resignation_request(request):
"resignation_request" in request.GET.keys()
)
resignation_request_feature.save()
return HttpResponse("Success")
message_text = (
"enabled" if resignation_request_feature.resignation_request else "disabled"
)
messages.success(
request,
_("Resignation Request setting has been {} successfully.").format(message_text),
)
if request.META.get("HTTP_HX_REQUEST"):
return HttpResponse(
"""
<span hx-trigger="load"
hx-get="/"
hx-swap="outerHTML"
hx-select="#offboardingGenericNav"
hx-target="#offboardingGenericNav">
</span>
"""
)
return redirect(general_settings)
@login_required