2018-02-18 18:12:17 +00:00
|
|
|
/**
|
|
|
|
* Notifications menu bar dropdown
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.notifications.dropdown = {
|
|
|
|
|
2018-02-21 15:27:10 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2018-02-21 15:37:02 +00:00
|
|
|
//Display the number of unread conversations
|
2018-02-24 13:03:20 +00:00
|
|
|
var conversations_number_elem = ComunicWeb.components.conversations.unreadDropdown.display_dropdown(target);
|
2018-02-21 15:37:02 +00:00
|
|
|
|
2018-02-21 15:27:10 +00:00
|
|
|
//Initialize service
|
2018-02-21 15:37:02 +00:00
|
|
|
ComunicWeb.components.notifications.service.init(notifs_number_elem, true, conversations_number_elem);
|
2018-02-21 15:27:10 +00:00
|
|
|
},
|
|
|
|
|
2018-02-18 18:12:17 +00:00
|
|
|
/**
|
|
|
|
* Display notifications dropdown
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} target The target of the notification dropdown
|
2018-02-21 15:27:10 +00:00
|
|
|
* @return {HTMLElement} The HTML element that contains the number of unread notifications
|
2018-02-18 18:12:17 +00:00
|
|
|
*/
|
2018-02-21 15:27:10 +00:00
|
|
|
display_notifications_dropdown: function(target){
|
2018-02-18 18:12:17 +00:00
|
|
|
|
|
|
|
//Create the button
|
|
|
|
var dropdown = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "li",
|
2018-02-19 14:58:33 +00:00
|
|
|
class: "dropdown messages-menu"
|
2018-02-18 18:12:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//Add dropdown toggle
|
|
|
|
var dropdownToggle = createElem2({
|
|
|
|
appendTo: dropdown,
|
|
|
|
type: "a",
|
|
|
|
class: "dropdown-toggle",
|
|
|
|
href: "#",
|
|
|
|
innerHTML: '<i class="fa fa-bell-o"></i>'
|
|
|
|
});
|
2018-02-18 18:16:48 +00:00
|
|
|
dropdownToggle.setAttribute("data-toggle", "dropdown");
|
2018-02-18 18:12:17 +00:00
|
|
|
|
|
|
|
//Add notification number
|
|
|
|
var notificationsNumber = createElem2({
|
|
|
|
appendTo: dropdownToggle,
|
|
|
|
type: "span",
|
|
|
|
class: "label label-danger",
|
|
|
|
innerHTML: "0"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add dropdown menu
|
2018-02-18 18:16:48 +00:00
|
|
|
var dropdownMenu = createElem2({
|
|
|
|
appendTo: dropdown,
|
|
|
|
type: "ul",
|
|
|
|
class: "dropdown-menu"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add dropdown header
|
|
|
|
var dropdownHeader = createElem2({
|
|
|
|
appendTo: dropdownMenu,
|
|
|
|
type: "li",
|
|
|
|
class: "header",
|
2018-08-04 08:02:12 +00:00
|
|
|
innerHTML: lang("notifications_dropdown_title")
|
2018-02-18 18:16:48 +00:00
|
|
|
});
|
2018-02-18 18:12:17 +00:00
|
|
|
|
2018-02-19 08:46:51 +00:00
|
|
|
//Add notifications list
|
2018-03-25 07:43:39 +00:00
|
|
|
var notificationsListContainer = createElem2({
|
2018-02-19 08:46:51 +00:00
|
|
|
appendTo: dropdownMenu,
|
2018-02-19 14:58:33 +00:00
|
|
|
type: "li"
|
|
|
|
});
|
|
|
|
var notificationsList = createElem2({
|
2018-03-25 07:43:39 +00:00
|
|
|
appendTo: notificationsListContainer,
|
2018-02-19 08:46:51 +00:00
|
|
|
type: "ul",
|
|
|
|
class: "menu"
|
|
|
|
});
|
|
|
|
|
2018-02-20 13:55:55 +00:00
|
|
|
//Add dropdown bottom
|
|
|
|
var dropdownBottom = createElem2({
|
|
|
|
appendTo: dropdownMenu,
|
|
|
|
type: "li",
|
|
|
|
class: "footer"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add a button to offer the user to delete all his notifications
|
|
|
|
var deleteAllLink = createElem2({
|
|
|
|
appendTo: dropdownBottom,
|
|
|
|
type: "a",
|
2018-08-04 08:02:12 +00:00
|
|
|
innerHTML: lang("notifications_dropdown_delete_all_link")
|
2018-02-20 13:55:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//Make the delete all notifications link lives
|
|
|
|
deleteAllLink.onclick = function(){
|
|
|
|
|
2018-08-04 08:02:12 +00:00
|
|
|
ComunicWeb.common.messages.confirm(lang("notifications_dropdown_confirm_delete_all"), function(accept){
|
2018-02-20 13:55:55 +00:00
|
|
|
|
|
|
|
//We continue only if the user confirmed the operation
|
|
|
|
if(!accept)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//Perform a request to the server through the interface
|
|
|
|
ComunicWeb.components.notifications.interface.delete_all(function(result){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(result.error){
|
2018-08-04 08:02:12 +00:00
|
|
|
ComunicWeb.common.notificationSystem.showNotification(lang("notifications_dropdown_err_delete_all_notifications"), "danger");
|
2018-02-20 13:55:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Display success
|
2018-08-04 08:02:12 +00:00
|
|
|
ComunicWeb.common.notificationSystem.showNotification(lang("notifications_dropdown_delete_all_success"), "success");
|
2018-02-20 13:55:55 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-02-19 08:46:51 +00:00
|
|
|
//Enable slimscroll
|
|
|
|
$(notificationsList).slimScroll({
|
|
|
|
height: '100%'
|
|
|
|
});
|
|
|
|
|
|
|
|
//Refresh the notifications list if the user click the dropdown button
|
|
|
|
dropdownToggle.onclick = function(){
|
2018-02-21 15:27:10 +00:00
|
|
|
ComunicWeb.components.notifications.dropdown.refresh_list_notifications(notificationsList);
|
2018-02-19 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
2018-02-21 15:27:10 +00:00
|
|
|
//Return the number of notifications target
|
|
|
|
return notificationsNumber;
|
2018-02-18 18:12:17 +00:00
|
|
|
},
|
|
|
|
|
2018-02-19 08:46:51 +00:00
|
|
|
/**
|
|
|
|
* Refresh the list of notifications
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} list The notifications list to refresh
|
|
|
|
*/
|
2018-02-21 15:27:10 +00:00
|
|
|
refresh_list_notifications: function(list){
|
2018-02-19 08:46:51 +00:00
|
|
|
|
2018-02-19 13:09:15 +00:00
|
|
|
//Perform a request on the API
|
|
|
|
ComunicWeb.components.notifications.interface.get_list_unread(function(result){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(result.error){
|
2018-08-04 08:02:12 +00:00
|
|
|
ComunicWeb.common.notificationSystem.showNotification(lang("notifications_dropdown_err_get_notifs_list"), "danger");
|
2018-02-19 13:09:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-19 14:58:33 +00:00
|
|
|
//Get the list of required users informations
|
|
|
|
var users_id = ComunicWeb.components.notifications.utils.get_users_id(result);
|
|
|
|
|
|
|
|
//Get informations about the users
|
|
|
|
ComunicWeb.user.userInfos.getMultipleUsersInfos(users_id, function(users){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(users.error){
|
2018-08-04 08:02:12 +00:00
|
|
|
ComunicWeb.common.notificationSystem.showNotification(lang("notifications_dropdown_err_get_related_users_info"), "danger");
|
2018-02-19 14:58:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
//Get information about the groups
|
|
|
|
var groups_id = ComunicWeb.components.notifications.utils.get_groups_id(result);
|
|
|
|
getInfoMultipleGroups(groups_id, function(groups){
|
2018-02-19 14:58:33 +00:00
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
//Check for errors
|
|
|
|
if(groups.error)
|
2018-08-04 08:02:12 +00:00
|
|
|
return notify(lang("notifications_dropdown_err_get_related_groups_info"), "danger");
|
2018-07-20 11:51:13 +00:00
|
|
|
|
|
|
|
//Empty the target list
|
|
|
|
list.innerHTML = "";
|
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
2018-02-19 14:58:33 +00:00
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
//Display a message if there isn't any notification to display
|
|
|
|
if(result.length == 0){
|
2018-02-19 14:58:33 +00:00
|
|
|
|
2018-08-04 08:02:12 +00:00
|
|
|
list.innerHTML = "<li class='no-notification-msg'>" + lang("notifications_dropdown_no_notif_notice") + "</li>";
|
2018-02-20 13:55:55 +00:00
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
}
|
2018-02-20 13:55:55 +00:00
|
|
|
|
2018-07-20 11:51:13 +00:00
|
|
|
});
|
|
|
|
|
2018-02-20 13:55:55 +00:00
|
|
|
|
2018-02-19 14:58:33 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2018-02-19 13:09:15 +00:00
|
|
|
});
|
2018-02-19 08:46:51 +00:00
|
|
|
|
2018-02-24 13:03:20 +00:00
|
|
|
}
|
2018-02-18 18:12:17 +00:00
|
|
|
}
|