wp-cass/public/js/cass.js
2024-12-26 11:17:02 +01:00

105 lines
3.3 KiB
JavaScript

function getDateFormated(date, showTime) {
var dateObj = new Date(date);
var day = dateObj.getDate();
var month = dateObj.getMonth() + 1;
var year = dateObj.getFullYear();
var hours = dateObj.getHours();
var minutes = dateObj.getMinutes();
var dayFormatted = (day < 10) ? `0${day}` : day;
var monthFormatted = (month < 10) ? `0${month}` : month;
var hoursFormatted = (hours < 10) ? `0${hours}` : hours;
var minutesFormatted = (minutes < 10) ? `0${minutes}` : minutes;
var dateFormated = "";
if (hours == 0 && minutes == 0 || !showTime) {
dateFormated = `${dayFormatted}.${monthFormatted}.${year}`;
} else {
dateFormated = `${dayFormatted}.${monthFormatted}.${year} à ${hoursFormatted}.${minutesFormatted}`;
}
return dateFormated;
}
function getReturnWithCarriage(text) {
if(text != null){
text = text.replace(/\n/g, '<br>');
} else {
text="";
}
return text;
}
function getTextFromState(state) {
let returnText = "";
switch (parseInt(state)) {
case 1:
returnText = "Brouillon";
break;
case 2:
returnText= "Ouverte";
break;
case 3:
returnText = "Confirmée";
break;
case 4:
returnText = "Terminée";
break;
case 5:
returnText= "Annulée";
break;
}
return returnText;
}
function ReadGlobal(text, DOMParserEnabled){
if(DOMParserEnabled) {
var parser = new DOMParser();
var text = parser.parseFromString('<!doctype html><body>' + text, 'text/html').body.textContent;
}
if(text != null){
text = text.replace(/\\/g, '');
} else {
text="";
}
return text;
}
function initializeTinyMCE(selectors) {
tinymce.init({
selector: selectors,
menubar: false,
height: 500,
plugins: 'advlist autolink lists link image charmap print preview anchor table', // Plugins actifs
toolbar: 'undo redo | formatselect | fontselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image table | removeformat', // Outils affichés
font_formats: 'Arial=arial,helvetica,sans-serif; Courier New=courier new,courier,monospace; Georgia=georgia,palatino; Times New Roman=times new roman,times; Verdana=verdana,geneva;', // Choix de polices
image_caption: true, // Activer les légendes d'image
automatic_uploads: true, // Activer les téléversements d'image
file_picker_types: 'image', // Limiter le sélecteur de fichiers aux images
file_picker_callback: function (callback, value, meta) {
// Gestionnaire personnalisé pour les fichiers
if (meta.filetype === 'image') {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function () {
const file = this.files[0];
const reader = new FileReader();
reader.onload = function () {
callback(reader.result, { alt: file.name });
};
reader.readAsDataURL(file);
};
input.click();
}
}
});
}