[ADD] Added transaltion and sweetjs

This commit is contained in:
Horilla
2023-08-31 17:08:24 +05:30
parent 7422c7cc8b
commit 6a77589d2a
2 changed files with 238 additions and 91 deletions

View File

@@ -1,3 +1,34 @@
var archiveMessages = {
ar: "هل ترغب حقًا في أرشفة جميع الموظفين المحددين؟",
de: "Möchten Sie wirklich alle ausgewählten Mitarbeiter archivieren?",
es: "¿Realmente quieres archivar a todos los empleados seleccionados?",
en: "Do you really want to archive all the selected employees?",
fr: "Voulez-vous vraiment archiver tous les employés sélectionnés ?",
};
var unarchiveMessages = {
ar: "هل ترغب حقًا في إلغاء أرشفة جميع الموظفين المحددين؟",
de: "Möchten Sie wirklich alle ausgewählten Mitarbeiter aus der Archivierung zurückholen?",
es: "¿Realmente quieres desarchivar a todos los empleados seleccionados?",
en: "Do you really want to unarchive all the selected employees?",
fr: "Voulez-vous vraiment désarchiver tous les employés sélectionnés?",
};
var deleteMessages = {
ar: "هل ترغب حقًا في حذف جميع الموظفين المحددين؟",
de: "Möchten Sie wirklich alle ausgewählten Mitarbeiter löschen?",
es: "¿Realmente quieres eliminar a todos los empleados seleccionados?",
en: "Do you really want to delete all the selected employees?",
fr: "Voulez-vous vraiment supprimer tous les employés sélectionnés?",
};
var norowMessages = {
ar: "لم يتم تحديد أي صفوف.",
de: "Es wurden keine Zeilen ausgewählt.",
es: "No se han seleccionado filas.",
en: "No rows have been selected.",
fr: "Aucune ligne n'a été sélectionnée.",
};
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== "") {
@@ -13,6 +44,18 @@ function getCookie(name) {
}
return cookieValue;
}
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
},
});
}
$(".all-employee").change(function (e) {
var is_checked = $(this).is(":checked");
if (is_checked) {
@@ -30,83 +73,154 @@ $(".all-employee").change(function (e) {
}
});
$("#archiveEmployees").click(function (e) {
choice = originalConfirm('Do you want to delete archive all this selected employees?')
if (choice) {
e.preventDefault();
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = archiveMessages[languageCode];
var textMessage = norowMessages[languageCode];
var checkedRows = $(".all-employee-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-archive?is_active=False",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
if (checkedRows.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
} else {
Swal.fire({
text: confirmMessage,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
}).then(function (result) {
if (result.isConfirmed) {
e.preventDefault();
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-archive?is_active=False",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
}
},
});
}
},
});
}
});
}
});
});
$("#unArchiveEmployees").click(function (e) {
e.preventDefault();
choice = originalConfirm('Do you want to delete archive all this selected employees?')
if (choice) {
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = unarchiveMessages[languageCode];
var textMessage = norowMessages[languageCode];
var checkedRows = $(".all-employee-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-archive?is_active=True",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
if (checkedRows.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
} else {
Swal.fire({
text: confirmMessage,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
}).then(function (result) {
if (result.isConfirmed) {
var checkedRows = $(".all-employee-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-archive?is_active=True",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
}
},
});
}
},
});
}
});
}
});
});
$("#deleteEmployees").click(function (e) {
e.preventDefault();
choice = originalConfirm('Do you want to delete archive all this selected employees?')
if (choice) {
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = deleteMessages[languageCode];
var textMessage = norowMessages[languageCode];
var checkedRows = $(".all-employee-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-delete",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
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) {
var checkedRows = $(".all-employee-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/employee/employee-bulk-delete",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload(); // Reload the current page
} else {
// console.log("Unexpected HTTP status:", jqXHR.status);
}
},
});
}
},
});
}
});
}
});
});

View File

@@ -1,3 +1,10 @@
var downloadMessages = {
ar: "هل ترغب في تنزيل القالب؟",
de: "Möchten Sie die Vorlage herunterladen?",
es: "¿Quieres descargar la plantilla?",
en: "Do you want to download the template?",
fr: "Voulez-vous télécharger le modèle ?",
};
function getCookie(name) {
let cookieValue = null;
@@ -15,6 +22,17 @@ function getCookie(name) {
return cookieValue;
}
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
},
});
}
// Get the form element
var form = document.getElementById("workInfoImportForm");
@@ -61,29 +79,44 @@ form.addEventListener("submit", function (event) {
});
$("#work-info-import").click(function (e) {
choice = originalConfirm("Do you want to download template?");
if (choice) {
$.ajax({
type: "GET",
url: "/employee/work-info-import",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
success: function (response) {
const file = new Blob([response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = downloadMessages[languageCode];
// Use SweetAlert for the confirmation dialog
Swal.fire({
text: confirmMessage,
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#008000',
cancelButtonColor: '#d33',
confirmButtonText: 'Confirm'
}).then(function(result) {
if (result.isConfirmed) {
$.ajax({
type: "GET",
url: "/employee/work-info-import",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
success: function (response) {
const file = new Blob([response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "work_info_template.xlsx";
document.body.appendChild(link);
link.click();
},
error: function (xhr, textStatus, errorThrown) {
console.error("Error downloading file:", errorThrown);
},
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "work_info_template.xlsx";
document.body.appendChild(link);
link.click();
},
error: function (xhr, textStatus, errorThrown) {
console.error("Error downloading file:", errorThrown);
},
}
});
}
});
});
});