2018-01-18 05:53:00 +00:00
|
|
|
/**
|
|
|
|
* Comments UI
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.comments.ui = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a list comments
|
|
|
|
*
|
|
|
|
* @param {Object} infos Informations about the comments
|
|
|
|
* @param {int} postID The ID of the post attached to the comments
|
|
|
|
* @param {HTMLElement} target The target for the comments
|
|
|
|
*/
|
|
|
|
display: function(infos, postID, target){
|
|
|
|
|
|
|
|
//First, get informations about the users
|
2018-01-19 06:00:49 +00:00
|
|
|
var usersID = ComunicWeb.components.comments.utils.get_users_id(infos);
|
2018-01-18 05:53:00 +00:00
|
|
|
|
2018-01-19 06:00:49 +00:00
|
|
|
//Get informations about the users
|
|
|
|
var usersInfo = ComunicWeb.user.userInfos.getMultipleUsersInfos(usersID, function(result){
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(result.error){
|
|
|
|
ComunicWeb.common.notificationSystem.showNotification("Couldn't informations about some users to display their comments !", "danger");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Process the comments
|
|
|
|
ComunicWeb.components.comments.ui._process_comments(infos, result, postID, target);
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the list of comments
|
|
|
|
*
|
|
|
|
* @param {Object} infos Informations about the comments
|
|
|
|
* @param {Object} userInfos Informations about the users of the comments
|
|
|
|
* @param {int} postID The ID of the post attached to the comments
|
|
|
|
* @param {HTMLElement} target The target for the comments
|
|
|
|
*/
|
|
|
|
_process_comments: function(infos, usersInfos, postID, target){
|
|
|
|
|
|
|
|
//Create comments contener
|
|
|
|
var contener = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "div",
|
|
|
|
class: "box-comments post-comments"
|
|
|
|
});
|
|
|
|
|
2018-01-21 19:27:00 +00:00
|
|
|
//Process the list of comments
|
|
|
|
for(i in infos){
|
|
|
|
this._show_comment(infos[i], usersInfos['user-' + infos[i].userID], contener);
|
|
|
|
}
|
2018-01-19 06:00:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a comment
|
|
|
|
*
|
2018-01-21 19:27:00 +00:00
|
|
|
* @param {object} infos Informations about the comment
|
|
|
|
* @param {object} user Informations about the user
|
|
|
|
* @param {HTMLElement} target The target for the comment
|
2018-01-19 06:00:49 +00:00
|
|
|
*/
|
2018-01-21 19:27:00 +00:00
|
|
|
_show_comment: function(infos, user, target){
|
|
|
|
|
|
|
|
//Create comment contener
|
|
|
|
var commentContener = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "div",
|
|
|
|
class: "box-comment"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add user image
|
|
|
|
createElem2({
|
|
|
|
appendTo: commentContener,
|
|
|
|
type: "img",
|
|
|
|
class: "img-circle imgs-sm",
|
|
|
|
src: user.accountImage
|
|
|
|
});
|
|
|
|
|
|
|
|
//Create comment text
|
|
|
|
var commentText = createElem2({
|
|
|
|
appendTo: commentContener,
|
|
|
|
type: "div",
|
|
|
|
class: "comment-text"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add usernmae
|
|
|
|
var userNameContener = createElem2({
|
|
|
|
appendTo: commentText,
|
|
|
|
type: "span",
|
|
|
|
class: "username",
|
|
|
|
innerHTML: userFullName(user)
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add right text
|
|
|
|
var rightContener = createElem2({
|
|
|
|
appendTo: userNameContener,
|
|
|
|
type: "span",
|
|
|
|
class: "text-muted pull-right"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add comment creation date
|
|
|
|
createElem2({
|
|
|
|
appendTo: rightContener,
|
|
|
|
type: "span",
|
|
|
|
innerHTML: ComunicWeb.common.date.timeDiffToStr(infos.time_sent) + " ago"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add comment content
|
|
|
|
var commentContent = createElem2({
|
|
|
|
appendTo: commentText,
|
|
|
|
type: "div",
|
|
|
|
innerHTML: infos.content
|
|
|
|
});
|
2018-01-18 05:53:00 +00:00
|
|
|
|
2018-01-21 19:27:00 +00:00
|
|
|
//Add comment image (if any)
|
2018-01-18 05:53:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|