$(function(){ notification_user_notification_search(); }); //CHARGEMENT DE LA PAGE function init_plugin_notification(){ switch($.urlParam('page')){ default: $('#notifications').fill({ action : 'notification_user_notification_search' }, function(r){ if(!r.rows) $('#notifications').append('
Aucune notification
'); }); break; } } $(document).ready(function(e){ //Positionnement icône des notifications if($(document).width() <= 767){ var notifIcon = $('#loginHeader > .notification_menu').detach(); $('#mainMenu > button.navbar-toggler').before(notifIcon); } //Meilleure ergonomie pour choisir les catégories de notification $('#notification_categories').on('click', ' .list-group-item.list-group-item-action', function(e){ var checkbox = $(this).find('label.check-component>input[type="checkbox"]'); checkbox.prop('checked', !checkbox.prop("checked")); checkbox.attr('checked', !checkbox.prop("checked")); }); }); //Changement positionnement icône des //notifs au redimensionnement de la fenêtre $(window).resize(function(event) { if($(document).width() > 767){ var notifIcon = $('#mainMenu > .notification_menu').detach(); $('#loginHeader').prepend(notifIcon); } if($(document).width() <= 767){ var notifIcon = $('#loginHeader > .notification_menu').detach(); $('#mainMenu > button.navbar-toggler').before(notifIcon); } }); //Marquer comme lu/non lu une notification function notification_user_notification_toggle_read(element,event,container){ if(event) event.stopPropagation(); if(!container) container = 'li'; var line = $(element).closest(container); var number = $('.notification_menu .notification-number'); var notifId = line.attr('data-id'); $.action({ action : 'notification_usernotification_toggle_read', id : notifId },function(r){ var oldNumber = parseInt(number.text()); if(!$.isNumeric(oldNumber)) oldNumber = 0; if(r.read){ $('.notification-item[data-id='+notifId+']').removeClass('unread').removeClass('notification-unread'); $(element).attr('title', 'Marquer comme non lu'); if(oldNumber==1) number.removeAttr('style'); number.text(oldNumber-1) } else { $('.notification-item[data-id='+notifId+']').addClass('unread').addClass('notification-unread'); $(element).attr('title', 'Marquer comme lu'); if(oldNumber==0) number.show(); number.text(oldNumber+1); } }); } function notification_user_notification_all_read(element, event){ event.preventDefault(); event.stopPropagation(); var notifDropdown = $(element).closest('.dropdown-menu'); var notifs = $('.dropdown-item.notification-unread', notifDropdown); if(!notifs.length) return; //Choix entre uniquement les notifs non lues affichées $.each(notifs, function(index, value){ notification_user_notification_toggle_read(value, event, '.dropdown-item'); }); //Ou prendre toutes les notifs non lues // $.action({ // action: 'notification_usernotification_all_read' // }, function(r){ // }); } //Récupération des notifications function notification_user_notification_search(){ var menu = $('.notification_menu .dropdown-menu'); menu.html('Chargement...'); $.action({ action : 'notification_user_notification_search', synthesis : true, },function(r){ if(r.unread!='0') $('.notification-number').show().html(r.unread); menu.html('Aucune notification'); if(r.rows && r.rows.length>0) menu.html(''); for (var key in r.rows) { var notification = r.rows[key]; var notificationLine = $(Mustache.render($('.notification-template').html(),notification)); menu.append(notificationLine); } $('.notification_menu .dropdown-menu .dropdown-divider').last().remove(); menu.append('Voir toutes les notifications') menu.prepend('