mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-25 21:39:21 +00:00
New structure to dropdown.js
This commit is contained in:
parent
65fe5f9736
commit
e22de3d9a9
@ -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){
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user