Skip to content
Snippets Groups Projects
Select Git revision
  • 474953b204495f7433ac477325c03ac778e33e70
  • master default protected
  • detached4
  • detached3
  • detached2
  • bsv-next
  • detached
  • php82
  • 6.x
  • 6.4.0
  • 6.3.3
  • 6.3.2
  • 6.3.1
  • 6.3.0
  • 6.2.7
  • 6.2.6
  • 6.2.5
  • 6.2.4
  • 6.2.3
  • 6.2.2
  • 6.2.1
  • 6.2.0
  • 6.1.3
  • 6.1.2
  • 6.1.1
  • 6.1.0
  • 6.0.0
27 results

flashMessenger.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    flashMessenger.js 2.05 KiB
    function toasts(messages)
    {
        for (let s in messages) {
            for (let m in messages[s]) {
                toast(messages[s][m], s);
            }
        }
    }
    
    
    
    
    function toast(message, severity) {
        const bgClasses = {
            info: 'bg-info',
            success: 'bg-success',
            warning: 'bg-warning',
            error: 'bg-danger'
        };
        const iconClasses = {
            info: 'info-circle',
            success: 'check-circle',
            warning: 'exclamation-circle',
            error: 'exclamation-triangle'
        };
    
        let toastContainer = document.getElementById('unicaen-vue-toast-container');
        if (!toastContainer) {
            toastContainer = document.createElement('div');
            toastContainer.id = 'unicaen-vue-toast-container';
            toastContainer.classList.add('toast-container', 'position-fixed', 'top-0', 'end-0', 'p-3');
            document.body.appendChild(toastContainer);
        }
    
        // Création de l'élément HTML pour le toast
        const toast = document.createElement('div');
        toast.classList.add('toast', 'show', 'text-white', bgClasses[severity] ? bgClasses[severity] : 'bg-secondary');
        toast.setAttribute('role', 'alert');
        toast.setAttribute('aria-live', 'assertive');
        toast.setAttribute('aria-atomic', 'true');
    
        if (severity === 'error' && message.length > 500){
            toast.setAttribute('style', 'width:700px');
        }
    
        const toastContent =
            '<button class="btn-close btn-close-white h5" style="float:right" data-bs-dismiss="toast" aria-label="Close"></button>' +
            '<i class="icon fas fa-' + iconClasses[severity] + '" style="float: left;font-size: 26pt;padding-left: .4rem;margin-top:.4rem;padding-right: 1rem;"></i>' +
            '<div class="toast-body">' + message + '  </div>';
    
        toast.innerHTML = toastContent;
    
        // Ajout du toast à l'élément du conteneur de toasts
        toastContainer.appendChild(toast);
    
        // Masquage du toast si ce n'est pas une erreur
        if (severity !== 'error') {
            setTimeout(() => {
                toast.classList.remove('show');
            }, 5000);
        }
    }
    
    
    export default {
        toast,
        toasts
    }