From aee92de63f5d960398fd95955e06ffc64908f60c Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 7 Aug 2025 16:34:33 +0530 Subject: [PATCH] [UPDT] BIOMETRIC: Refactor biometric static files to use Django i18n gettext in js --- biometric/static/actions.js | 328 +++++++++++++++--------------------- 1 file changed, 139 insertions(+), 189 deletions(-) diff --git a/biometric/static/actions.js b/biometric/static/actions.js index 7039cff90..631a6bfd9 100644 --- a/biometric/static/actions.js +++ b/biometric/static/actions.js @@ -1,30 +1,3 @@ - -var deleteUsersMessages = { - ar: "هل ترغب حقًا في حذف جميع الحضور المحددة؟", - de: "Möchten Sie wirklich alle ausgewählten Anwesenheiten löschen?", - es: "¿Realmente quieres eliminar todas las asistencias seleccionadas?", - en: "Do you really want to delete all the selected Users?", - fr: "Voulez-vous vraiment supprimer toutes les présences sélectionnées?", -}; -var nousersdeleteMessages = { - ar: "لم يتم تحديد أي صفوف لحذف الحضور.", - de: "Es sind keine Zeilen zum Löschen von Anwesenheiten ausgewählt.", - es: "No se seleccionan filas para eliminar asistencias.", - en: "No rows are selected for deleting users from device.", - fr: "Aucune ligne n'est sélectionnée pour la suppression des présences.", -}; - -function getCurrentLanguageCode(callback) { - $.ajax({ - type: "GET", - url: "/employee/get-language-code/", - success: function (response) { - var languageCode = response.language_code; - callback(languageCode); // Pass the language code to the callback function - }, - }); -} - function selectAllDahuaUsers(element) { var is_checked = $("#allBioEmployee").is(":checked"); if (is_checked) { @@ -33,6 +6,7 @@ function selectAllDahuaUsers(element) { $(".all-bio-employee-row").prop("checked", false); } } + function selectAllETimeOfficeUsers(element) { var is_checked = $("#allBioEmployee").is(":checked"); if (is_checked) { @@ -55,180 +29,156 @@ $(".all-bio-employee-row").change(function (e) { $("#deleteBioUsers").click(function (e) { e.preventDefault(); - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = deleteUsersMessages[languageCode]; - var textMessage = nousersdeleteMessages[languageCode]; - var checkedRows = $(".all-bio-employee-row").filter(":checked"); - var deviceId = $(".all-bio-employee").attr("data-device"); - if (checkedRows.length === 0) { - Swal.fire({ - text: textMessage, - icon: "warning", - confirmButtonText: "Close", - }); - } else { - Swal.fire({ - text: confirmMessage, - icon: "error", - showCancelButton: true, - confirmButtonColor: "#008000", - cancelButtonColor: "#d33", - confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - $("#BiometricDeviceTestModal").toggleClass("oh-modal--show") - $.ajax({ - type: "POST", - url: "/biometric/biometric-users-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - deviceId: deviceId, - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); - } else { - } - }, - }); - } - }); - } - }); + var checkedRows = $(".all-bio-employee-row").filter(":checked"); + var deviceId = $(".all-bio-employee").attr("data-device"); + if (checkedRows.length === 0) { + Swal.fire({ + text: i18nMessages.noRowsSelected, + icon: "warning", + confirmButtonText: i18nMessages.close, + }); + } else { + Swal.fire({ + text: i18nMessages.confirmBulkDelete, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $("#BiometricDeviceTestModal").toggleClass("oh-modal--show") + $.ajax({ + type: "POST", + url: "/biometric/biometric-users-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + deviceId: deviceId, + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); + } else { + } + }, + }); + } + }); + } }); $("#deleteCosecUsers").click(function (e) { e.preventDefault(); - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = deleteUsersMessages[languageCode]; - var textMessage = nousersdeleteMessages[languageCode]; - var checkedRows = $(".all-bio-employee-row").filter(":checked"); - var deviceId = $(".all-bio-employee").attr("data-device"); - if (checkedRows.length === 0) { - Swal.fire({ - text: textMessage, - icon: "warning", - confirmButtonText: "Close", - }); - } else { - Swal.fire({ - text: confirmMessage, - icon: "error", - showCancelButton: true, - confirmButtonColor: "#008000", - cancelButtonColor: "#d33", - confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - $("#BiometricDeviceTestModal").toggleClass("oh-modal--show"); - $.ajax({ - type: "POST", - url: "/biometric/cosec-users-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - deviceId: deviceId, - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); - } else { - } - }, - }); - } - }); - } - }); + var checkedRows = $(".all-bio-employee-row").filter(":checked"); + var deviceId = $(".all-bio-employee").attr("data-device"); + if (checkedRows.length === 0) { + Swal.fire({ + text: i18nMessages.noRowsSelected, + icon: "warning", + confirmButtonText: i18nMessages.close, + }); + } else { + Swal.fire({ + text: i18nMessages.confirmBulkDelete, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $("#BiometricDeviceTestModal").toggleClass("oh-modal--show"); + $.ajax({ + type: "POST", + url: "/biometric/cosec-users-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + deviceId: deviceId, + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); + } else { + } + }, + }); + } + }); + } }); function deleteDahuaUsers(e) { - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = deleteUsersMessages[languageCode]; - var textMessage = nousersdeleteMessages[languageCode]; - var checkedRows = $(".all-bio-employee-row").filter(":checked"); - if (checkedRows.length === 0) { - Swal.fire({ - text: textMessage, - icon: "warning", - confirmButtonText: "Close", - }); - } else { - Swal.fire({ - text: confirmMessage, - icon: "error", - showCancelButton: true, - confirmButtonColor: "#008000", - cancelButtonColor: "#d33", - confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - var hxValue = JSON.stringify(ids); - var bioDeviceID = JSON.stringify($("#allBioEmployee").data("device")) - $("#deleteDahuaUsers").attr("hx-vals", `{"ids":${hxValue},"device_id":${bioDeviceID}}`); - $("#deleteDahuaUsers").click(); - } - }); - } - }); + var checkedRows = $(".all-bio-employee-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: i18nMessages.noRowsSelected, + icon: "warning", + confirmButtonText: i18nMessages.close, + }); + } else { + Swal.fire({ + text: i18nMessages.confirmBulkDelete, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + var hxValue = JSON.stringify(ids); + var bioDeviceID = JSON.stringify($("#allBioEmployee").data("device")) + $("#deleteDahuaUsers").attr("hx-vals", `{"ids":${hxValue},"device_id":${bioDeviceID}}`); + $("#deleteDahuaUsers").click(); + } + }); + } } function deleteETimeOfficeUsers(e) { - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = deleteUsersMessages[languageCode]; - var textMessage = nousersdeleteMessages[languageCode]; - var checkedRows = $(".all-bio-employee-row").filter(":checked"); - if (checkedRows.length === 0) { - Swal.fire({ - text: textMessage, - icon: "warning", - confirmButtonText: "Close", - }); - } else { - Swal.fire({ - text: confirmMessage, - icon: "error", - showCancelButton: true, - confirmButtonColor: "#008000", - cancelButtonColor: "#d33", - confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - var hxValue = JSON.stringify(ids); - var bioDeviceID = JSON.stringify($("#allBioEmployee").data("device")) - $("#deleteETimeOfficeUsers").attr("hx-vals", `{"ids":${hxValue},"device_id":${bioDeviceID}}`); - $("#deleteETimeOfficeUsers").click(); - } - }); - } - }); + var checkedRows = $(".all-bio-employee-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: i18nMessages.noRowsSelected, + icon: "warning", + confirmButtonText: i18nMessages.close, + }); + } else { + Swal.fire({ + text: i18nMessages.confirmBulkDelete, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + var hxValue = JSON.stringify(ids); + var bioDeviceID = JSON.stringify($("#allBioEmployee").data("device")) + $("#deleteETimeOfficeUsers").attr("hx-vals", `{"ids":${hxValue},"device_id":${bioDeviceID}}`); + $("#deleteETimeOfficeUsers").click(); + } + }); + } } // ------------------------------------------------------------------------------------------------------------------------------