2018-03-05 17:50:56 +00:00
|
|
|
/**
|
|
|
|
* Friends list modal
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.friends.listModal = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the box that contains the list of friends of the user
|
|
|
|
*
|
2018-03-07 16:53:26 +00:00
|
|
|
* @param {number} user The ID of the target user
|
2018-03-05 17:50:56 +00:00
|
|
|
*/
|
2018-03-07 16:53:26 +00:00
|
|
|
display: function(user){
|
|
|
|
|
|
|
|
//Check if the user is requesting its own friends list or not
|
|
|
|
if(user == userID()){
|
|
|
|
|
|
|
|
//Get the list of friends of the current user
|
|
|
|
ComunicWeb.components.friends.interface.get_current_list(true, function(r){
|
|
|
|
|
|
|
|
//Check for error
|
|
|
|
if(r.error){
|
|
|
|
ComunicWeb.common.notificationSystem.showNotification("Could not get your list of friends !", "danger");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show the list
|
|
|
|
ComunicWeb.components.friends.listModal._show(user, r);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
//Try to get the list of friends of the specified user
|
|
|
|
ComunicWeb.components.friends.interface.get_user_list(user, function(r){
|
|
|
|
|
|
|
|
//Check for error
|
|
|
|
if(r.error){
|
|
|
|
ComunicWeb.common.notificationSystem.showNotification("Could not get the of friends of the user (it may be private) !", "danger");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show the list
|
|
|
|
ComunicWeb.components.friends.listModal._show(user, r);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the list of friends of a user
|
|
|
|
*
|
|
|
|
* @param {number} user The ID of the target user
|
|
|
|
* @param {object} list The list of users to display
|
|
|
|
*/
|
|
|
|
_show: function(user, list){
|
|
|
|
|
|
|
|
//Create a modal root
|
|
|
|
var modal = createElem2({
|
|
|
|
type: "div",
|
|
|
|
class: "modal modal-primary input-string-modal"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalDialog = createElem2({
|
|
|
|
appendTo: modal,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-dialog"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalContent = createElem2({
|
|
|
|
appendTo: modalDialog,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-content",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Modal header
|
|
|
|
var modalHeader = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-header"
|
|
|
|
});
|
|
|
|
|
|
|
|
var closeModal = createElem2({
|
|
|
|
appendTo: modalHeader,
|
|
|
|
type: "button",
|
|
|
|
class: "close",
|
|
|
|
});
|
|
|
|
|
|
|
|
createElem2({
|
|
|
|
appendTo: closeModal,
|
|
|
|
type: "span",
|
|
|
|
innerHTML: "x"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalTitle = createElem2({
|
|
|
|
appendTo: modalHeader,
|
|
|
|
type: "h4",
|
|
|
|
class: "modal-title",
|
|
|
|
innerHTML: "Friends list"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Modal body
|
|
|
|
var modalBody = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-body",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Modal footer
|
|
|
|
var modalFooter = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-footer"
|
|
|
|
});
|
|
|
|
|
|
|
|
var closeButton = createElem2({
|
|
|
|
appendTo: modalFooter,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-default",
|
|
|
|
innerHTML: "Close"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Create the response function
|
|
|
|
var respond = function(){
|
|
|
|
|
|
|
|
//Close modal
|
|
|
|
$(modal).modal('hide');
|
|
|
|
emptyElem(modal);
|
|
|
|
modal.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Make the buttons live
|
|
|
|
closeButton.onclick = respond;
|
|
|
|
closeModal.onclick = respond;
|
|
|
|
|
|
|
|
//Display the right version of the friends list
|
2018-03-11 08:56:42 +00:00
|
|
|
if(userID() == user){
|
|
|
|
|
|
|
|
//Show the friends list of the user
|
|
|
|
this._show_personnal(modalBody, list);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2018-03-07 16:53:26 +00:00
|
|
|
|
|
|
|
//Display a read-only list of friends
|
|
|
|
this._show_read_only(modalBody, list, user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show the modal
|
|
|
|
$(modal).modal('show');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a read-only list of friends
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} target The target for the list of friends
|
|
|
|
* @param {array} ids The list of IDs of the target users
|
|
|
|
* @param {userID} user The ID of the related user
|
|
|
|
*/
|
|
|
|
_show_read_only: function(target, ids, user){
|
|
|
|
|
2018-03-25 07:43:39 +00:00
|
|
|
//Create the friends list container
|
2018-03-07 16:53:26 +00:00
|
|
|
var list = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "div",
|
|
|
|
class: "friends-list-ro"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Get informations about the users
|
|
|
|
ComunicWeb.user.userInfos.getMultipleUsersInfos(ids, function(users){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(users.error){
|
|
|
|
ComunicWeb.common.notificationSystem.showNotification("An error occured while retrieving informations about the friends !", "danger");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Parse the list of friends
|
2018-04-24 18:19:00 +00:00
|
|
|
ids.forEach(function(id){
|
2018-03-07 16:53:26 +00:00
|
|
|
|
|
|
|
//Display the user
|
2018-03-25 07:43:39 +00:00
|
|
|
const userContainer = createElem2({
|
2018-03-07 16:53:26 +00:00
|
|
|
appendTo: list,
|
|
|
|
type: "div",
|
|
|
|
class: "friend"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Create user link
|
|
|
|
const userLink = createElem2({
|
2018-03-25 07:43:39 +00:00
|
|
|
appendTo: userContainer,
|
2018-03-07 16:53:26 +00:00
|
|
|
type: "a"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add user account image
|
|
|
|
createElem2({
|
|
|
|
appendTo: userLink,
|
|
|
|
type: "img",
|
|
|
|
src: users["user-" + id].accountImage
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add users name
|
|
|
|
createElem2({
|
|
|
|
appendTo: userLink,
|
2018-03-07 18:31:29 +00:00
|
|
|
type: "div",
|
2018-03-07 16:53:26 +00:00
|
|
|
class: "friends-name",
|
|
|
|
innerHTML: userFullName(users["user-" + id])
|
|
|
|
});
|
|
|
|
|
|
|
|
//Make the link button lives
|
|
|
|
userLink.onclick = function(){
|
|
|
|
|
|
|
|
//Open user page
|
2018-07-14 12:18:21 +00:00
|
|
|
openUserPage(users["user-" + id]);
|
2018-03-07 16:53:26 +00:00
|
|
|
|
|
|
|
//Close all modals
|
|
|
|
$(".modal").modal("hide");
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
2018-03-05 17:50:56 +00:00
|
|
|
|
2018-03-11 08:56:42 +00:00
|
|
|
/**
|
|
|
|
* Show the list of friends of the user
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} target The target element for the list
|
|
|
|
* @param {array} list The list of friends of the user
|
|
|
|
*/
|
|
|
|
_show_personnal: function(target, list){
|
|
|
|
|
|
|
|
//Get the list of friends ID
|
|
|
|
var usersID = ComunicWeb.components.friends.utils.getUsersIdFromPersonnalList(list);
|
|
|
|
|
|
|
|
//Create list target
|
|
|
|
var listTarget = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "div",
|
|
|
|
class: "personnal-friends-list"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Get informations about the users
|
|
|
|
ComunicWeb.user.userInfos.getMultipleUsersInfos(usersID, function(users){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(users.error){
|
|
|
|
ComunicWeb.common.notificationSystem.showNotification("Could not get informations about friends !", "danger");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Display each friend
|
2018-04-24 18:19:00 +00:00
|
|
|
list.forEach(function(friend){
|
2018-03-11 08:56:42 +00:00
|
|
|
|
2018-03-11 09:39:09 +00:00
|
|
|
//Display the friend
|
|
|
|
ComunicWeb.components.friends.ui.show_personnal_friend(listTarget, friend, users["user-"+friend.ID_friend]);
|
2018-03-11 08:56:42 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-11 09:39:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2018-03-11 08:56:42 +00:00
|
|
|
|
2018-03-05 17:50:56 +00:00
|
|
|
};
|