mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 05:49:22 +00:00
Update the number of notifications
This commit is contained in:
parent
26bbf1043e
commit
f97826752a
@ -806,6 +806,20 @@ var ComunicWeb = {
|
|||||||
|
|
||||||
//TODO : implement
|
//TODO : implement
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification refresh service
|
||||||
|
*/
|
||||||
|
service: {
|
||||||
|
//TODO : implement
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifications interface
|
||||||
|
*/
|
||||||
|
interface: {
|
||||||
|
//TODO : implement
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@ ComunicWeb.components.notifications.dropdown = {
|
|||||||
innerHTML: "Notifications"
|
innerHTML: "Notifications"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Initialize service
|
||||||
|
ComunicWeb.components.notifications.service.init(notificationsNumber, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
25
assets/js/components/notifications/interface.js
Normal file
25
assets/js/components/notifications/interface.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Notifications interface
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
ComunicWeb.components.notifications.interface = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of unread notifications
|
||||||
|
*
|
||||||
|
* @param {function} callback
|
||||||
|
*/
|
||||||
|
getNbUnreads: function(callback){
|
||||||
|
|
||||||
|
//Perform API request
|
||||||
|
var apiURI = "notifications/count_unread";
|
||||||
|
var params = {};
|
||||||
|
|
||||||
|
//Perform the request
|
||||||
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
assets/js/components/notifications/service.js
Normal file
48
assets/js/components/notifications/service.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* Notifications service
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
ComunicWeb.components.notifications.service = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init the service
|
||||||
|
*
|
||||||
|
* @param {HTMLElement} target The target that will receive
|
||||||
|
* the number of unread notifications
|
||||||
|
* @param {Bool} auto_hide Automatically hide the notifications
|
||||||
|
* number if there is not any new notification
|
||||||
|
*/
|
||||||
|
init: function(target, auto_hide){
|
||||||
|
|
||||||
|
//Initialize interval
|
||||||
|
var interval = setInterval(function(){
|
||||||
|
|
||||||
|
//Auto-remove interval if the target has been removed
|
||||||
|
if(!target.isConnected)
|
||||||
|
return clearInterval(interval);
|
||||||
|
|
||||||
|
//Get the number of notifications from the API
|
||||||
|
ComunicWeb.components.notifications.interface.getNbUnreads(function(response){
|
||||||
|
|
||||||
|
//Continue in case of success
|
||||||
|
if(response.error)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Update the target
|
||||||
|
target.innerHTML = response.number;
|
||||||
|
|
||||||
|
//If the number of notifications equals 0, hide the target if required
|
||||||
|
if(response.number == 0 && auto_hide)
|
||||||
|
target.style.display = "none";
|
||||||
|
else
|
||||||
|
target.style.display = "block";
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
@ -258,6 +258,8 @@ class Dev {
|
|||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
"js/components/notifications/dropdown.js",
|
"js/components/notifications/dropdown.js",
|
||||||
|
"js/components/notifications/service.js",
|
||||||
|
"js/components/notifications/interface.js",
|
||||||
|
|
||||||
//User scripts
|
//User scripts
|
||||||
"js/user/loginTokens.js",
|
"js/user/loginTokens.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user