radiantrh/Js/fonctions.js
2025-12-25 11:01:11 +00:00

511 lines
14 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$(function(){
appliquerDataTable();
});
// Gestion du menu burger - Version simplifiée
document.addEventListener('DOMContentLoaded', function() {
const burgerToggle = document.getElementById('burgerMenuToggle');
const burgerDropdown = document.getElementById('burgerDropdown');
if (burgerToggle && burgerDropdown) {
// Ouvrir/fermer le menu burger
burgerToggle.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
burgerDropdown.classList.toggle('show');
});
// Fermer le menu quand on clique ailleurs sur la page
document.addEventListener('click', function(e) {
if (!e.target.closest('.burger-menu-container')) {
burgerDropdown.classList.remove('show');
}
});
// Empêcher la fermeture quand on clique dans le menu dropdown
burgerDropdown.addEventListener('click', function(e) {
e.stopPropagation();
});
}
});
// Fonction pour formater les messages avec retours à la ligne automatiques
function formatMessageForSwal(message) {
if (!message) return '';
// Définir la longueur maximale par ligne selon la largeur de l'écran
const screenWidth = window.innerWidth;
let maxLineLength;
if (screenWidth < 576) { // Mobile
maxLineLength = 40;
} else if (screenWidth < 768) { // Tablet
maxLineLength = 60;
} else { // Desktop
maxLineLength = 80;
}
// Si le message est déjà court, ne pas le modifier
if (message.length <= maxLineLength && !message.includes('\n')) {
return message;
}
// Diviser le message en mots
const words = message.split(' ');
let lines = [];
let currentLine = '';
words.forEach(word => {
// Si ajouter ce mot dépasse la limite, créer une nouvelle ligne
if ((currentLine + ' ' + word).length > maxLineLength && currentLine !== '') {
lines.push(currentLine);
currentLine = word;
} else {
// Ajouter le mot à la ligne courante
currentLine = currentLine ? currentLine + ' ' + word : word;
}
});
// Ajouter la dernière ligne
if (currentLine) {
lines.push(currentLine);
}
return lines.join('<br>');
}
// Fonction pour ajuster dynamiquement le contenu SweetAlert
function adjustSwalContent() {
const popup = Swal.getPopup();
const title = Swal.getTitle();
const htmlContainer = Swal.getHtmlContainer();
if (popup && title) {
// Ajuster la largeur maximale selon l'écran
const screenWidth = window.innerWidth;
if (screenWidth < 576) {
popup.style.maxWidth = '95vw';
popup.style.width = '95vw';
popup.style.margin = '10px';
} else if (screenWidth < 768) {
popup.style.maxWidth = '85vw';
popup.style.width = '85vw';
} else {
popup.style.maxWidth = '500px';
popup.style.width = '500px';
}
// Gérer le défilement si nécessaire
const titleHeight = title.scrollHeight;
const maxTitleHeight = Math.min(window.innerHeight * 0.6, 400);
if (titleHeight > maxTitleHeight) {
title.style.overflowY = 'auto';
title.style.maxHeight = maxTitleHeight + 'px';
title.style.paddingRight = '10px';
}
// Ajuster également le conteneur HTML si présent
if (htmlContainer) {
const containerHeight = htmlContainer.scrollHeight;
const maxContainerHeight = Math.min(window.innerHeight * 0.4, 300);
if (containerHeight > maxContainerHeight) {
htmlContainer.style.overflowY = 'auto';
htmlContainer.style.maxHeight = maxContainerHeight + 'px';
htmlContainer.style.paddingRight = '10px';
}
}
}
}
// Fonction d'alerte principale
function alert_ebene(p_msg, p_msg_eng) {
let codeLangue = $("#codeLangue").val();
let message = (codeLangue === "en_US") ? p_msg_eng : p_msg;
// Formater le message pour les retours à la ligne
let formattedMessage = formatMessageForSwal(message);
Swal.fire({
title: formattedMessage,
icon: 'info',
confirmButtonText: codeLangue === "en_US" ? 'OK' : 'D\'accord',
customClass: {
popup: 'responsive-swal-popup',
title: 'responsive-swal-title',
htmlContainer: 'responsive-swal-html'
},
didOpen: () => {
adjustSwalContent();
},
willOpen: () => {
// Ajustement avant l'ouverture
document.body.style.overflow = 'hidden';
},
willClose: () => {
document.body.style.overflow = 'auto';
}
});
}
// Fonction de confirmation
function confirm_ebene(p_msg, p_msg_eng) {
let codeLangue = $("#codeLangue").val();
let message = (codeLangue === "en_US") ? p_msg_eng : p_msg;
// Formater le message pour les retours à la ligne
let formattedMessage = formatMessageForSwal(message);
return Swal.fire({
title: formattedMessage,
icon: 'warning',
showCancelButton: true,
confirmButtonText: codeLangue === "en_US" ? 'Yes' : 'Oui',
cancelButtonText: codeLangue === "en_US" ? 'No' : 'Non',
customClass: {
popup: 'responsive-swal-popup',
title: 'responsive-swal-title',
htmlContainer: 'responsive-swal-html'
},
didOpen: () => {
adjustSwalContent();
},
willOpen: () => {
document.body.style.overflow = 'hidden';
},
willClose: () => {
document.body.style.overflow = 'auto';
}
}).then((result) => {
return result.isConfirmed;
});
}
// Fonction de prompt
function prompt_ebene(p_msg, p_msg_eng, p_retour, callback) {
let codeLangue = $("#codeLangue").val();
let message = (codeLangue === "en_US") ? p_msg_eng : p_msg;
// Formater le message pour les retours à la ligne
let formattedMessage = formatMessageForSwal(message);
Swal.fire({
title: formattedMessage,
input: 'text',
inputValue: p_retour,
showCancelButton: true,
confirmButtonText: 'OK',
cancelButtonText: 'Annuler',
customClass: {
popup: 'responsive-swal-popup',
title: 'responsive-swal-title',
htmlContainer: 'responsive-swal-html'
},
didOpen: () => {
adjustSwalContent();
},
willOpen: () => {
document.body.style.overflow = 'hidden';
},
willClose: () => {
document.body.style.overflow = 'auto';
}
}).then((result) => {
if (result.isConfirmed) {
callback(result.value);
} else {
callback(null);
}
});
}
// Écouter les changements de taille de fenêtre
window.addEventListener('resize', () => {
// Réajuster si une alerte est ouverte
if (Swal.isVisible()) {
setTimeout(adjustSwalContent, 100);
}
});
function change_password()
{
v_msg="Attention, vous serez déconnecté par la suite! Voulez-vous changer votre mot de passe?";
v_msgEng="Attention, you will be logged out afterwards! Do you want to change your password?";
confirm_ebene(v_msg, v_msgEng)
.then((isConfirmed) => {
if (isConfirmed) {
// L'utilisateur a confirmé
window.location.assign($("#racineWeb" ).val()+"Changermotpass/");
} else {
// L'utilisateur a annulé
console.log("Confirmation refusée");
}
});
}
function afficher_beneficiaire_id()
{
idBeneficiaire=$("#idBeneficiaire_C").val();
okId=$("#okId").val();
// alert("okId = "+okId);
// alert("idBeneficiaire:"+idBeneficiaire+"fin");
//return
$("#contenu").html('<div class="spinner-responsive">' + '<span><i class="fa fa-spinner"></i></span>' + '</div>');
if (idBeneficiaire>"")
{
ajax_context_beneficiaire_afficher(idBeneficiaire, okId);
}
}
function afficher_beneficiaire_id_okId()
{
idBeneficiaire=$("#idBeneficiaire_C").val();
okId=$("#okId").val();
if (idBeneficiaire>"")
{
ajax_context_beneficiaire_afficher(idBeneficiaire, okId);
}
}
function ajax_context_beneficiaire_afficher(idBeneficiaire, okId)
{
donnees = 'idBeneficiaire='+idBeneficiaire+'&okId='+okId;
$.ajax({
url: $("#racineWeb").val()+"Ajaxcontextbeneficiaire/",
type : 'post',
data: donnees,
error: function(errorData) {
// alert("Erreur : "+errorData);
},
complete: function() {
window.location.assign($("#racineWeb" ).val()+"Fichebeneficiaire/"+idBeneficiaire);
}
});
}
function change_password()
{
v_msg="Attention, vous serez déconnecté par la suite! Voulez-vous changer votre mot de passe?";
v_msgEng="Attention, you will be logged out afterwards! Do you want to change your password?";
confirm_ebene(v_msg, v_msgEng)
.then((isConfirmed) => {
if (isConfirmed) {
// L'utilisateur a confirmé
window.location.assign($("#racineWeb" ).val()+"Changermotpass/");
} else {
// L'utilisateur a annulé
console.log("Confirmation refusée");
}
});
}
function changer_langue_connexion()
{
codeLangue = $("#langue").val();
donnees = 'codeLangue='+codeLangue;
$.ajax({
url: $("#racineWeb").val()+"Ajaxconnexioncookie/changerlangue/",
type : 'post',
data: donnees,
error: function(errorData)
{
},
success: function(data)
{
$("#div_detail_connexion").html(data);
},
complete: function()
{
$(".selectpicker").selectpicker();
}
});
}
function connexion_cookie()
{
msgErreur=$("#msgErreur").val();
donnees = 'msgErreur='+msgErreur;
$.ajax({
url: $("#racineWeb").val()+"Ajaxconnexioncookie/",
type: 'POST',
data: donnees,
success: function(data)
{
$("#div_ajaxconnexion").html(data);
},
error: function(errorData)
{
},
complete: function()
{
var login = document.getElementById("login").value;
if (login>" ")
{
$("#mdp").focus();
}
else
{
$("#login").focus();
}
}
});
}
// Applique la librairie DataBase sur les tableaux
function appliquerDataTable() {
const $table = $('.tabliste');
const codeLangue = $("#codeLangue").val();
// Détruire l'instance existante si elle existe
if ($.fn.DataTable.isDataTable($table)) {
$table.DataTable().destroy();
$table.empty(); // Optionnel
}
try {
// Dictionnaire des traductions
const translations = {
en_US: {
lengthMenu: "Display _MENU_ records per page",
zeroRecords: "Nothing found - sorry",
info: "Showing page _PAGE_ of _PAGES_",
infoEmpty: "No records available",
search: "Search:",
paginate: {
next: "►",
previous: "◄",
first: "|◄",
last: "►|"
},
infoFiltered: "(filtered from _MAX_ total records)"
},
fr_FR: {
lengthMenu: "Affiche _MENU_ par page",
zeroRecords: "Désolé - Aucune donnée trouvée",
info: "_PAGE_ sur _PAGES_ pages",
infoEmpty: "Pas d'enregistrement",
search: "Recherche:",
paginate: {
next: "►",
previous: "◄",
first: "|◄",
last: "►|"
},
infoFiltered: "(filtré de _MAX_ total enregistrements)"
}
// Tu peux ajouter d'autres langues ici (ex: es_ES, de_DE, etc.)
};
// Options communes
const options = {
destroy: true,
responsive: true,
order: [[0, "desc"]],
lengthMenu: [50, 100, 150],
scrollX: true,
scrollY: "75vh",
pagingType: "full_numbers",
autoWidth: false,
language: translations[codeLangue] || translations.fr_FR
};
// Initialisation du DataTable
$table.DataTable(options);
} catch (err) {
console.error("Erreur lors de l'application du DataTable :", err);
return false;
}
}
function raffraichier_gabarit()
{
$.ajax({
url: $("#racineWeb").val()+"Ajaxgabarit/",
success: function(data)
{
$("#div_ajaxgabarit").html(data);
//codeSociete = $("#codeSociete").val();
//codeLangue = $("#codeLangue").val();
fusionConsOrd = $("#fusionConsOrd").val();
vue = $("#vue").val();
if(fusionConsOrd != "1" && vue !="Connexion"){
window.location.assign($("#racineWeb" ).val()+"Connexion/");
}
},
error: function(errorData)
{
},
complete: function()
{
$(".datepicker" ).datepicker();
raffraichier_messagerie();
}
});
}
function raffraichier_messagerie()
{
deconnexion='0';
if(navigator.onLine)
{
c_html = "";
$.ajax({
url: $("#racineWeb").val()+"Ajaxmessagerie/",
success: function(data) {
c_html = data;
},
error: function(errorData) {
},
complete: function() {
$("#nbMessagesNonLus").html(c_html);
msgNonLus=$("#msgNonLus").val();
$("#span_notification").text(msgNonLus);
// Ajout du 27/10/2024 => déconnecter si session expirée
deconnexion=$("#deconnexion").val();
// alert("deconnexion => "+deconnexion);
if(deconnexion=='1')
{
window.location.assign($("#racineWeb" ).val()+"Connexion/deconnecter/");
}
}
});
}
else
{
$("#test_connexion").css('background-color', 'red');
return;
}
}