ComunicWeb/assets/js/pages/userPage/posts.js

113 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-12-29 07:58:22 +00:00
/**
* Posts function
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.userPage.posts = {
/**
* Display the posts
*
* @param {Object} userInfos Informations about the user
* @param {Object} params Additionnal parametres passed with the request
* @param {HTMLElement} target The target where the posts will be applied
*/
display: function(userInfos, params, target){
//Create posts blocks
var postsBlock = createElem2({
appendTo: target,
type: "div",
class: "box box-primary"
});
2017-12-31 17:51:46 +00:00
var postsBody = createElem2({
appendTo: postsBlock,
type: "div",
2018-01-03 08:28:40 +00:00
class: "box-body",
2017-12-31 17:51:46 +00:00
});
2018-01-03 08:28:40 +00:00
//Display loading message
var loadingMsg = createElem2({
appendTo: postsBody,
type: "p",
innerHTML: "Loading posts..."
});
loadingMsg.style.textAlign = "center";
2017-12-31 17:51:46 +00:00
//Get the posts from the API
ComunicWeb.components.posts.interface.get_user(userInfos.userID, function(result){
//Check for errors
if(result.error){
//Display notification
ComunicWeb.common.notificationSystem.showNotification("Couldn't get user posts!", "danger", 4, "Error");
}
else {
2018-01-03 08:28:40 +00:00
//Empty the target
emptyElem(postsBody);
2017-12-31 17:51:46 +00:00
//Show the posts
ComunicWeb.pages.userPage.posts._show(result, postsBody);
}
});
2017-12-29 07:58:22 +00:00
2017-12-31 17:51:46 +00:00
},
/**
* Show user posts
*
* @param {Object} posts The list of posts to display
2018-01-03 08:28:40 +00:00
* @param {HTMLElement} target The rendering target
2017-12-31 17:51:46 +00:00
*/
_show: function(posts, target){
2018-01-03 08:28:40 +00:00
2017-12-31 17:51:46 +00:00
//Process each post
var i;
for(i in posts){
//Display post
ComunicWeb.components.posts.ui.display_post(posts[i], target);
}
2018-01-03 08:28:40 +00:00
//Check if there is not any posts
if(target.children.length == 0){
this._no_posts_msg(target);
}
2017-12-31 17:51:46 +00:00
},
2017-12-29 07:58:22 +00:00
2018-01-03 08:28:40 +00:00
/**
* Display a message to inform user that there is not any post
* on the page he is visiting
*
* @param {HTMLElement} target The target for the message
*/
_no_posts_msg(target){
var msgContener = createElem2({
appendTo: target,
type: "div"
});
var msgTitle = createElem2({
appendTo: msgContener,
type: "h2",
innerHTML: "No post yet"
});
msgTitle.style.textAlign = "center";
var msgContent = createElem2({
appendTo: msgContener,
type: "p",
innerHTML: "Nobody has posted a message on this page yet."
}).style.textAlign = "center";
}
2017-12-29 07:58:22 +00:00
};