/* --- Surcharge objets --- */ String.prototype.capitalize = function() { return this[0].toUpperCase() + this.slice(1); } /* --- Fonctions utilitaires --- */ function getCookie(key) { const split = document.cookie.split(';'); let cookies = {}; split.forEach(elt => { const val = elt.trim().split('='); cookies[val[0]] = val[1]; }); if(key !== undefined) { return cookies[key]; } return cookies; } function pagination(id, pageNum, perPage, total, tabElt, paginationElt, dataPage, tableClass) { pageNum = parseInt(pageNum); perPage = parseInt(perPage); total = parseInt(total); tableClass = tableClass || 'striped'; // Création du tableau let tab = ``; let first = true; let keys = []; dataPage.forEach(elt => { if(first) { tab += ''; for (const key in elt) { keys.push(key); tab += ``; } tab += ''; first = false; } tab += ''; keys.forEach(key => { tab += ``; }); tab += ''; }); tab += '
${key.capitalize()}
${elt[key]}
'; // Creation de la pagination const nbPage = Math.ceil(total / perPage); let pagination = `'; // Affichage tabElt.html(tab); paginationElt.html(pagination); } /* --- Initialisation modules --- */ $(document).ready(function(){ // Chargement menu mobile $('.sidenav').sidenav(); // Select $('select').formSelect(); // Modal M.Modal.init($('.modal'), { dismissible: false, startingTop: '20%', endingTop: '25%', onOpenEnd: (modal) => { setTimeout(() => { M.Modal.getInstance(modal).close(); }, 3000); } }); // Date picker M.Datepicker.init($('.datepicker'), { format: 'dd/mm/yyyy', firstDay: 1, yearRange: [ new Date(Date.now()).getFullYear() - 100, new Date(Date.now()).getFullYear() ], i18n: { cancel: 'Annuler', clear: 'Supprimer', months: [ 'Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre' ], monthsShort: [ 'Janv', 'Fevr', 'Mars', 'Avr', 'Mai', 'Juin', 'Juil', 'Aout', 'Sept', 'Oct', 'Nov', 'Dec' ], weekdays: [ 'Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi' ], weekdaysShort: [ 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam' ], weekdaysAbbrev: ['D','L','M','M','J','V','S'] } }); });