Can display notifications related to groups posts.

This commit is contained in:
Pierre HUBERT 2018-07-20 13:51:13 +02:00
parent ede515f7a2
commit bd888f0f47
3 changed files with 55 additions and 15 deletions

View File

@ -166,24 +166,34 @@ ComunicWeb.components.notifications.dropdown = {
return;
}
//Get information about the groups
var groups_id = ComunicWeb.components.notifications.utils.get_groups_id(result);
getInfoMultipleGroups(groups_id, function(groups){
//Empty the target list
list.innerHTML = "";
//Check for errors
if(groups.error)
return notify("Could not get groups information!", "danger");
//Process the list of notifications
for (var i = 0; i < result.length; i++) {
const notification = result[i];
//Display the notification
ComunicWeb.components.notifications.ui.display_notification(notification, list, users);
}
//Empty the target list
list.innerHTML = "";
//Display a message if there isn't any notification to display
if(result.length == 0){
//Process the list of notifications
for (var i = 0; i < result.length; i++) {
const notification = result[i];
//Display the notification
ComunicWeb.components.notifications.ui.display_notification(notification, list, users, groups);
}
list.innerHTML = "<li class='no-notification-msg'>You do not have any notification yet.</li>";
//Display a message if there isn't any notification to display
if(result.length == 0){
}
list.innerHTML = "<li class='no-notification-msg'>You do not have any notification yet.</li>";
}
});
}, false);

View File

@ -13,8 +13,9 @@ ComunicWeb.components.notifications.ui = {
* @param {HTMLElement} target The target of the notification
* @param {Object} users Informations about users that might be required
* to display the notification
* @param {Object} groups Information about the potential related groups
*/
display_notification: function(data, target, users){
display_notification: function(data, target, users, groups){
//Generate the informations about the notifications
var from_user = users["user-"+data.from_user_id];
@ -49,6 +50,7 @@ ComunicWeb.components.notifications.ui = {
message += " ";
//Notification target
//User page
if(data.from_container_type == "user_page"){
if(data.from_user_id == data.from_container_id)
@ -58,6 +60,13 @@ ComunicWeb.components.notifications.ui = {
}
//Group page
if(data.from_container_type == "group_page"){
message += "on the group "+groups[data.from_container_id].name+".";
}
//Create notification action
var action = function(){

View File

@ -28,6 +28,27 @@ ComunicWeb.components.notifications.utils = {
return users;
}
},
/**
* Get the ID of the groups related to the notifications
*
* @param {Array} list The list to process
* @return {Array} The list of target groups IDs
*/
get_groups_id: function(list){
var groups = [];
list.forEach(function(notif){
if(!groups.includes(notif.from_container_id) && notif.from_container_type == "group_page")
groups.push(notif.from_container_id);
});
return groups;
},
}