diff --git a/assets/js/components/notifications/dropdown.js b/assets/js/components/notifications/dropdown.js index 03469b3d..99b929cd 100644 --- a/assets/js/components/notifications/dropdown.js +++ b/assets/js/components/notifications/dropdown.js @@ -6,12 +6,27 @@ ComunicWeb.components.notifications.dropdown = { + /** + * Display new data dropdowns + * + * @param {HTMLElement} target The target for the notification area + */ + display: function(target){ + + //Display the number of notifications + var notifs_number_elem = this.display_notifications_dropdown(target); + + //Initialize service + ComunicWeb.components.notifications.service.init(notifs_number_elem, true); + }, + /** * Display notifications dropdown * * @param {HTMLElement} target The target of the notification dropdown + * @return {HTMLElement} The HTML element that contains the number of unread notifications */ - display: function(target){ + display_notifications_dropdown: function(target){ //Create the button var dropdown = createElem2({ @@ -112,16 +127,13 @@ ComunicWeb.components.notifications.dropdown = { height: '100%' }); - //Initialize service - ComunicWeb.components.notifications.service.init(notificationsNumber, true); - //Refresh the notifications list if the user click the dropdown button dropdownToggle.onclick = function(){ - - ComunicWeb.components.notifications.dropdown.refresh_list(notificationsList); - + ComunicWeb.components.notifications.dropdown.refresh_list_notifications(notificationsList); } + //Return the number of notifications target + return notificationsNumber; }, /** @@ -129,7 +141,7 @@ ComunicWeb.components.notifications.dropdown = { * * @param {HTMLElement} list The notifications list to refresh */ - refresh_list: function(list){ + refresh_list_notifications: function(list){ //Perform a request on the API ComunicWeb.components.notifications.interface.get_list_unread(function(result){ diff --git a/assets/js/components/notifications/interface.js b/assets/js/components/notifications/interface.js index 36fad4b9..ea003cbf 100644 --- a/assets/js/components/notifications/interface.js +++ b/assets/js/components/notifications/interface.js @@ -35,8 +35,8 @@ ComunicWeb.components.notifications.interface = { //Perform the request ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); - - } + + }, /** * Get the list of unread notifications diff --git a/assets/js/components/notifications/service.js b/assets/js/components/notifications/service.js index 898cd010..8d1a2223 100644 --- a/assets/js/components/notifications/service.js +++ b/assets/js/components/notifications/service.js @@ -24,17 +24,17 @@ ComunicWeb.components.notifications.service = { return clearInterval(interval); //Get the number of notifications from the API - ComunicWeb.components.notifications.interface.getNbUnreads(function(response){ + ComunicWeb.components.notifications.interface.getAllUnread(function(response){ //Continue in case of success if(response.error) return; //Update the target - target.innerHTML = response.number; + target.innerHTML = response.notifications; //If the number of notifications equals 0, hide the target if required - if(response.number == 0 && auto_hide) + if(response.notifications == 0 && auto_hide) target.style.display = "none"; else target.style.display = "block";