[UPDT] BIOMETRIC: Updated biometric form toggle functions in cbv

This commit is contained in:
Horilla
2025-10-23 17:29:51 +05:30
parent 11f331331b
commit 0ad1fbf782
5 changed files with 79 additions and 48 deletions

View File

@@ -69,6 +69,7 @@ class BiometricCardView(HorillaCardView):
model = BiometricDevices
filter_class = BiometricDeviceFilter
custom_empty_template = "biometric/empty_view_biometric.html"
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
@@ -91,6 +92,8 @@ class BiometricCardView(HorillaCardView):
hx-post="{get_archive_url}"
class="oh-dropdown__link"
hx-target="#listContainer"
hx-swap="none"
hx-on-htmx-after-request="$('.reload-record').click()"
""",
},
{
@@ -100,6 +103,8 @@ class BiometricCardView(HorillaCardView):
hx-post="{get_delete_url}"
class="oh-dropdown__link oh-dropdown__link--danger"
hx-target="#biometricDeviceList"
hx-swap="none"
hx-on-htmx-after-request="$('.reload-record').click()"
""",
},
]
@@ -142,6 +147,17 @@ class BiometricCardView(HorillaCardView):
),
]
def get_queryset(self):
queryset = super().get_queryset()
active = (
True
if self.request.GET.get("is_active", True)
in ["unknown", "True", "true", True]
else False
)
queryset = queryset.filter(is_active=active)
return queryset
@method_decorator(login_required, name="dispatch")
@method_decorator(

View File

@@ -215,7 +215,7 @@ class BiometricDevices(HorillaModel):
"""
This method to get update url
"""
url = reverse_lazy("biometric-device-edit", kwargs={"device_id": self.pk})
url = reverse_lazy("biometric-device-edit", kwargs={"pk": self.pk})
return url
def get_archive_url(self):

View File

@@ -59,15 +59,9 @@
</span>
</div> {% endcomment %}
<div id="biometricDeviceList">
{% if devices %}
<div class="oh-wrapper" hx-get="{% url "biometric-card-view" %}?is_active=True" hx-trigger="load" id="listContainer">
</div>
{% comment %} {% include 'biometric/card_biometric_devices.html' %} {% endcomment %}
{% else %}
{% include 'biometric/empty_view_biometric.html' %}
{% endif %}
<div class="oh-wrapper" hx-get="{% url "biometric-card-view" %}?is_active=True" hx-trigger="load" id="listContainer">
</div>
</div>
<div class="oh-modal" id="BiometricDeviceModal" role="dialog" aria-labelledby="BiometricDeviceModal"
aria-hidden="true">

View File

@@ -1,46 +1,68 @@
<div>
{% include "generic/horilla_form.html" %}
</div>
<div>{% include "generic/horilla_form.html" %}</div>
<style>
#id_machine_ip_parent_div,
#id_port_parent_div,
#id_cosec_username_parent_div,
#id_anviz_request_id_parent_div,
#id_zk_password_parent_div,
#id_bio_username_parent_div,
#id_bio_password_parent_div,
#id_api_url_parent_div,
#id_api_key_parent_div,
#id_api_secret_parent_div,
#id_cosec_username_parent_div,
#id_anviz_request_id_parent_div,
#id_api_token_parent_div,
#id_api_expires_parent_div,
#id_is_live_parent_div,
#id_last_fetch_date_parent_div,
#id_last_fetch_time_parent_div,
#id_cosec_password_parent_div {
display: none;
display: none;
}
</style>
</style>
<script>
$('#id_machine_type_parent_div').on('change', function() {
var selectedOption = $(this).find('option:selected').text();
if (selectedOption === 'ZKTeco Biometric') {
$("#id_machine_ip_parent_div, #id_port_parent_div").show();
function machineTypeChange(selectElement) {
var machineType = selectElement.val();
var allElements = [
"#id_zk_password_parent_div",
"#id_machine_ip_parent_div",
"#id_bio_username_parent_div",
"#id_bio_password_parent_div",
"#id_port_parent_div",
"#id_api_url_parent_div",
"#id_api_key_parent_div",
"#id_api_secret_parent_div",
"#id_anviz_request_id_parent_div",
]
// Hide all elements initially
$(allElements.join(', ')).hide();
// Show relevant elements based on the selected machine type
switch (machineType) {
case "anviz":
$("input[name='api_url']").val("");
$("#id_api_url_parent_div, #id_api_key_parent_div, #id_api_secret_parent_div, #id_anviz_request_id_parent_div").show();
break;
case "zk":
$("#id_zk_password_parent_div, #id_machine_ip_parent_div, #id_port_parent_div").show();
break;
case "cosec":
case "dahua":
$("#id_machine_ip_parent_div, #id_bio_username_parent_div, #id_bio_password_parent_div, #id_port_parent_div").show();
break;
case "etimeoffice":
$("#id_api_url_parent_div, #id_bio_username_parent_div, #id_bio_password_parent_div").show();
if (!$("input[name='api_url']").val()) {
$("input[name='api_url']").val("https://api.etimeoffice.com/api/");
}
break;
default:
// No elements need to be shown for unknown machine types
break;
}
else {
$("#id_machine_ip_parent_div, #id_port_parent_div").hide();
}
if (selectedOption === 'Anviz Biometric'){
$("#id_anviz_request_id_parent_div, #id_api_url_parent_div, #id_api_key_parent_div, #id_api_secret_parent_div").show();
}
else {
$("#id_anviz_request_id_parent_div, #id_api_url_parent_div, #id_api_key_parent_div, #id_api_secret_parent_div").hide();
}
if (selectedOption === 'Matrix COSEC Biometric'){
$("#id_machine_ip_parent_div,#id_port_parent_div, #id_cosec_username_parent_div,#id_cosec_password_parent_div").show();
}
else {
$("#id_cosec_username_parent_div,#id_cosec_password_parent_div").hide();
}
});
}
$(document).ready(function (e) {
$('select[name="machine_type"]').change();
@@ -49,7 +71,7 @@
passwordField.wrap('<div class="password-wrapper" style="position: relative;"></div>');
var button = $(
'<button type="button" class="oh-btn oh-btn--transparent oh-password-input--toggle" style="position: absolute; right: 5px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer;">' +
'<button type="button" class="oh-password-input--toggle" style="position: absolute; right: 10px; top: 40%; transform: translateY(-50%); background: none; border: none; cursor: pointer;">' +
'<ion-icon class="oh-passowrd-input__show-icon" title="Show Password" name="eye-outline"></ion-icon>' +
'<ion-icon class="oh-passowrd-input__hide-icon d-none" title="Hide Password" name="eye-off-outline"></ion-icon>' +
'</button>'
@@ -60,7 +82,6 @@
'padding-right': '30px'
});
$(".oh-password-input--toggle").click(function () {
var passwordInput = $(this).prev('input[name="cosec_password"]');
var showIcon = $(this).find(".oh-passowrd-input__show-icon");

View File

@@ -79,16 +79,16 @@ urlpatterns = [
views.biometric_device_bulk_fetch_logs,
name="biometric-device-bulk-fetch-logs",
),
path(
"biometric-device-add",
views.biometric_device_add,
name="biometric-device-add",
),
path(
"biometric-device-edit/<uuid:device_id>/",
views.biometric_device_edit,
name="biometric-device-edit",
),
# path(
# "biometric-device-add",
# views.biometric_device_add,
# name="biometric-device-add",
# ),
# path(
# "biometric-device-edit/<uuid:device_id>/",
# views.biometric_device_edit,
# name="biometric-device-edit",
# ),
path(
"biometric-device-delete/<uuid:device_id>/",
views.biometric_device_delete,