mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +00:00
Display the posts of a group
This commit is contained in:
parent
2032017b0c
commit
74e06a2b89
5
assets/css/pages/groups/sections/posts.css
Normal file
5
assets/css/pages/groups/sections/posts.css
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Groups posts section stylesheet
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
@ -1279,6 +1279,13 @@ var ComunicWeb = {
|
||||
membershipBlock: {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Posts sections
|
||||
*/
|
||||
posts: {
|
||||
//TODO : implement
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -31,6 +31,31 @@ ComunicWeb.components.posts.interface = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a group posts
|
||||
*
|
||||
* @param {number} groupID The ID of the target group
|
||||
* @param {int} lastPostID The ID of the last post loaded
|
||||
* @param {function} callback
|
||||
*/
|
||||
get_group: function(groupID, lastPostID, callback){
|
||||
|
||||
//Load the previous posts to the loaded post if required
|
||||
if(lastPostID > 0)
|
||||
lastPostID--;
|
||||
|
||||
//Prepare the API request
|
||||
var APIuri = "posts/get_group";
|
||||
var params = {
|
||||
groupID: groupID,
|
||||
startFrom: lastPostID
|
||||
};
|
||||
|
||||
//Make the request
|
||||
ComunicWeb.common.api.makeAPIrequest(APIuri, params, true, callback);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the list of the latest posts
|
||||
*
|
||||
|
@ -90,6 +90,21 @@ ComunicWeb.pages.groups.pages.group = {
|
||||
ComunicWeb.components.posts.form.display("group", id, postFormCol);
|
||||
}
|
||||
|
||||
//Display group posts
|
||||
var postsRow = createElem2({
|
||||
appendTo: target,
|
||||
type: "div",
|
||||
class: "row group-page"
|
||||
});
|
||||
|
||||
var postsCol = createElem2({
|
||||
appendTo: postsRow,
|
||||
type: "div",
|
||||
class: "col-md-6"
|
||||
});
|
||||
|
||||
ComunicWeb.pages.groups.sections.posts.display(info, postsCol);
|
||||
|
||||
}
|
||||
|
||||
}
|
110
assets/js/pages/groups/sections/posts.js
Normal file
110
assets/js/pages/groups/sections/posts.js
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Groups posts section
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.pages.groups.sections.posts = {
|
||||
|
||||
/**
|
||||
* ID of the oldest known post
|
||||
*/
|
||||
_oldest_post_id: 0,
|
||||
|
||||
/**
|
||||
* Loading message
|
||||
*/
|
||||
_loading_msg: null,
|
||||
|
||||
/**
|
||||
* Display the section
|
||||
*
|
||||
* @param {Object} info Information about the related group
|
||||
* @param {HTMLElement} target The target for the section
|
||||
*/
|
||||
display: function(info, target){
|
||||
|
||||
//Reset posts counter
|
||||
this._oldest_post_id = 0;
|
||||
|
||||
//Create posts target
|
||||
var postsBody = createElem2({
|
||||
appendTo: target,
|
||||
type: "div",
|
||||
class: "box box-primary"
|
||||
});
|
||||
|
||||
var postsBody = createElem2({
|
||||
appendTo: postsBody,
|
||||
type: "div",
|
||||
class: "box-body"
|
||||
});
|
||||
|
||||
//Display loading message
|
||||
this._loading_msg = ComunicWeb.common.messages.createCalloutElem(
|
||||
"Loading", "Please wait while we load this group posts...", "info");
|
||||
postsBody.appendChild(this._loading_msg);
|
||||
|
||||
this._refresh_list(info, postsBody);
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh the list of posts of this group
|
||||
*
|
||||
* @param {Object} info Information about the group
|
||||
* @param {HTMLElement} target
|
||||
*/
|
||||
_refresh_list: function(info, target){
|
||||
|
||||
//Get the posts of the group
|
||||
ComunicWeb.components.posts.interface.get_group(info.id, 0, function(result){
|
||||
|
||||
ComunicWeb.pages.groups.sections.posts._loading_msg.remove();
|
||||
|
||||
//Check for errors
|
||||
if(result.error){
|
||||
target.appendChild(ComunicWeb.common.messages.createCalloutElem(
|
||||
"Error", "Could not get this group posts!", "danger"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Display the list of posts
|
||||
ComunicWeb.pages.groups.sections.posts._display_list(result, target);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Display a list of posts
|
||||
*
|
||||
* @param {Array} list The list of posts
|
||||
* @param {HTMLElement} target The target for the list
|
||||
*/
|
||||
_display_list: function(list, target){
|
||||
|
||||
var oldest_id = 0;
|
||||
|
||||
list.forEach(function(post){
|
||||
|
||||
if(oldest_id == 0 || post.ID < oldest_id)
|
||||
oldest_id = post.ID;
|
||||
|
||||
//Display the post
|
||||
ComunicWeb.components.posts.ui.display_post(post, target);
|
||||
});
|
||||
|
||||
if(this._oldest_post_id == 0 && oldest_id == 0){
|
||||
|
||||
//Display message
|
||||
var message = ComunicWeb.common.messages.createCalloutElem("No post to display", "This group has not sent any post yet.", "info");
|
||||
message.className += " noGroupPosts";
|
||||
target.appendChild(message);
|
||||
|
||||
}
|
||||
|
||||
if(this._oldest_post_id == 0 || this._oldest_post_id > oldest_id)
|
||||
this._oldest_post_id = oldest_id;
|
||||
},
|
||||
|
||||
};
|
@ -228,6 +228,7 @@ class Dev {
|
||||
//Groups sections
|
||||
"css/pages/groups/sections/header.css",
|
||||
"css/pages/groups/sections/membershipBlock.css",
|
||||
"css/pages/groups/sections/posts.css",
|
||||
|
||||
|
||||
//Settings page
|
||||
@ -440,6 +441,7 @@ class Dev {
|
||||
//Groups sections
|
||||
"js/pages/groups/sections/header.js",
|
||||
"js/pages/groups/sections/membershipBlock.js",
|
||||
"js/pages/groups/sections/posts.js",
|
||||
|
||||
|
||||
//User settings page
|
||||
|
Loading…
Reference in New Issue
Block a user