[UPDT] HORILLA: Refactor html files to use Django i18n gettext in js

This commit is contained in:
Horilla
2025-08-08 14:44:09 +05:30
parent 43fa24e2c6
commit 0909434fee
68 changed files with 9780 additions and 34667 deletions

View File

@@ -1,45 +1,4 @@
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 ?",
};
var importsuccess = {
ar: "نجح الاستيراد", // Arabic
de: "Import erfolgreich", // German
es: "Importado con éxito", // Spanish
en: "Imported Successfully!", // English
fr: "Importation réussie" // French
};
var uploadsuccess = {
ar: "تحميل كامل", // Arabic
de: "Upload abgeschlossen", // German
es: "Carga completa", // Spanish
en: "Upload Complete!", // English
fr: "Téléchargement terminé" // French
};
var uploadingmessage = {
ar: "جارٍ الرفع",
de: "Hochladen...",
es: "Subiendo...",
en: "Uploading...",
fr: "Téléchargement en cours...",
};
var validationmessage = {
ar: "يرجى تحميل ملف بامتداد .xlsx فقط.",
de: "Bitte laden Sie nur eine Datei mit der Erweiterung .xlsx hoch.",
es: "Por favor, suba un archivo con la extensión .xlsx solamente.",
en: "Please upload a file with the .xlsx extension only.",
fr: "Veuillez télécharger uniquement un fichier avec l'extension .xlsx.",
};
function getCookie(name) {
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
@@ -53,25 +12,13 @@ var downloadMessages = {
}
}
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("projectImportForm");
// Get the form element
var form = document.getElementById("projectImportForm");
// Add an event listener to the form submission
form.addEventListener("submit", function (event) {
// Add an event listener to the form submission
form.addEventListener("submit", function (event) {
// Prevent the default form submission
event.preventDefault();
@@ -82,228 +29,208 @@ var downloadMessages = {
var fileInput = document.querySelector("#projectImportFile");
formData.append("file", fileInput.files[0]);
$.ajax({
type: "POST",
url: "/project/project-import",
dataType: "binary",
data: formData,
processData: false,
contentType: false,
headers: {
"X-CSRFToken": getCookie('csrftoken'), // Replace with your csrf token value
},
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 = "ImportError.xlsx";
document.body.appendChild(link);
link.click();
},
error: function (xhr, textStatus, errorThrown) {
console.error("Error downloading file:", errorThrown);
},
});
});
$("#importProject").click(function (e) {
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) {
$("#loading").show();
var xhr = new XMLHttpRequest();
xhr.open('GET', "/project/project-import", true);
xhr.responseType = 'arraybuffer';
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
var percent = (e.loaded / e.total) * 100;
$(".progress-bar").width(percent + "%").attr("aria-valuenow", percent);
$("#progress-text").text("Uploading... " + percent.toFixed(2) + "%");
}
};
xhr.onload = function (e) {
if (this.status == 200) {
const file = new Blob([this.response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "project_template.xlsx";
document.body.appendChild(link);
link.click();
}
};
xhr.onerror = function (e) {
console.error("Error downloading file:", e);
};
xhr.send();
}
});
});
});
$(document).on('click', '#importProject', function (e) {
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) {
$("#loading").show();
var xhr = new XMLHttpRequest();
xhr.open('GET', "/project/project-import", true);
xhr.responseType = 'arraybuffer';
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
var percent = (e.loaded / e.total) * 100;
$(".progress-bar").width(percent + "%").attr("aria-valuenow", percent);
$("#progress-text").text("Uploading... " + percent.toFixed(2) + "%");
}
};
xhr.onload = function (e) {
if (this.status == 200) {
const file = new Blob([this.response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "project_template.xlsx";
document.body.appendChild(link);
link.click();
// Clean up by removing the link element
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
};
xhr.onerror = function (e) {
console.error("Error downloading file:", e);
};
xhr.send();
}
});
type: "POST",
url: "/project/project-import",
dataType: "binary",
data: formData,
processData: false,
contentType: false,
headers: {
"X-CSRFToken": getCookie('csrftoken'), // Replace with your csrf token value
},
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 = "ImportError.xlsx";
document.body.appendChild(link);
link.click();
},
error: function (xhr, textStatus, errorThrown) {
console.error("Error downloading file:", errorThrown);
},
});
});
$(document).ajaxStart(function () {
$("#importProject").click(function (e) {
e.preventDefault();
// Use SweetAlert for the confirmation dialog
Swal.fire({
text: i18nMessages.downloadTemplate,
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#008000',
cancelButtonColor: '#d33',
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
$("#loading").show();
var xhr = new XMLHttpRequest();
xhr.open('GET', "/project/project-import", true);
xhr.responseType = 'arraybuffer';
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
var percent = (e.loaded / e.total) * 100;
$(".progress-bar").width(percent + "%").attr("aria-valuenow", percent);
$("#progress-text").text("Uploading... " + percent.toFixed(2) + "%");
}
};
xhr.onload = function (e) {
if (this.status == 200) {
const file = new Blob([this.response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "project_template.xlsx";
document.body.appendChild(link);
link.click();
}
};
xhr.onerror = function (e) {
console.error("Error downloading file:", e);
};
xhr.send();
}
});
});
$(document).on('click', '#importProject', function (e) {
e.preventDefault();
// Use SweetAlert for the confirmation dialog
Swal.fire({
text: i18nMessages.downloadTemplate,
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#008000',
cancelButtonColor: '#d33',
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
$("#loading").show();
var xhr = new XMLHttpRequest();
xhr.open('GET', "/project/project-import", true);
xhr.responseType = 'arraybuffer';
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
var percent = (e.loaded / e.total) * 100;
$(".progress-bar").width(percent + "%").attr("aria-valuenow", percent);
$("#progress-text").text("Uploading... " + percent.toFixed(2) + "%");
}
};
xhr.onload = function (e) {
if (this.status == 200) {
const file = new Blob([this.response], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const url = URL.createObjectURL(file);
const link = document.createElement("a");
link.href = url;
link.download = "project_template.xlsx";
document.body.appendChild(link);
link.click();
// Clean up by removing the link element
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
};
xhr.onerror = function (e) {
console.error("Error downloading file:", e);
};
xhr.send();
}
});
});
$(document).ajaxStart(function () {
$("#loading").show();
});
});
$(document).ajaxStop(function () {
$(document).ajaxStop(function () {
$("#loading").hide();
});
});
function simulateProgress() {
var languageCode = null;
getCurrentLanguageCode(function(code){
languageCode = code;
var importMessage = importsuccess[languageCode];
var uploadMessage = uploadsuccess[languageCode];
var uploadingMessage = uploadingmessage[languageCode];
function simulateProgress() {
let progressBar = document.querySelector('.progress-bar');
let progressText = document.getElementById('progress-text');
let width = 0;
let interval = setInterval(function() {
if (width >= 100) {
clearInterval(interval);
progressText.innerText = uploadMessage;
setTimeout(function() {
document.getElementById('loading').style.display = 'none';
}, 3000);
Swal.fire({
text: importMessage,
icon: "success",
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
});
setTimeout(function() {
$('#projectImport').removeClass('oh-modal--show');
location.reload(true);
}, 2000);
} else {
width++;
progressBar.style.width = width + '%';
progressBar.setAttribute('aria-valuenow', width);
progressText.innerText = uploadingMessage + width + '%';
}
let interval = setInterval(function () {
if (width >= 100) {
clearInterval(interval);
progressText.innerText = gettext("Upload Completed!");
setTimeout(function () {
document.getElementById('loading').style.display = 'none';
}, 3000);
Swal.fire({
text: gettext("Imported Successfully!"),
icon: "success",
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
});
setTimeout(function () {
$('#projectImport').removeClass('oh-modal--show');
location.reload(true);
}, 2000);
} else {
width++;
progressBar.style.width = width + '%';
progressBar.setAttribute('aria-valuenow', width);
progressText.innerText = i18nMessages.uploading + width + '%';
}
}, 20);
}
)}
}
document.getElementById('projectImportForm').addEventListener('submit', function(event) {
document.getElementById('projectImportForm').addEventListener('submit', function (event) {
event.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function(code){
languageCode = code;
var erroMessage = validationmessage[languageCode];
var fileInput = $('#projectImportFile').val();
var allowedExtensions = /(\.xlsx)$/i;
if (!allowedExtensions.exec(fileInput)) {
var errorMessage = document.createElement('div');
errorMessage.classList.add('error-message');
var errorMessage = document.createElement('div');
errorMessage.classList.add('error-message');
errorMessage.textContent = erroMessage;
errorMessage.textContent = gettext("Please upload a file with the .xlsx extension only.");
document.getElementById('error-container').appendChild(errorMessage);
document.getElementById('error-container').appendChild(errorMessage);
fileInput.value = '';
fileInput.value = '';
setTimeout(function() {
errorMessage.remove();
}, 2000);
setTimeout(function () {
errorMessage.remove();
}, 2000);
return false;
return false;
}
else{
else {
document.getElementById('loading').style.display = 'block';
document.getElementById('loading').style.display = 'block';
simulateProgress();
simulateProgress();
}
});
})
})

View File

@@ -1,27 +1,3 @@
var exportMessages = {
// 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 export all the selected projects?",
// fr: "Voulez-vous vraiment supprimer tous les employés sélectionnés?",
};
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 ?",
};
var norowMessagesSelected = {
// 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 !== "") {
@@ -38,62 +14,47 @@ 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
},
});
}
function validateProjectIds(event) {
getCurrentLanguageCode(function (code) {
languageCode = code;
var textMessage = norowMessagesSelected[languageCode];
var takeAction = $(event.currentTarget).data("action");
var takeAction = $(event.currentTarget).data("action");
var idsRaw = $("#selectedInstances").attr("data-ids");
if (!idsRaw) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
return;
}
var idsRaw = $("#selectedInstances").attr("data-ids");
if (!idsRaw) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
return;
}
var ids = JSON.parse(idsRaw);
if (ids.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
return;
}
var ids = JSON.parse(idsRaw);
if (ids.length === 0) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
return;
}
let triggerId;
if (takeAction === "archive") {
triggerId = "#bulkArchiveProject";
} else if (takeAction === "unarchive") {
triggerId = "#bulkUnArchiveProject";
} else if (takeAction === "delete") {
triggerId = "#bulkDeleteProject";
} else {
console.warn("Unsupported action:", takeAction);
return;
}
let triggerId;
if (takeAction === "archive") {
triggerId = "#bulkArchiveProject";
} else if (takeAction === "unarchive") {
triggerId = "#bulkUnArchiveProject";
} else if (takeAction === "delete") {
triggerId = "#bulkDeleteProject";
} else {
console.warn("Unsupported action:", takeAction);
return;
}
const $triggerElement = $(triggerId);
if ($triggerElement.length) {
$triggerElement.attr("hx-vals", JSON.stringify({ ids })).click();
} else {
console.warn("Trigger element not found for:", triggerId);
}
});
const $triggerElement = $(triggerId);
if ($triggerElement.length) {
$triggerElement.attr("hx-vals", JSON.stringify({ ids })).click();
} else {
console.warn("Trigger element not found for:", triggerId);
}
}
$(".all-projects").change(function (e) {
@@ -107,122 +68,114 @@ $(".all-projects").change(function (e) {
$("#exportProject").click(function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = exportMessages[languageCode];
var textMessage = norowMessagesSelected[languageCode];
var checkedRows = $(".all-project-row").filter(":checked");
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-project-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/project-bulk-export",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
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 = "project details.xlsx";
document.body.appendChild(link);
link.click();
},
});
}
});
}
});
var checkedRows = $(".all-project-row").filter(":checked");
if (checkedRows.length === 0) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
Swal.fire({
text: i18nMessages.downloadExcel,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
var checkedRows = $(".all-project-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/project-bulk-export",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
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 = "project details.xlsx";
document.body.appendChild(link);
link.click();
},
});
}
});
}
});
$(document).on('click', '#exportProject', function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = exportMessages[languageCode];
var textMessage = norowMessagesSelected[languageCode];
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.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-project-row").filter(":checked");
// ids = [];
// checkedRows.each(function () {
// ids.push($(this).attr("id"));
// });
$.ajax({
type: "POST",
url: "/project/project-bulk-export",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
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 = "project details.xlsx";
document.body.appendChild(link);
link.click();
},
});
}
});
}
});
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.length === 0) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
Swal.fire({
text: i18nMessages.downloadExcel,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
// var checkedRows = $(".all-project-row").filter(":checked");
// ids = [];
// checkedRows.each(function () {
// ids.push($(this).attr("id"));
// });
$.ajax({
type: "POST",
url: "/project/project-bulk-export",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
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 = "project details.xlsx";
document.body.appendChild(link);
link.click();
},
});
}
});
}
});

View File

@@ -1,371 +1,305 @@
var archiveMessage = {
// 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 tasks?",
// fr: "Voulez-vous vraiment archiver tous les employés sélectionnés ?",
};
var unarchiveMessage = {
// 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 tasks?",
// fr: "Voulez-vous vraiment désarchiver tous les employés sélectionnés?",
};
var deleteMessage = {
// 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 tasks?",
// fr: "Voulez-vous vraiment supprimer tous les employés sélectionnés?",
};
var norowMessage = {
// 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) {
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== "") {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
}
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-task-all").change(function (e) {
$(".all-task-all").change(function (e) {
var is_checked = $(this).is(":checked");
if (is_checked) {
$(".all-task-all-row").prop("checked", true);
$(".all-task-all-row").prop("checked", true);
} else {
$(".all-task-all-row").prop("checked", false);
$(".all-task-all-row").prop("checked", false);
}
});
});
$("#archiveTaskAll").click(function (e) {
$("#archiveTaskAll").click(function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = archiveMessage[languageCode];
var textMessage = norowMessage[languageCode];
var checkedRows = $(".all-task-all-row").filter(":checked");
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: "/project/task-all-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);
}
},
});
}
var checkedRows = $(".all-task-all-row").filter(":checked");
if (checkedRows.length === 0) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
}
});
});
} else {
Swal.fire({
text: i18nMessages.confirmBulkArchive,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
e.preventDefault();
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/task-all-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);
}
},
});
}
});
}
});
//Bulk archive
$(document).on('click', '#archiveTask', function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = archiveMessage[languageCode];
var textMessage = norowMessage[languageCode];
e.preventDefault();
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
Swal.fire({
text: confirmMessage,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
}).then(function (result) {
if (result.isConfirmed) {
Swal.fire({
text: i18nMessages.confirmBulkArchive,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-archive?is_active=False",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-archive?is_active=False",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
}
},
});
}
});
}
},
});
}
});
}
});
});
$("#unArchiveTaskAll").click(function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = unarchiveMessage[languageCode];
var textMessage = norowMessage[languageCode];
var checkedRows = $(".all-task-all-row").filter(":checked");
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-task-all-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/task-all-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);
}
},
});
}
var checkedRows = $(".all-task-all-row").filter(":checked");
if (checkedRows.length === 0) {
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
}
});
});
} else {
Swal.fire({
text: i18nMessages.confirmBulkUnArchive,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
var checkedRows = $(".all-task-all-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/task-all-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);
}
},
});
}
});
}
});
//Bulk unarchive
$(document).on('click', '#unArchiveTask', function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = unarchiveMessage[languageCode];
var textMessage = norowMessage[languageCode];
e.preventDefault();
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
Swal.fire({
text: confirmMessage,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
}).then(function (result) {
if (result.isConfirmed) {
Swal.fire({
text: i18nMessages.confirmBulkUnArchive,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-archive?is_active=True",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-archive?is_active=True",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
}
},
});
}
});
}
},
});
}
});
}
});
});
$("#deleteTaskAll").click(function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = deleteMessage[languageCode];
var textMessage = norowMessage[languageCode];
var checkedRows = $(".all-task-all-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) {
var checkedRows = $(".all-task-all-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/task-all-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);
}
},
});
}
var checkedRows = $(".all-task-all-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: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
var checkedRows = $(".all-task-all-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/task-all-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);
}
},
});
}
});
}
});
//Bulk delete
$(document).on('click', '#deleteTask', function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = deleteMessage[languageCode];
var textMessage = norowMessage[languageCode];
e.preventDefault();
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
});
Swal.fire({
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
Swal.fire({
text: confirmMessage,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
}).then(function (result) {
if (result.isConfirmed) {
Swal.fire({
text: i18nMessages.confirmBulkDelete,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-delete",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
$.ajax({
type: "POST",
url: "/project/task-all-bulk-delete",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
ids: JSON.stringify(ids),
},
success: function (response, textStatus, jqXHR) {
if (jqXHR.status === 200) {
location.reload();
} else {
}
},
});
}
});
}
},
});
}
});
}
});
});

View File

@@ -1,172 +1,121 @@
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 timesheet?",
// 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 timesheet?",
// fr: "Voulez-vous vraiment désarchiver tous les employés sélectionnés?",
};
var deleteMessagesBulk = {
// 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 timesheet?",
// 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) {
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== "") {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
}
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-time-sheet").change(function (e) {
$(".all-time-sheet").change(function (e) {
var is_checked = $(this).is(":checked");
if (is_checked) {
$(".all-time-sheet-row").prop("checked", true);
$(".all-time-sheet-row").prop("checked", true);
} else {
$(".all-time-sheet-row").prop("checked", false);
$(".all-time-sheet-row").prop("checked", false);
}
});
});
$("#deleteTimeSheet").click(function (e) {
e.preventDefault();
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = deleteMessagesBulk[languageCode];
var textMessage = norowMessages[languageCode];
var checkedRows = $(".all-time-sheet-row").filter(":checked");
if (checkedRows.length === 0) {
var checkedRows = $(".all-time-sheet-row").filter(":checked");
if (checkedRows.length === 0) {
Swal.fire({
text: textMessage,
icon: "warning",
confirmButtonText: "Close",
text: i18nMessages.noRowsSelected,
icon: "warning",
confirmButtonText: i18nMessages.close,
});
} else {
} else {
Swal.fire({
text: confirmMessage,
icon: "error",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: "Confirm",
text: i18nMessages.confirmBulkDelete,
icon: "error",
showCancelButton: true,
confirmButtonColor: "#008000",
cancelButtonColor: "#d33",
confirmButtonText: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
var checkedRows = $(".all-time-sheet-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
if (result.isConfirmed) {
var checkedRows = $(".all-time-sheet-row").filter(":checked");
ids = [];
checkedRows.each(function () {
ids.push($(this).attr("id"));
});
$.ajax({
type: "POST",
url: "/project/time-sheet-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);
}
},
});
}
$.ajax({
type: "POST",
url: "/project/time-sheet-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);
}
},
});
}
});
}
});
});
}
});
function deleteTimeSheet(){
var languageCode = null;
getCurrentLanguageCode(function (code) {
languageCode = code;
var confirmMessage = deleteMessagesBulk[languageCode];
var textMessage = norowMessages[languageCode];
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.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-time-sheet-row").filter(":checked");
// ids = [];
// checkedRows.each(function () {
// ids.push($(this).attr("id"));
// });
function deleteTimeSheet() {
ids = [];
ids.push($("#selectedInstances").attr("data-ids"));
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
if (ids.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: i18nMessages.confirm,
cancelButtonText: i18nMessages.cancel,
}).then(function (result) {
if (result.isConfirmed) {
// var checkedRows = $(".all-time-sheet-row").filter(":checked");
// ids = [];
// checkedRows.each(function () {
// ids.push($(this).attr("id"));
// });
$.ajax({
type: "POST",
url: "/project/time-sheet-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);
}
},
});
}
});
}
});
};
$.ajax({
type: "POST",
url: "/project/time-sheet-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);
}
},
});
}
});
}
};