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

359 lines
7.4 KiB
JavaScript
Raw Permalink 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
2018-05-03 19:56:58 +00:00
//Add user virtual directory (if any)
if(infos.virtualDirectory != ""){
var userTag = createElem2({
appendTo: boxBody,
type: "div",
innerHTML: "@"+ infos.virtualDirectory,
class: "user-tag-in-profile"
});
}
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: lang("user_page_profile_info_friends_link")
2017-12-23 17:19:06 +00:00
});
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: lang("user_page_profile_info_loading"),
2017-12-23 16:46:55 +00:00
});
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> " + lang("user_page_profile_info_conversation_button")
2017-12-24 12:48:05 +00:00
});
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",
2018-05-05 08:25:17 +00:00
class: "box box-primary about-user-box"
2017-12-24 12:48:05 +00:00
});
//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: lang("user_page_profile_info_about_box_title", [infos.firstName])
2017-12-24 12:48:05 +00:00
});
//Create box body
var boxBody = createElem2({
appendTo: boxRoot,
type: "div",
class: "box-body"
});
2021-04-17 07:00:01 +00:00
//Add user email address
if(infos.email_address){
const emailAddress = createElem2({
appendTo: boxBody,
type: "strong"
});
createElem2({
appendTo: emailAddress,
type: "i",
class: "fa fa-envelope-o margin-r-5"
});
createElem2({
appendTo: emailAddress,
type: "span",
innerHTML: tr("Email address")
});
createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
innerHTML: infos.email_address
});
//Add separator
createElem2({
appendTo: boxBody,
type: "hr",
});
}
//Add location
if(infos.location){
const location = createElem2({
appendTo: boxBody,
type: "strong"
});
createElem2({
appendTo: location,
type: "i",
class: "fa fa-map-marker margin-r-5"
});
createElem2({
appendTo: location,
type: "span",
innerHTML: tr("Location")
});
createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
innerHTML: infos.location
});
//Add separator
createElem2({
appendTo: boxBody,
type: "hr",
});
}
2017-12-24 12:48:05 +00:00
//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: lang("user_page_profile_info_website")
2017-12-24 12:48:05 +00:00
});
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",
});
}
2018-05-05 09:27:57 +00:00
//Add user public note (if any)
if(infos.publicNote){
var userNote = createElem2({
appendTo: boxBody,
type: "strong"
});
createElem2({
appendTo: userNote,
type: "i",
class: "fa fa-file-text-o margin-r-5"
});
createElem2({
appendTo: userNote,
type: "span",
innerHTML: lang("user_page_profile_info_note")
2018-05-05 09:27:57 +00:00
});
var publicNotes = createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
innerHTML: infos.publicNote
});
//Parse text
ComunicWeb.components.textParser.parse({
element: publicNotes,
user: infos
2018-05-05 09:27:57 +00:00
});
//Add separator
createElem2({
appendTo: boxBody,
type: "hr",
});
}
2017-12-24 12:48:05 +00:00
//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: lang("user_page_profile_info_membership")
2017-12-24 12:48:05 +00:00
});
createElem2({
appendTo: boxBody,
type: "p",
class: "text-muted",
innerHTML: lang("user_page_profile_info_member_for", [ComunicWeb.common.date.timeDiffToStr(infos.account_creation_time)])
2017-12-24 12:48:05 +00:00
});
},
2017-12-23 13:52:01 +00:00
};