2018-02-19 14:58:33 +00:00
|
|
|
/**
|
|
|
|
* Notifications UI script
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.notifications.ui = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a single notification
|
|
|
|
*
|
|
|
|
* @param {Object} data Informations about the notification
|
|
|
|
* @param {HTMLElement} target The target of the notification
|
|
|
|
* @param {Object} users Informations about users that might be required
|
|
|
|
* to display the notification
|
2018-07-20 11:51:13 +00:00
|
|
|
* @param {Object} groups Information about the potential related groups
|
2018-02-19 14:58:33 +00:00
|
|
|
*/
|
2018-07-20 11:51:13 +00:00
|
|
|
display_notification: function(data, target, users, groups){
|
2018-02-19 14:58:33 +00:00
|
|
|
|
|
|
|
//Generate the informations about the notifications
|
|
|
|
var from_user = users["user-"+data.from_user_id];
|
|
|
|
|
|
|
|
//Generate the appropriate string
|
|
|
|
|
|
|
|
//Notification author
|
|
|
|
var message = userFullName(from_user) + " ";
|
|
|
|
|
|
|
|
//Notification action
|
2018-03-03 13:39:48 +00:00
|
|
|
//Comment
|
2018-02-19 14:58:33 +00:00
|
|
|
if(data.type == "comment_created")
|
|
|
|
message += "posted a comment";
|
|
|
|
|
2018-03-03 13:39:48 +00:00
|
|
|
//About friendship requests
|
|
|
|
if(data.type == "sent_friend_request")
|
|
|
|
message += "sent you a friendship request.";
|
|
|
|
if(data.type == "accepted_friend_request")
|
|
|
|
message += "accepted your friendship request.";
|
|
|
|
if(data.type == "rejected_friend_request")
|
|
|
|
message += "rejected your friendship request.";
|
|
|
|
|
|
|
|
//Generic element creation
|
2018-02-19 14:58:33 +00:00
|
|
|
if(data.type == "elem_created"){
|
|
|
|
|
|
|
|
if(data.on_elem_type == "post")
|
|
|
|
message += "created a new post";
|
|
|
|
|
|
|
|
}
|
2018-03-03 13:39:48 +00:00
|
|
|
|
|
|
|
//Space separator
|
2018-02-19 14:58:33 +00:00
|
|
|
message += " ";
|
|
|
|
|
|
|
|
//Notification target
|
2018-07-20 11:51:13 +00:00
|
|
|
//User page
|
2018-02-19 14:58:33 +00:00
|
|
|
if(data.from_container_type == "user_page"){
|
|
|
|
|
2018-04-10 17:14:11 +00:00
|
|
|
if(data.from_user_id == data.from_container_id)
|
|
|
|
message += "on his / her page";
|
|
|
|
else
|
|
|
|
message += "on "+userFullName(users["user-"+data.from_container_id])+"'s page";
|
2018-02-19 14:58:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
//Group page
|
|
|
|
if(data.from_container_type == "group_page"){
|
|
|
|
message += "on the group "+groups[data.from_container_id].name+".";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-20 12:59:52 +00:00
|
|
|
//Create notification action
|
|
|
|
var action = function(){
|
|
|
|
|
2018-02-20 13:08:54 +00:00
|
|
|
//Mark the notification as seen
|
|
|
|
ComunicWeb.components.notifications.interface.mark_seen(data.id, true);
|
|
|
|
|
|
|
|
//Process specific action
|
2018-03-03 13:39:48 +00:00
|
|
|
//For the post
|
|
|
|
if(data.on_elem_type == "post"){
|
2018-02-20 12:59:52 +00:00
|
|
|
|
2018-02-20 13:08:54 +00:00
|
|
|
//Open associated post page
|
2018-02-20 12:59:52 +00:00
|
|
|
openPage("post/" + data.on_elem_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:39:48 +00:00
|
|
|
//For the friendship requests
|
|
|
|
if(data.on_elem_type == "friend_request"){
|
|
|
|
|
|
|
|
//Open user page
|
2018-07-14 12:18:21 +00:00
|
|
|
openUserPageFromID(data.from_user_id);
|
2018-03-03 13:39:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-20 12:59:52 +00:00
|
|
|
};
|
|
|
|
|
2018-02-19 14:58:33 +00:00
|
|
|
//Create the notification object
|
2018-03-25 07:43:39 +00:00
|
|
|
var notificationContainer = createElem2({
|
2018-02-19 14:58:33 +00:00
|
|
|
appendTo: target,
|
|
|
|
type: "li",
|
2018-03-25 07:43:39 +00:00
|
|
|
class: "notification-container"
|
2018-02-19 14:58:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//Create notification link
|
|
|
|
var notificationLink = createElem2({
|
2018-03-25 07:43:39 +00:00
|
|
|
appendTo: notificationContainer,
|
2018-02-19 14:58:33 +00:00
|
|
|
type: "a"
|
|
|
|
});
|
2018-02-20 12:59:52 +00:00
|
|
|
notificationLink.onclick = action;
|
2018-02-19 14:58:33 +00:00
|
|
|
|
|
|
|
//Add notification left content
|
|
|
|
var notificationLeftContent = createElem2({
|
|
|
|
appendTo: notificationLink,
|
|
|
|
type: "div",
|
|
|
|
class: "pull-left"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add user image
|
|
|
|
var userImage = createElem2({
|
|
|
|
appendTo: notificationLeftContent,
|
|
|
|
type: "img",
|
|
|
|
src: from_user.accountImage,
|
|
|
|
class: "img-circle"
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//Add the notification message
|
|
|
|
var notificationMessage = createElem2({
|
|
|
|
appendTo: notificationLink,
|
|
|
|
type: "p",
|
|
|
|
innerHTML: message
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add notification date
|
|
|
|
var notificationCreationTime = createElem2({
|
|
|
|
appendTo: notificationLink,
|
|
|
|
type: "small",
|
|
|
|
class: "notification-creation-time",
|
|
|
|
innerHTML: '<i class="fa fa-clock-o"></i> ' + ComunicWeb.common.date.timeDiffToStr(data.time_create) + " ago"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
}
|