ComunicWeb/assets/js/pages/userPage/profileInfos.js

253 lines
5.2 KiB
JavaScript
Raw Normal View History

2017-12-23 13:52:01 +00:00
/**
* Profile informations displaying handler
*
* Handlers the rendering of informations such as
* the name of the user, or account informations
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.userPage.profileInfos = {
/**
* Display profile informations
*
* @param {Object} infos Informations about the user
* @param {HTMLElement} target The target of the profile informations
*/
display: function(infos, target){
//Create the main box
this.createMainBox(infos, target);
2017-12-24 12:48:05 +00:00
//About user box
this.createAboutUserBox(infos, target);
2017-12-23 13:52:01 +00:00
},
/**
* Display the main informations about the user
*
* @param {Object} infos Informations about the user
* @param {HTMLElement} target The target of the box
*/
createMainBox: function(infos, target){
2018-03-25 07:43:39 +00:00
//Create box container
var boxContainer = createElem2({
2017-12-23 13:52:01 +00:00
appendTo: target,
type: "div",
class: "box box-primary"
});
//Setup box body
var boxBody = createElem2({
2018-03-25 07:43:39 +00:00
appendTo: boxContainer,
2017-12-23 13:52:01 +00:00
type: "div",
class: "box-body box-profile"
});
//Add user image
var userImage = createElem2({
appendTo: boxBody,
type: "img",
class: "profile-user-img img-responsive img-circle",
src: infos.accountImage
});
//Add user name
var userName = createElem2({
appendTo: boxBody,
type: "h3",
class: "profile-username text-center",
innerHTML: infos.firstName + " " + infos.lastName
});
2017-12-23 16:46:55 +00:00
2017-12-29 08:19:48 +00:00
2017-12-29 07:58:22 +00:00
//Show user likes
var userLikesTarget = createElem2({
appendTo: boxBody,
type: "div"
});
userLikesTarget.style.textAlign = "center";
2017-12-29 08:19:48 +00:00
userLikesTarget.style.marginBottom = "10px";
2017-12-29 07:58:22 +00:00
//Check wether user is linking or not
var userLiking = null;
if(signed_in()){
userLiking = infos.user_like_page;
}
//Call component
ComunicWeb.components.like.button.display(
"user",
infos.userID,
infos.pageLikes,
userLiking,
2018-02-04 07:08:25 +00:00
userLikesTarget
2017-12-29 07:58:22 +00:00
);
2017-12-29 08:19:48 +00:00
//Add a list of informations about user
2017-12-23 17:19:06 +00:00
var listInfos = createElem2({
appendTo: boxBody,
type: "url",
class: "list-group list-group-unbordered"
});
//Add number of friends
var friendsLi = createElem2({
appendTo: listInfos,
type: "li",
class: "list-group-item"
});
createElem2({
appendTo: friendsLi,
type: "b",
innerHTML: "Friends"
});
2018-03-05 17:50:56 +00:00
var friendsListLink = createElem2({
2017-12-23 17:19:06 +00:00
appendTo: friendsLi,
type: "a",
class: "pull-right",
innerHTML: infos.number_friends
2017-12-23 17:32:54 +00:00
});
2018-03-05 17:50:56 +00:00
//Make the user number lives
friendsListLink.onclick = function(){
ComunicWeb.components.friends.listModal.display(infos.userID);
};
2017-12-23 16:46:55 +00:00
//Add user status informations (if required)
if(signed_in()){
if(userID() != infos.userID){
2017-12-24 12:48:05 +00:00
// Get user status
2017-12-23 16:46:55 +00:00
var userStatus = createElem2({
appendTo: boxBody,
type: "div",
innerHTML: "Loading...",
});
userStatus.style.textAlign = "center";
ComunicWeb.pages.userPage.friendshipStatus.display(infos.userID, userStatus);
2017-12-24 12:48:05 +00:00
//Add separator
userStatus.style.marginBottom = "5px";
//Create conversation button
var conversationButton = createElem2({
appendTo: boxBody,
type: "button",
class: "btn btn-default btn-block",
innerHTML: "<i class='fa fa-comments'></i> Conversation"
});
conversationButton.onclick = function(){
ComunicWeb.components.conversations.manager.openPrivate(infos.userID);
}
2017-12-23 16:46:55 +00:00
}
}
2017-12-24 12:48:05 +00:00
},
/**
* Create the about the user box
*
* @param {Object} infos Informations about the user
* @param {HTMLElement} target The target for the box
*/
createAboutUserBox: function(infos, target){
//Create box root
var boxRoot = createElem2({
appendTo: target,
type: "div",
class: "box box-primary"
});
//Add box header
var boxHeader = createElem2({
appendTo: boxRoot,
type: "div",
class: "box-header with-border"
});
//Add box title
createElem2({
appendTo: boxHeader,
type: "h3",
class: "box-title",
innerHTML: "About " + infos.firstName
});
//Create box body
var boxBody = createElem2({
appendTo: boxRoot,
type: "div",
class: "box-body"
});
//Add user website (if any)
if(infos.personnalWebsite){
var userWebsite = createElem2({
appendTo: boxBody,
type: "strong"
});
createElem2({
appendTo: userWebsite,
type: "i",
class: "fa fa-link margin-r-5"
});
createElem2({
appendTo: userWebsite,
type: "span",
innerHTML: "Website"
});
var websiteLinkContainer = createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
});
createElem2({
appendTo: websiteLinkContainer,
type: "a",
href: infos.personnalWebsite,
innerHTML: infos.personnalWebsite
}).target="_blank";
//Add separator
createElem2({
appendTo: boxBody,
type: "hr",
});
}
//Add informations about membership
var membershipInfos = createElem2({
appendTo: boxBody,
type: "strong"
});
createElem2({
appendTo: membershipInfos,
type: "i",
class: "fa fa-clock-o margin-r-5"
});
createElem2({
appendTo: membershipInfos,
type: "span",
innerHTML: "Membership"
});
createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
innerHTML: "Member for " + ComunicWeb.common.date.timeDiffToStr(infos.account_creation_time)
});
},
2017-12-23 13:52:01 +00:00
};